@@ -282,6 +282,8 @@ uchar* my_hash_first_from_hash_value(const HASH *hash,
282282 uint flag = 1 ;
283283 uint idx = my_hash_mask (hash_value ,
284284 hash -> blength , hash -> records );
285+ if (!length )
286+ length = hash -> key_length ; // length for fixed length keys or 0
285287 do
286288 {
287289 pos = dynamic_element (& hash -> array ,idx ,HASH_LINK * );
@@ -316,6 +318,8 @@ uchar* my_hash_next(const HASH *hash, const uchar *key, size_t length,
316318 if (* current_record != NO_RECORD )
317319 {
318320 HASH_LINK * data = dynamic_element (& hash -> array ,0 ,HASH_LINK * );
321+ if (!length )
322+ length = hash -> key_length ; // length for fixed length keys or 0
319323 for (idx = data [* current_record ].next ; idx != NO_RECORD ; idx = pos -> next )
320324 {
321325 pos = data + idx ;
@@ -356,8 +360,11 @@ static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink)
356360 length length of key
357361
358362 NOTES:
359- If length is 0, comparison is done using the length of the
360- record being compared against.
363+ length equal 0 can mean 2 things:
364+ 1) it is fixed key length hash (HASH::key_length != 0) and
365+ default length should be taken in this case
366+ 2) it is really 0 length key for variable key length hash
367+ (HASH::key_length == 0)
361368
362369 RETURN
363370 = 0 key of record == key
@@ -368,10 +375,11 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key,
368375 size_t length )
369376{
370377 size_t rec_keylength ;
371- uchar * rec_key = (uchar * ) my_hash_key (hash , pos -> data , & rec_keylength , 1 );
372- return ((length && length != rec_keylength ) ||
378+ uchar * rec_key ;
379+ rec_key = (uchar * ) my_hash_key (hash , pos -> data , & rec_keylength , 1 );
380+ return (length != rec_keylength ) ||
373381 my_strnncoll (hash -> charset , (uchar * ) rec_key , rec_keylength ,
374- (uchar * ) key , rec_keylength )) ;
382+ (uchar * ) key , rec_keylength );
375383}
376384
377385
0 commit comments