MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_hash_update

Function my_hash_update

mysys/hash.c:612–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610 */
611
612my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,
613 size_t old_key_length)
614{
615 uint new_index,new_pos_index,blength,records;
616 size_t idx,empty;
617 HASH_LINK org_link,*data,*previous,*pos;
618 DBUG_ENTER("my_hash_update");
619
620 if (HASH_UNIQUE & hash->flags)
621 {
622 HASH_SEARCH_STATE state;
623 uchar *found, *new_key= (uchar*) my_hash_key(hash, record, &idx, 1);
624 if ((found= my_hash_first(hash, new_key, idx, &state)))
625 {
626 do
627 {
628 if (found != record)
629 DBUG_RETURN(1); /* Duplicate entry */
630 }
631 while ((found= my_hash_next(hash, new_key, idx, &state)));
632 }
633 }
634
635 data=dynamic_element(&hash->array,0,HASH_LINK*);
636 blength=hash->blength; records=hash->records;
637
638 /* Search after record with key */
639
640 idx= my_hash_mask(calc_hash(hash, old_key, (old_key_length ?
641 old_key_length :
642 hash->key_length)),
643 blength, records);
644 new_index= my_hash_mask(rec_hashnr(hash, record), blength, records);
645 if (idx == new_index)
646 DBUG_RETURN(0); /* Nothing to do (No record check) */
647 previous=0;
648 for (;;)
649 {
650
651 if ((pos= data+idx)->data == record)
652 break;
653 previous=pos;
654 if ((idx=pos->next) == NO_RECORD)
655 DBUG_RETURN(1); /* Not found in links */
656 }
657 org_link= *pos;
658 empty=idx;
659
660 /* Relink record from current chain */
661
662 if (!previous)
663 {
664 if (pos->next != NO_RECORD)
665 {
666 empty=pos->next;
667 *pos= data[pos->next];
668 }
669 }

Callers

nothing calls this directly

Calls 8

my_hash_keyFunction · 0.85
my_hash_firstFunction · 0.85
my_hash_nextFunction · 0.85
my_hash_maskFunction · 0.85
rec_hashnrFunction · 0.85
my_hash_rec_maskFunction · 0.85
movelinkFunction · 0.85
calc_hashFunction · 0.70

Tested by

no test coverage detected