1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2002, 2004-200 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* remove current record in heap-database */
|
|
17 |
||
1130.3.28
by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check. |
18 |
#include "heap_priv.h" |
1
by brian
clean slate |
19 |
|
481
by Brian Aker
Remove all of uchar. |
20 |
int heap_delete(HP_INFO *info, const unsigned char *record) |
1
by brian
clean slate |
21 |
{
|
481
by Brian Aker
Remove all of uchar. |
22 |
unsigned char *pos; |
1697.2.1
by Brian Aker
Encapsulate the internal share for HEAP. |
23 |
HP_SHARE *share=info->getShare(); |
1
by brian
clean slate |
24 |
HP_KEYDEF *keydef, *end, *p_lastinx; |
25 |
||
26 |
test_active(info); |
|
27 |
||
51.3.4
by Jay Pipes
Final removal from heap storage engine plus fixes from MontyT re: _mi_report_crashed() |
28 |
if (info->opt_flag & READ_CHECK_USED) |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
29 |
return(errno); /* Record changed */ |
1
by brian
clean slate |
30 |
share->changed=1; |
31 |
||
32 |
if ( --(share->records) < share->blength >> 1) share->blength>>=1; |
|
33 |
pos=info->current_ptr; |
|
34 |
||
35 |
p_lastinx = share->keydef + info->lastinx; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
36 |
for (keydef = share->keydef, end = keydef + share->keys; keydef < end; |
1
by brian
clean slate |
37 |
keydef++) |
38 |
{
|
|
1749.3.3
by Brian Aker
Remove another layer of dead code in heap. |
39 |
if (hp_delete_key(info, keydef, record, pos, keydef == p_lastinx)) |
1
by brian
clean slate |
40 |
goto err; |
41 |
}
|
|
42 |
||
43 |
info->update=HA_STATE_DELETED; |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
44 |
hp_free_chunks(&share->recordspace, pos); |
1
by brian
clean slate |
45 |
info->current_hash_ptr=0; |
46 |
||
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
47 |
return(0); |
1
by brian
clean slate |
48 |
err: |
49 |
if (++(share->records) == share->blength) |
|
50 |
share->blength+= share->blength; |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
51 |
return(errno); |
1
by brian
clean slate |
52 |
}
|
53 |
||
54 |
||
55 |
/*
|
|
56 |
Remove one key from hash-table
|
|
57 |
||
58 |
SYNPOSIS
|
|
59 |
hp_delete_key()
|
|
60 |
info Hash handler
|
|
61 |
keyinfo key definition of key that we want to delete
|
|
62 |
record row data to be deleted
|
|
63 |
recpos Pointer to heap record in memory
|
|
64 |
flag Is set if we want's to correct info->current_ptr
|
|
65 |
||
66 |
RETURN
|
|
67 |
0 Ok
|
|
68 |
other Error code
|
|
69 |
*/
|
|
70 |
||
71 |
int hp_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo, |
|
481
by Brian Aker
Remove all of uchar. |
72 |
const unsigned char *record, unsigned char *recpos, int flag) |
1
by brian
clean slate |
73 |
{
|
291
by Brian Aker
Head ulong conversion. |
74 |
uint32_t blength,pos2,pos_hashnr,lastpos_hashnr; |
1
by brian
clean slate |
75 |
HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr; |
1697.2.1
by Brian Aker
Encapsulate the internal share for HEAP. |
76 |
HP_SHARE *share=info->getShare(); |
1
by brian
clean slate |
77 |
|
78 |
blength=share->blength; |
|
79 |
if (share->records+1 == blength) |
|
80 |
blength+= blength; |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
81 |
|
82 |
/* find the very last HASH_INFO pointer in the index */
|
|
83 |
/* note that records has already been decremented */
|
|
1
by brian
clean slate |
84 |
lastpos=hp_find_hash(&keyinfo->block,share->records); |
85 |
last_ptr=0; |
|
86 |
||
87 |
/* Search after record with key */
|
|
88 |
pos= hp_find_hash(&keyinfo->block, |
|
89 |
hp_mask(hp_rec_hashnr(keyinfo, record), blength, |
|
90 |
share->records + 1)); |
|
91 |
gpos = pos3 = 0; |
|
92 |
||
93 |
while (pos->ptr_to_rec != recpos) |
|
94 |
{
|
|
95 |
if (flag && !hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 0)) |
|
96 |
last_ptr=pos; /* Previous same key */ |
|
97 |
gpos=pos; |
|
98 |
if (!(pos=pos->next_key)) |
|
99 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
100 |
return(errno=HA_ERR_CRASHED); /* This shouldn't happend */ |
1
by brian
clean slate |
101 |
}
|
102 |
}
|
|
103 |
||
104 |
/* Remove link to record */
|
|
105 |
||
106 |
if (flag) |
|
107 |
{
|
|
108 |
/* Save for heap_rnext/heap_rprev */
|
|
109 |
info->current_hash_ptr=last_ptr; |
|
110 |
info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0; |
|
111 |
}
|
|
112 |
empty=pos; |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
113 |
if (gpos) { |
114 |
/* gpos says we have previous HASH_INFO, change previous to point to next, this way unlinking "empty" */
|
|
115 |
gpos->next_key=pos->next_key; |
|
116 |
}
|
|
1
by brian
clean slate |
117 |
else if (pos->next_key) |
118 |
{
|
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
119 |
/* no previous gpos, this pos is the first in the list and it has pointer to "next" */
|
120 |
/* move next HASH_INFO data to our pos, to free up space at the next position */
|
|
121 |
/* remember next pos as "empty", nobody refers to "empty" at this point */
|
|
1
by brian
clean slate |
122 |
empty=pos->next_key; |
123 |
pos->ptr_to_rec=empty->ptr_to_rec; |
|
124 |
pos->next_key=empty->next_key; |
|
125 |
}
|
|
126 |
else
|
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
127 |
{
|
128 |
/* this was the only HASH_INFO at this position */
|
|
1
by brian
clean slate |
129 |
keyinfo->hash_buckets--; |
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
130 |
}
|
1
by brian
clean slate |
131 |
|
132 |
if (empty == lastpos) /* deleted last hash key */ |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
133 |
return (0); |
1
by brian
clean slate |
134 |
|
135 |
/* Move the last key (lastpos) */
|
|
136 |
lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec); |
|
137 |
/* pos is where lastpos should be */
|
|
138 |
pos=hp_find_hash(&keyinfo->block, hp_mask(lastpos_hashnr, share->blength, |
|
139 |
share->records)); |
|
140 |
if (pos == empty) /* Move to empty position. */ |
|
141 |
{
|
|
142 |
empty[0]=lastpos[0]; |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
143 |
return(0); |
1
by brian
clean slate |
144 |
}
|
145 |
pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec); |
|
146 |
/* pos3 is where the pos should be */
|
|
147 |
pos3= hp_find_hash(&keyinfo->block, |
|
148 |
hp_mask(pos_hashnr, share->blength, share->records)); |
|
149 |
if (pos != pos3) |
|
150 |
{ /* pos is on wrong posit */ |
|
151 |
empty[0]=pos[0]; /* Save it here */ |
|
152 |
pos[0]=lastpos[0]; /* This shold be here */ |
|
153 |
hp_movelink(pos, pos3, empty); /* Fix link to pos */ |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
154 |
return(0); |
1
by brian
clean slate |
155 |
}
|
156 |
pos2= hp_mask(lastpos_hashnr, blength, share->records + 1); |
|
157 |
if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1)) |
|
158 |
{ /* Identical key-positions */ |
|
159 |
if (pos2 != share->records) |
|
160 |
{
|
|
161 |
empty[0]=lastpos[0]; |
|
162 |
hp_movelink(lastpos, pos, empty); |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
163 |
return(0); |
1
by brian
clean slate |
164 |
}
|
165 |
pos3= pos; /* Link pos->next after lastpos */ |
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
pos3= 0; /* Different positions merge */ |
|
170 |
keyinfo->hash_buckets--; |
|
171 |
}
|
|
172 |
||
173 |
empty[0]=lastpos[0]; |
|
174 |
hp_movelink(pos3, empty, pos->next_key); |
|
175 |
pos->next_key=empty; |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
176 |
return(0); |
1
by brian
clean slate |
177 |
}
|