16
16
/* Remove a row from a MyISAM table */
18
#include "myisamdef.h"
19
#include <drizzled/util/test.h>
21
static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uint32_t comp_flag,
22
unsigned char *key,uint32_t key_length,my_off_t page,unsigned char *anc_buff);
23
static int del(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,unsigned char *anc_buff,
24
my_off_t leaf_page,unsigned char *leaf_buff,unsigned char *keypos,
25
my_off_t next_block,unsigned char *ret_key);
26
static int underflow(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *anc_buff,
27
my_off_t leaf_page,unsigned char *leaf_buff,unsigned char *keypos);
28
static uint32_t remove_key(MI_KEYDEF *keyinfo,uint32_t nod_flag,unsigned char *keypos,
29
unsigned char *lastkey,unsigned char *page_end,
21
static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uint comp_flag,
22
uchar *key,uint key_length,my_off_t page,uchar *anc_buff);
23
static int del(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,uchar *anc_buff,
24
my_off_t leaf_page,uchar *leaf_buff,uchar *keypos,
25
my_off_t next_block,uchar *ret_key);
26
static int underflow(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *anc_buff,
27
my_off_t leaf_page,uchar *leaf_buff,uchar *keypos);
28
static uint remove_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar *keypos,
29
uchar *lastkey,uchar *page_end,
30
30
my_off_t *next_block);
31
31
static int _mi_ck_real_delete(register MI_INFO *info,MI_KEYDEF *keyinfo,
32
unsigned char *key, uint32_t key_length, my_off_t *root);
35
int mi_delete(MI_INFO *info,const unsigned char *record)
32
uchar *key, uint key_length, my_off_t *root);
35
int mi_delete(MI_INFO *info,const uchar *record)
38
unsigned char *old_key;
42
42
MYISAM_SHARE *share=info->s;
43
DBUG_ENTER("mi_delete");
44
45
/* Test if record is in datafile */
47
DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
48
mi_print_error(info->s, HA_ERR_CRASHED);
49
DBUG_RETURN(my_errno= HA_ERR_CRASHED););
50
DBUG_EXECUTE_IF("my_error_test_undefined_error",
51
mi_print_error(info->s, INT_MAX);
52
DBUG_RETURN(my_errno= INT_MAX););
45
53
if (!(info->update & HA_STATE_AKTIV))
47
return(my_errno=HA_ERR_KEY_NOT_FOUND); /* No database read */
55
DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND); /* No database read */
49
57
if (share->options & HA_OPTION_READ_ONLY_DATA)
51
return(my_errno=EACCES);
59
DBUG_RETURN(my_errno=EACCES);
53
61
if (_mi_readinfo(info,F_WRLCK,1))
62
DBUG_RETURN(my_errno);
55
63
if (info->s->calc_checksum)
56
64
info->checksum=(*info->s->calc_checksum)(info,record);
57
65
if ((*share->compare_record)(info,record))
86
100
info->state->records--;
88
102
mi_sizestore(lastpos,info->lastpos);
89
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
103
myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,sizeof(lastpos),0);
104
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
105
allow_break(); /* Allow SIGHUP & SIGINT */
90
106
if (info->invalidator != 0)
108
DBUG_PRINT("info", ("invalidator... '%s' (delete)", info->filename));
92
109
(*info->invalidator)(info->filename);
93
110
info->invalidator=0;
98
115
save_errno=my_errno;
99
116
mi_sizestore(lastpos,info->lastpos);
117
myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos, sizeof(lastpos),0);
100
118
if (save_errno != HA_ERR_RECORD_CHANGED)
102
120
mi_print_error(info->s, HA_ERR_CRASHED);
103
121
mi_mark_crashed(info); /* mark table crashed */
105
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
123
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
106
124
info->update|=HA_STATE_WRITTEN; /* Buffer changed */
125
allow_break(); /* Allow SIGHUP & SIGINT */
107
126
my_errno=save_errno;
108
127
if (save_errno == HA_ERR_KEY_NOT_FOUND)
128
147
static int _mi_ck_real_delete(register MI_INFO *info, MI_KEYDEF *keyinfo,
129
unsigned char *key, uint32_t key_length, my_off_t *root)
148
uchar *key, uint key_length, my_off_t *root)
133
152
my_off_t old_root;
134
unsigned char *root_buff;
154
DBUG_ENTER("_mi_ck_real_delete");
136
156
if ((old_root=*root) == HA_OFFSET_ERROR)
138
158
mi_print_error(info->s, HA_ERR_CRASHED);
139
return(my_errno=HA_ERR_CRASHED);
159
DBUG_RETURN(my_errno=HA_ERR_CRASHED);
141
if (!(root_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
161
if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
142
162
MI_MAX_KEY_BUFF*2)))
144
return(my_errno=ENOMEM);
164
DBUG_PRINT("error",("Couldn't allocate memory"));
165
DBUG_RETURN(my_errno=ENOMEM);
167
DBUG_PRINT("info",("root_page: %ld", (long) old_root));
146
168
if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0))
151
if ((error=d_search(info,keyinfo, (SEARCH_SAME), key,key_length,old_root,root_buff)) > 0)
173
if ((error=d_search(info,keyinfo,
174
(keyinfo->flag & HA_FULLTEXT ? SEARCH_FIND | SEARCH_UPDATE
176
key,key_length,old_root,root_buff)) >0)
180
DBUG_PRINT("test",("Enlarging of root when deleting"));
155
181
error=_mi_enlarge_root(info,keyinfo,key,root);
157
183
else /* error == 1 */
188
215
static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
189
uint32_t comp_flag, unsigned char *key, uint32_t key_length,
190
my_off_t page, unsigned char *anc_buff)
216
uint comp_flag, uchar *key, uint key_length,
217
my_off_t page, uchar *anc_buff)
192
219
int flag,ret_value,save_flag;
193
uint32_t length,nod_flag,search_key_length;
195
unsigned char *leaf_buff,*keypos;
220
uint length,nod_flag,search_key_length;
222
uchar *leaf_buff,*keypos;
196
223
my_off_t leaf_page= 0, next_block;
197
unsigned char lastkey[MI_MAX_KEY_BUFF];
224
uchar lastkey[MI_MAX_KEY_BUFF];
225
DBUG_ENTER("d_search");
226
DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
199
228
search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
200
229
flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
201
230
comp_flag, &keypos, lastkey, &last_key);
202
231
if (flag == MI_FOUND_WRONG_KEY)
233
DBUG_PRINT("error",("Found wrong key"));
206
236
nod_flag=mi_test_if_nod(anc_buff);
238
if (!flag && keyinfo->flag & HA_FULLTEXT)
243
get_key_full_length_rdonly(off, lastkey);
244
subkeys=ft_sintXkorr(lastkey+off);
245
DBUG_ASSERT(info->ft1_to_ft2==0 || subkeys >=0);
246
comp_flag=SEARCH_SAME;
249
/* normal word, one-level tree structure */
250
if (info->ft1_to_ft2)
252
/* we're in ft1->ft2 conversion mode. Saving key data */
253
insert_dynamic(info->ft1_to_ft2, (lastkey+off));
257
/* we need exact match only if not in ft1->ft2 conversion mode */
258
flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key,USE_WHOLE_KEY,
259
comp_flag, &keypos, lastkey, &last_key);
261
/* fall through to normal delete */
265
/* popular word. two-level tree. going down */
270
if (!(tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&kpos,lastkey)))
272
mi_print_error(info->s, HA_ERR_CRASHED);
273
my_errno= HA_ERR_CRASHED;
276
root=_mi_dpos(info,nod_flag,kpos);
279
/* the last entry in sub-tree */
280
if (_mi_dispose(info, keyinfo, root,DFLT_INIT_HITS))
282
/* fall through to normal delete */
286
keyinfo=&info->s->ft2_keyinfo;
287
kpos-=keyinfo->keylength+nod_flag; /* we'll modify key entry 'in vivo' */
288
get_key_full_length_rdonly(off, key);
290
ret_value=_mi_ck_real_delete(info, &info->s->ft2_keyinfo,
291
key, HA_FT_WLEN, &root);
292
_mi_dpointer(info, kpos+HA_FT_WLEN, root);
294
ft_intXstore(kpos, subkeys);
296
ret_value=_mi_write_keypage(info,keyinfo,page,
297
DFLT_INIT_HITS,anc_buff);
298
DBUG_PRINT("exit",("Return: %d",ret_value));
299
DBUG_RETURN(ret_value);
211
306
leaf_page=_mi_kpos(nod_flag,keypos);
212
if (!(leaf_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
307
if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
213
308
MI_MAX_KEY_BUFF*2)))
310
DBUG_PRINT("error",("Couldn't allocate memory"));
312
DBUG_PRINT("exit",("Return: %d",-1));
218
315
if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
263
362
ret_value= underflow(info,keyinfo,anc_buff,leaf_page,leaf_buff,keypos);
265
364
{ /* This happens only with packed keys */
365
DBUG_PRINT("test",("Enlarging of key when deleting"));
266
366
if (!_mi_get_last_key(info,keyinfo,anc_buff,lastkey,keypos,&length))
270
370
ret_value=_mi_insert(info,keyinfo,key,anc_buff,keypos,lastkey,
271
(unsigned char*) 0,(unsigned char*) 0,(my_off_t) 0,(bool) 0);
371
(uchar*) 0,(uchar*) 0,(my_off_t) 0,(my_bool) 0);
274
374
if (ret_value == 0 && mi_getint(anc_buff) > keyinfo->block_length)
279
379
if (save_flag && ret_value != 1)
280
380
ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
281
my_afree((unsigned char*) leaf_buff);
383
DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
385
my_afree((uchar*) leaf_buff);
386
DBUG_PRINT("exit",("Return: %d",ret_value));
387
DBUG_RETURN(ret_value);
285
my_afree((unsigned char*) leaf_buff);
390
my_afree((uchar*) leaf_buff);
391
DBUG_PRINT("exit",("Error: %d",my_errno));
290
396
/* Remove a key that has a page-reference */
292
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, unsigned char *key,
293
unsigned char *anc_buff, my_off_t leaf_page, unsigned char *leaf_buff,
294
unsigned char *keypos, /* Pos to where deleted key was */
398
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key,
399
uchar *anc_buff, my_off_t leaf_page, uchar *leaf_buff,
400
uchar *keypos, /* Pos to where deleted key was */
295
401
my_off_t next_block,
296
unsigned char *ret_key) /* key before keypos in anc_buff */
402
uchar *ret_key) /* key before keypos in anc_buff */
298
404
int ret_value,length;
299
uint32_t a_length,nod_flag,tmp;
405
uint a_length,nod_flag,tmp;
300
406
my_off_t next_page;
301
unsigned char keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
407
uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
302
408
MYISAM_SHARE *share=info->s;
303
409
MI_KEY_PARAM s_temp;
411
DBUG_PRINT("enter",("leaf_page: %ld keypos: 0x%lx", (long) leaf_page,
413
DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
305
415
endpos=leaf_buff+mi_getint(leaf_buff);
306
416
if (!(key_start=_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
310
420
if ((nod_flag=mi_test_if_nod(leaf_buff)))
312
422
next_page= _mi_kpos(nod_flag,endpos);
313
if (!(next_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
423
if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
314
424
MI_MAX_KEY_BUFF*2)))
316
426
if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
430
DBUG_DUMP("next_page",(uchar*) next_buff,mi_getint(next_buff));
320
431
if ((ret_value=del(info,keyinfo,key,anc_buff,next_page,next_buff,
321
432
keypos,next_block,ret_key)) >0)
446
DBUG_PRINT("test",("Inserting of key when deleting"));
335
447
if (!_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
338
450
ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
339
(unsigned char*) 0,(unsigned char*) 0,(my_off_t) 0,0);
451
(uchar*) 0,(uchar*) 0,(my_off_t) 0,0);
342
454
if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
345
my_afree((unsigned char*) next_buff);
457
my_afree((uchar*) next_buff);
458
DBUG_RETURN(ret_value);
349
461
/* Remove last key from leaf page */
362
474
prev_key=(keypos == anc_buff+2+share->base.key_reflength ?
364
476
length=(*keyinfo->pack_key)(keyinfo,share->base.key_reflength,
365
keypos == endpos ? (unsigned char*) 0 : keypos,
477
keypos == endpos ? (uchar*) 0 : keypos,
366
478
prev_key, prev_key,
367
479
keybuff,&s_temp);
369
bmove_upp((unsigned char*) endpos+length,(unsigned char*) endpos,(uint) (endpos-keypos));
481
bmove_upp((uchar*) endpos+length,(uchar*) endpos,(uint) (endpos-keypos));
371
memcpy(keypos,keypos-length, (int) (endpos-keypos)+length);
483
bmove(keypos,keypos-length, (int) (endpos-keypos)+length);
372
484
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
373
485
/* Save pointer to next leaf */
374
486
if (!(*keyinfo->get_key)(keyinfo,share->base.key_reflength,&keypos,ret_key))
376
488
_mi_kpointer(info,keypos - share->base.key_reflength,next_block);
377
489
mi_putint(anc_buff,a_length+length,share->base.key_reflength);
379
return( mi_getint(leaf_buff) <=
491
DBUG_RETURN( mi_getint(leaf_buff) <=
380
492
(info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
381
493
(uint) keyinfo->underflow_block_length));
387
499
/* Balances adjacent pages if underflow occours */
389
501
static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo,
390
unsigned char *anc_buff,
391
503
my_off_t leaf_page,/* Ancestor page and underflow page */
392
unsigned char *leaf_buff,
393
unsigned char *keypos) /* Position to pos after key */
505
uchar *keypos) /* Position to pos after key */
396
uint32_t length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
508
uint length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
397
509
key_reflength,key_length;
398
510
my_off_t next_page;
399
unsigned char anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
511
uchar anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
400
512
*buff,*endpos,*next_keypos,*anc_pos,*half_pos,*temp_pos,*prev_key,
402
514
MI_KEY_PARAM s_temp;
403
515
MYISAM_SHARE *share=info->s;
516
DBUG_ENTER("underflow");
517
DBUG_PRINT("enter",("leaf_page: %ld keypos: 0x%lx",(long) leaf_page,
519
DBUG_DUMP("anc_buff",(uchar*) anc_buff,mi_getint(anc_buff));
520
DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
406
523
info->buff_used=1;
434
553
if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0))
436
555
buff_length=mi_getint(buff);
556
DBUG_DUMP("next",(uchar*) buff,buff_length);
438
558
/* find keys to make a big key-page */
439
memcpy(next_keypos - key_reflength, buff + 2, key_reflength);
559
bmove((uchar*) next_keypos-key_reflength,(uchar*) buff+2,
440
561
if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,next_keypos,&length)
441
562
|| !_mi_get_last_key(info,keyinfo,leaf_buff,leaf_key,
442
563
leaf_buff+leaf_length,&length))
445
566
/* merge pages and put parting key from anc_buff between */
446
prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
567
prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
447
568
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,buff+p_length,
448
569
prev_key, prev_key,
449
570
anc_key, &s_temp);
450
571
length=buff_length-p_length;
451
572
endpos=buff+length+leaf_length+t_length;
452
573
/* buff will always be larger than before !*/
453
bmove_upp((unsigned char*) endpos, (unsigned char*) buff+buff_length,length);
454
memcpy(buff, leaf_buff, leaf_length);
574
bmove_upp((uchar*) endpos, (uchar*) buff+buff_length,length);
575
memcpy((uchar*) buff, (uchar*) leaf_buff,(size_t) leaf_length);
455
576
(*keyinfo->store_key)(keyinfo,buff+leaf_length,&s_temp);
456
577
buff_length=(uint) (endpos-buff);
457
578
mi_putint(buff,buff_length,nod_flag);
468
589
if (buff_length <= keyinfo->block_length)
469
590
{ /* Keys in one page */
470
memcpy(leaf_buff, buff, buff_length);
591
memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) buff_length);
471
592
if (_mi_dispose(info,keyinfo,next_page,DFLT_INIT_HITS))
475
596
{ /* Page is full */
476
597
endpos=anc_buff+anc_length;
598
DBUG_PRINT("test",("anc_buff: 0x%lx endpos: 0x%lx",
599
(long) anc_buff, (long) endpos));
477
600
if (keypos != anc_buff+2+key_reflength &&
478
601
!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length))
481
604
&key_length, &after_key)))
483
606
length=(uint) (half_pos-buff);
484
memcpy(leaf_buff, buff, length);
607
memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) length);
485
608
mi_putint(leaf_buff,length,nod_flag);
487
610
/* Correct new keypointer to leaf_page */
488
611
half_pos=after_key;
489
612
_mi_kpointer(info,leaf_key+key_length,next_page);
490
613
/* Save key in anc_buff */
491
prev_key=(keypos == anc_buff+2+key_reflength ? (unsigned char*) 0 : anc_key),
614
prev_key=(keypos == anc_buff+2+key_reflength ? (uchar*) 0 : anc_key),
492
615
t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
493
(keypos == endpos ? (unsigned char*) 0 :
616
(keypos == endpos ? (uchar*) 0 :
495
618
prev_key, prev_key,
496
619
leaf_key, &s_temp);
497
620
if (t_length >= 0)
498
bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,
621
bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,
499
622
(uint) (endpos-keypos));
501
memcpy(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
624
bmove(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
502
625
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
503
626
mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
505
628
/* Store key first in new page */
507
memcpy(buff + 2, half_pos - nod_flag, nod_flag);
630
bmove((uchar*) buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
508
631
if (!(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key))
510
t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (unsigned char*) 0,
511
(unsigned char*) 0, (unsigned char *) 0,
633
t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (uchar*) 0,
634
(uchar*) 0, (uchar *) 0,
512
635
leaf_key, &s_temp);
513
636
/* t_length will always be > 0 for a new page !*/
514
637
length=(uint) ((buff+mi_getint(buff))-half_pos);
515
memcpy(buff + p_length + t_length, half_pos, length);
638
bmove((uchar*) buff+p_length+t_length,(uchar*) half_pos,(size_t) length);
516
639
(*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp);
517
640
mi_putint(buff,length+t_length+p_length,nod_flag);
546
673
/* merge pages and put parting key from anc_buff between */
547
prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
674
prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
548
675
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
549
676
(leaf_length == p_length ?
550
(unsigned char*) 0 : leaf_buff+p_length),
677
(uchar*) 0 : leaf_buff+p_length),
551
678
prev_key, prev_key,
552
679
anc_key, &s_temp);
553
680
if (t_length >= 0)
554
memcpy(endpos+t_length,leaf_buff+p_length, leaf_length-p_length);
681
bmove((uchar*) endpos+t_length,(uchar*) leaf_buff+p_length,
682
(size_t) (leaf_length-p_length));
555
683
else /* We gained space */
556
memcpy(endpos, leaf_buff+((int) p_length-t_length),
557
leaf_length - p_length + t_length);
684
bmove((uchar*) endpos,(uchar*) leaf_buff+((int) p_length-t_length),
685
(size_t) (leaf_length-p_length+t_length));
559
687
(*keyinfo->store_key)(keyinfo,endpos,&s_temp);
560
688
buff_length=buff_length+leaf_length-p_length+t_length;
587
715
_mi_kpointer(info,leaf_key+key_length,leaf_page);
588
716
/* Save key in anc_buff */
717
DBUG_DUMP("anc_buff",(uchar*) anc_buff,anc_length);
718
DBUG_DUMP("key_to_anc",(uchar*) leaf_key,key_length);
590
720
temp_pos=anc_buff+anc_length;
591
721
t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
592
keypos == temp_pos ? (unsigned char*) 0
722
keypos == temp_pos ? (uchar*) 0
594
724
anc_pos, anc_pos,
595
725
leaf_key,&s_temp);
596
726
if (t_length > 0)
597
bmove_upp((unsigned char*) temp_pos+t_length,(unsigned char*) temp_pos,
727
bmove_upp((uchar*) temp_pos+t_length,(uchar*) temp_pos,
598
728
(uint) (temp_pos-keypos));
600
memcpy(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
730
bmove(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
601
731
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
602
732
mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
604
734
/* Store first key on new page */
606
memcpy(leaf_buff+2, half_pos - nod_flag, nod_flag);
736
bmove((uchar*) leaf_buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
607
737
if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key)))
609
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (unsigned char*) 0,
610
(unsigned char*) 0, (unsigned char*) 0, leaf_key, &s_temp);
739
DBUG_DUMP("key_to_leaf",(uchar*) leaf_key,length);
740
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
741
(uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
611
742
length=(uint) ((buff+buff_length)-half_pos);
612
memcpy(leaf_buff + p_length + t_length, half_pos, length);
743
DBUG_PRINT("info",("t_length: %d length: %d",t_length,(int) length));
744
bmove((uchar*) leaf_buff+p_length+t_length,(uchar*) half_pos,
613
746
(*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
614
747
mi_putint(leaf_buff,length+t_length+p_length,nod_flag);
615
748
if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
632
765
returns how many chars was removed or 0 on error
635
static uint32_t remove_key(MI_KEYDEF *keyinfo, uint32_t nod_flag,
636
unsigned char *keypos, /* Where key starts */
637
unsigned char *lastkey, /* key to be removed */
638
unsigned char *page_end, /* End of page */
768
static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag,
769
uchar *keypos, /* Where key starts */
770
uchar *lastkey, /* key to be removed */
771
uchar *page_end, /* End of page */
639
772
my_off_t *next_block) /* ptr to next block */
642
unsigned char *start;
776
DBUG_ENTER("remove_key");
777
DBUG_PRINT("enter",("keypos: 0x%lx page_end: 0x%lx",(long) keypos, (long) page_end));
645
780
if (!(keyinfo->flag &