25 DBUG_ENTER(
"heap_delete");
26 DBUG_PRINT(
"enter",(
"info: 0x%lx record: 0x%lx", (
long) info, (
long) record));
30 if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,record))
31 DBUG_RETURN(my_errno);
34 if ( --(share->records) < share->blength >> 1) share->blength>>=1;
35 pos=info->current_ptr;
37 p_lastinx = share->keydef + info->lastinx;
38 for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
41 if ((*keydef->delete_key)(info, keydef, record, pos, keydef == p_lastinx))
45 info->update=HA_STATE_DELETED;
46 *((uchar**) pos)=share->del_link;
48 pos[share->reclength]=0;
50 info->current_hash_ptr=0;
51 #if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
52 DBUG_EXECUTE(
"check_heap",heap_check_heap(info, 0););
57 if (++(share->records) == share->blength)
58 share->blength+= share->blength;
59 DBUG_RETURN(my_errno);
68 const uchar *record, uchar *recpos,
int flag)
77 custom_arg.keyseg= keyinfo->seg;
78 custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
79 custom_arg.search_flag= SEARCH_SAME;
80 old_allocated= keyinfo->rb_tree.allocated;
81 res= tree_delete(&keyinfo->rb_tree, info->recbuf, custom_arg.key_length,
83 info->s->index_length-= (old_allocated - keyinfo->rb_tree.allocated);
105 const uchar *record, uchar *recpos,
int flag)
107 ulong blength, pos2, pos_hashnr, lastpos_hashnr, key_pos;
108 HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
110 DBUG_ENTER(
"hp_delete_key");
112 blength=share->blength;
113 if (share->records+1 == blength)
115 lastpos=hp_find_hash(&keyinfo->block,share->records);
119 key_pos= hp_mask(hp_rec_hashnr(keyinfo, record), blength, share->records + 1);
120 pos= hp_find_hash(&keyinfo->block, key_pos);
124 while (pos->ptr_to_rec != recpos)
126 if (flag && !hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 0))
129 if (!(pos=pos->next_key))
131 DBUG_RETURN(my_errno=HA_ERR_CRASHED);
140 info->current_hash_ptr=last_ptr;
141 info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
142 DBUG_PRINT(
"info",(
"Corrected current_ptr to point at: 0x%lx",
143 (
long) info->current_ptr));
147 gpos->next_key=pos->next_key;
148 else if (pos->next_key)
151 pos->ptr_to_rec=empty->ptr_to_rec;
152 pos->next_key=empty->next_key;
155 keyinfo->hash_buckets--;
157 if (empty == lastpos)
161 lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec);
163 pos=hp_find_hash(&keyinfo->block, hp_mask(lastpos_hashnr, share->blength,
170 pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
172 pos3= hp_find_hash(&keyinfo->block,
173 hp_mask(pos_hashnr, share->blength, share->records));
178 hp_movelink(pos, pos3, empty);
181 pos2= hp_mask(lastpos_hashnr, blength, share->records + 1);
182 if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1))
184 if (pos2 != share->records)
187 hp_movelink(lastpos, pos, empty);
196 if (flag && pos2 == key_pos)
198 info->current_ptr= 0;
199 info->current_hash_ptr= 0;
205 keyinfo->hash_buckets--;
209 hp_movelink(pos3, empty, pos->next_key);