00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "heap_priv.h"
00019
00020 int heap_delete(HP_INFO *info, const unsigned char *record)
00021 {
00022 unsigned char *pos;
00023 HP_SHARE *share=info->getShare();
00024 HP_KEYDEF *keydef, *end, *p_lastinx;
00025
00026 test_active(info);
00027
00028 if (info->opt_flag & READ_CHECK_USED)
00029 return(errno);
00030 share->changed=1;
00031
00032 if ( --(share->records) < share->blength >> 1) share->blength>>=1;
00033 pos=info->current_ptr;
00034
00035 p_lastinx = share->keydef + info->lastinx;
00036 for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
00037 keydef++)
00038 {
00039 if (hp_delete_key(info, keydef, record, pos, keydef == p_lastinx))
00040 goto err;
00041 }
00042
00043 info->update=HA_STATE_DELETED;
00044 hp_free_chunks(&share->recordspace, pos);
00045 info->current_hash_ptr=0;
00046
00047 return(0);
00048 err:
00049 if (++(share->records) == share->blength)
00050 share->blength+= share->blength;
00051 return(errno);
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
00072 const unsigned char *record, unsigned char *recpos, int flag)
00073 {
00074 uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
00075 HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
00076 HP_SHARE *share=info->getShare();
00077
00078 blength=share->blength;
00079 if (share->records+1 == blength)
00080 blength+= blength;
00081
00082
00083
00084 lastpos=hp_find_hash(&keyinfo->block,share->records);
00085 last_ptr=0;
00086
00087
00088 pos= hp_find_hash(&keyinfo->block,
00089 hp_mask(hp_rec_hashnr(keyinfo, record), blength,
00090 share->records + 1));
00091 gpos = pos3 = 0;
00092
00093 while (pos->ptr_to_rec != recpos)
00094 {
00095 if (flag && !hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 0))
00096 last_ptr=pos;
00097 gpos=pos;
00098 if (!(pos=pos->next_key))
00099 {
00100 return(errno= drizzled::HA_ERR_CRASHED);
00101 }
00102 }
00103
00104
00105
00106 if (flag)
00107 {
00108
00109 info->current_hash_ptr=last_ptr;
00110 info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
00111 }
00112 empty=pos;
00113 if (gpos) {
00114
00115 gpos->next_key=pos->next_key;
00116 }
00117 else if (pos->next_key)
00118 {
00119
00120
00121
00122 empty=pos->next_key;
00123 pos->ptr_to_rec=empty->ptr_to_rec;
00124 pos->next_key=empty->next_key;
00125 }
00126 else
00127 {
00128
00129 keyinfo->hash_buckets--;
00130 }
00131
00132 if (empty == lastpos)
00133 return (0);
00134
00135
00136 lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec);
00137
00138 pos=hp_find_hash(&keyinfo->block, hp_mask(lastpos_hashnr, share->blength,
00139 share->records));
00140 if (pos == empty)
00141 {
00142 empty[0]=lastpos[0];
00143 return(0);
00144 }
00145 pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
00146
00147 pos3= hp_find_hash(&keyinfo->block,
00148 hp_mask(pos_hashnr, share->blength, share->records));
00149 if (pos != pos3)
00150 {
00151 empty[0]=pos[0];
00152 pos[0]=lastpos[0];
00153 hp_movelink(pos, pos3, empty);
00154 return(0);
00155 }
00156 pos2= hp_mask(lastpos_hashnr, blength, share->records + 1);
00157 if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1))
00158 {
00159 if (pos2 != share->records)
00160 {
00161 empty[0]=lastpos[0];
00162 hp_movelink(lastpos, pos, empty);
00163 return(0);
00164 }
00165 pos3= pos;
00166 }
00167 else
00168 {
00169 pos3= 0;
00170 keyinfo->hash_buckets--;
00171 }
00172
00173 empty[0]=lastpos[0];
00174 hp_movelink(pos3, empty, pos->next_key);
00175 pos->next_key=empty;
00176 return(0);
00177 }