diff options
-rw-r--r-- | storage/heap/heapdef.h | 20 | ||||
-rw-r--r-- | storage/heap/hp_hash.c | 40 |
2 files changed, 27 insertions, 33 deletions
diff --git a/storage/heap/heapdef.h b/storage/heap/heapdef.h index 8d9d1f81c53..a20fe6836a2 100644 --- a/storage/heap/heapdef.h +++ b/storage/heap/heapdef.h @@ -83,7 +83,6 @@ extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, HASH_INFO *pos); extern ulong hp_hashnr(HP_KEYDEF *keyinfo,const uchar *key); extern ulong hp_rec_hashnr(HP_KEYDEF *keyinfo,const uchar *rec); -extern ulong hp_mask(ulong hashnr,ulong buffmax,ulong maxlength); extern void hp_movelink(HASH_INFO *pos,HASH_INFO *next_link, HASH_INFO *newlink); extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const uchar *rec1, @@ -111,3 +110,22 @@ void init_heap_psi_keys(); #endif /* HAVE_PSI_INTERFACE */ C_MODE_END + +/* + Calculate position number for hash value. + SYNOPSIS + hp_mask() + hashnr Hash value + buffmax Value such that + 2^(n-1) < maxlength <= 2^n = buffmax + maxlength + + RETURN + Array index, in [0..maxlength) +*/ + +static inline ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength) +{ + if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1)); + return (hashnr & ((buffmax >> 1) -1)); +} diff --git a/storage/heap/hp_hash.c b/storage/heap/hp_hash.c index eaf284c2015..eca8f71458b 100644 --- a/storage/heap/hp_hash.c +++ b/storage/heap/hp_hash.c @@ -100,18 +100,20 @@ uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, uint nextflag) { reg1 HASH_INFO *pos,*prev_ptr; - int flag; uint old_nextflag; HP_SHARE *share=info->s; DBUG_ENTER("hp_search"); old_nextflag=nextflag; - flag=1; prev_ptr=0; if (share->records) { - pos=hp_find_hash(&keyinfo->block, hp_mask(hp_hashnr(keyinfo, key), - share->blength, share->records)); + ulong search_pos= + hp_mask(hp_hashnr(keyinfo, key), share->blength, share->records); + pos=hp_find_hash(&keyinfo->block, search_pos); + if (search_pos != + hp_mask(pos->hash_of_key, share->blength, share->records)) + goto not_found; /* Wrong link */ do { if (!hp_key_cmp(keyinfo, pos->ptr_to_rec, key)) @@ -142,17 +144,11 @@ uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, } } } - if (flag) - { - flag=0; /* Reset flag */ - if (hp_find_hash(&keyinfo->block, - hp_mask(pos->hash_of_key, - share->blength, share->records)) != pos) - break; /* Wrong link */ - } } while ((pos=pos->next_key)); } + +not_found: my_errno=HA_ERR_KEY_NOT_FOUND; if (nextflag == 2 && ! info->current_ptr) { @@ -195,26 +191,6 @@ uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, /* - Calculate position number for hash value. - SYNOPSIS - hp_mask() - hashnr Hash value - buffmax Value such that - 2^(n-1) < maxlength <= 2^n = buffmax - maxlength - - RETURN - Array index, in [0..maxlength) -*/ - -ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength) -{ - if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1)); - return (hashnr & ((buffmax >> 1) -1)); -} - - -/* Change next_link -> ... -> X -> pos to |