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));
90
105
if (info->invalidator != 0)
107
DBUG_PRINT("info", ("invalidator... '%s' (delete)", info->filename));
92
108
(*info->invalidator)(info->filename);
93
109
info->invalidator=0;
98
114
save_errno=my_errno;
99
115
mi_sizestore(lastpos,info->lastpos);
116
myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos, sizeof(lastpos),0);
100
117
if (save_errno != HA_ERR_RECORD_CHANGED)
102
119
mi_print_error(info->s, HA_ERR_CRASHED);
103
120
mi_mark_crashed(info); /* mark table crashed */
105
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
122
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
106
123
info->update|=HA_STATE_WRITTEN; /* Buffer changed */
107
124
my_errno=save_errno;
108
125
if (save_errno == HA_ERR_KEY_NOT_FOUND)
128
145
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)
146
uchar *key, uint key_length, my_off_t *root)
133
150
my_off_t old_root;
134
unsigned char *root_buff;
152
DBUG_ENTER("_mi_ck_real_delete");
136
154
if ((old_root=*root) == HA_OFFSET_ERROR)
138
156
mi_print_error(info->s, HA_ERR_CRASHED);
139
return(my_errno=HA_ERR_CRASHED);
157
DBUG_RETURN(my_errno=HA_ERR_CRASHED);
141
if (!(root_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
159
if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
142
160
MI_MAX_KEY_BUFF*2)))
144
return(my_errno=ENOMEM);
162
DBUG_PRINT("error",("Couldn't allocate memory"));
163
DBUG_RETURN(my_errno=ENOMEM);
165
DBUG_PRINT("info",("root_page: %ld", (long) old_root));
146
166
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)
171
if ((error=d_search(info,keyinfo,
172
(keyinfo->flag & HA_FULLTEXT ? SEARCH_FIND | SEARCH_UPDATE
174
key,key_length,old_root,root_buff)) >0)
178
DBUG_PRINT("test",("Enlarging of root when deleting"));
155
179
error=_mi_enlarge_root(info,keyinfo,key,root);
157
181
else /* error == 1 */
188
213
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)
214
uint comp_flag, uchar *key, uint key_length,
215
my_off_t page, uchar *anc_buff)
192
217
int flag,ret_value,save_flag;
193
uint32_t length,nod_flag,search_key_length;
195
unsigned char *leaf_buff,*keypos;
218
uint length,nod_flag,search_key_length;
220
uchar *leaf_buff,*keypos;
196
221
my_off_t leaf_page= 0, next_block;
197
unsigned char lastkey[MI_MAX_KEY_BUFF];
222
uchar lastkey[MI_MAX_KEY_BUFF];
223
DBUG_ENTER("d_search");
224
DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
199
226
search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
200
227
flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
201
228
comp_flag, &keypos, lastkey, &last_key);
202
229
if (flag == MI_FOUND_WRONG_KEY)
231
DBUG_PRINT("error",("Found wrong key"));
206
234
nod_flag=mi_test_if_nod(anc_buff);
236
if (!flag && keyinfo->flag & HA_FULLTEXT)
241
get_key_full_length_rdonly(off, lastkey);
242
subkeys=ft_sintXkorr(lastkey+off);
243
DBUG_ASSERT(info->ft1_to_ft2==0 || subkeys >=0);
244
comp_flag=SEARCH_SAME;
247
/* normal word, one-level tree structure */
248
if (info->ft1_to_ft2)
250
/* we're in ft1->ft2 conversion mode. Saving key data */
251
insert_dynamic(info->ft1_to_ft2, (lastkey+off));
255
/* we need exact match only if not in ft1->ft2 conversion mode */
256
flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key,USE_WHOLE_KEY,
257
comp_flag, &keypos, lastkey, &last_key);
259
/* fall through to normal delete */
263
/* popular word. two-level tree. going down */
268
if (!(tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&kpos,lastkey)))
270
mi_print_error(info->s, HA_ERR_CRASHED);
271
my_errno= HA_ERR_CRASHED;
274
root=_mi_dpos(info,nod_flag,kpos);
277
/* the last entry in sub-tree */
278
if (_mi_dispose(info, keyinfo, root,DFLT_INIT_HITS))
280
/* fall through to normal delete */
284
keyinfo=&info->s->ft2_keyinfo;
285
kpos-=keyinfo->keylength+nod_flag; /* we'll modify key entry 'in vivo' */
286
get_key_full_length_rdonly(off, key);
288
ret_value=_mi_ck_real_delete(info, &info->s->ft2_keyinfo,
289
key, HA_FT_WLEN, &root);
290
_mi_dpointer(info, kpos+HA_FT_WLEN, root);
292
ft_intXstore(kpos, subkeys);
294
ret_value=_mi_write_keypage(info,keyinfo,page,
295
DFLT_INIT_HITS,anc_buff);
296
DBUG_PRINT("exit",("Return: %d",ret_value));
297
DBUG_RETURN(ret_value);
211
304
leaf_page=_mi_kpos(nod_flag,keypos);
212
if (!(leaf_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
305
if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
213
306
MI_MAX_KEY_BUFF*2)))
308
DBUG_PRINT("error",("Couldn't allocate memory"));
310
DBUG_PRINT("exit",("Return: %d",-1));
218
313
if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
263
360
ret_value= underflow(info,keyinfo,anc_buff,leaf_page,leaf_buff,keypos);
265
362
{ /* This happens only with packed keys */
363
DBUG_PRINT("test",("Enlarging of key when deleting"));
266
364
if (!_mi_get_last_key(info,keyinfo,anc_buff,lastkey,keypos,&length))
270
368
ret_value=_mi_insert(info,keyinfo,key,anc_buff,keypos,lastkey,
271
(unsigned char*) 0,(unsigned char*) 0,(my_off_t) 0,(bool) 0);
369
(uchar*) 0,(uchar*) 0,(my_off_t) 0,(my_bool) 0);
274
372
if (ret_value == 0 && mi_getint(anc_buff) > keyinfo->block_length)
279
377
if (save_flag && ret_value != 1)
280
378
ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
281
my_afree((unsigned char*) leaf_buff);
381
DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
383
my_afree((uchar*) leaf_buff);
384
DBUG_PRINT("exit",("Return: %d",ret_value));
385
DBUG_RETURN(ret_value);
285
my_afree((unsigned char*) leaf_buff);
388
my_afree((uchar*) leaf_buff);
389
DBUG_PRINT("exit",("Error: %d",my_errno));
290
394
/* 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 */
396
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key,
397
uchar *anc_buff, my_off_t leaf_page, uchar *leaf_buff,
398
uchar *keypos, /* Pos to where deleted key was */
295
399
my_off_t next_block,
296
unsigned char *ret_key) /* key before keypos in anc_buff */
400
uchar *ret_key) /* key before keypos in anc_buff */
298
402
int ret_value,length;
299
uint32_t a_length,nod_flag,tmp;
403
uint a_length,nod_flag,tmp;
300
404
my_off_t next_page;
301
unsigned char keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
405
uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
302
406
MYISAM_SHARE *share=info->s;
303
407
MI_KEY_PARAM s_temp;
409
DBUG_PRINT("enter",("leaf_page: %ld keypos: 0x%lx", (long) leaf_page,
411
DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
305
413
endpos=leaf_buff+mi_getint(leaf_buff);
306
414
if (!(key_start=_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
310
418
if ((nod_flag=mi_test_if_nod(leaf_buff)))
312
420
next_page= _mi_kpos(nod_flag,endpos);
313
if (!(next_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
421
if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
314
422
MI_MAX_KEY_BUFF*2)))
316
424
if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
428
DBUG_DUMP("next_page",(uchar*) next_buff,mi_getint(next_buff));
320
429
if ((ret_value=del(info,keyinfo,key,anc_buff,next_page,next_buff,
321
430
keypos,next_block,ret_key)) >0)
444
DBUG_PRINT("test",("Inserting of key when deleting"));
335
445
if (!_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
338
448
ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
339
(unsigned char*) 0,(unsigned char*) 0,(my_off_t) 0,0);
449
(uchar*) 0,(uchar*) 0,(my_off_t) 0,0);
342
452
if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
345
my_afree((unsigned char*) next_buff);
455
my_afree((uchar*) next_buff);
456
DBUG_RETURN(ret_value);
349
459
/* Remove last key from leaf page */
362
472
prev_key=(keypos == anc_buff+2+share->base.key_reflength ?
364
474
length=(*keyinfo->pack_key)(keyinfo,share->base.key_reflength,
365
keypos == endpos ? (unsigned char*) 0 : keypos,
475
keypos == endpos ? (uchar*) 0 : keypos,
366
476
prev_key, prev_key,
367
477
keybuff,&s_temp);
369
bmove_upp((unsigned char*) endpos+length,(unsigned char*) endpos,(uint) (endpos-keypos));
479
bmove_upp((uchar*) endpos+length,(uchar*) endpos,(uint) (endpos-keypos));
371
memcpy(keypos,keypos-length, (int) (endpos-keypos)+length);
481
bmove(keypos,keypos-length, (int) (endpos-keypos)+length);
372
482
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
373
483
/* Save pointer to next leaf */
374
484
if (!(*keyinfo->get_key)(keyinfo,share->base.key_reflength,&keypos,ret_key))
376
486
_mi_kpointer(info,keypos - share->base.key_reflength,next_block);
377
487
mi_putint(anc_buff,a_length+length,share->base.key_reflength);
379
return( mi_getint(leaf_buff) <=
489
DBUG_RETURN( mi_getint(leaf_buff) <=
380
490
(info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
381
491
(uint) keyinfo->underflow_block_length));
387
497
/* Balances adjacent pages if underflow occours */
389
499
static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo,
390
unsigned char *anc_buff,
391
501
my_off_t leaf_page,/* Ancestor page and underflow page */
392
unsigned char *leaf_buff,
393
unsigned char *keypos) /* Position to pos after key */
503
uchar *keypos) /* Position to pos after key */
396
uint32_t length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
506
uint length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
397
507
key_reflength,key_length;
398
508
my_off_t next_page;
399
unsigned char anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
509
uchar anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
400
510
*buff,*endpos,*next_keypos,*anc_pos,*half_pos,*temp_pos,*prev_key,
402
512
MI_KEY_PARAM s_temp;
403
513
MYISAM_SHARE *share=info->s;
514
DBUG_ENTER("underflow");
515
DBUG_PRINT("enter",("leaf_page: %ld keypos: 0x%lx",(long) leaf_page,
517
DBUG_DUMP("anc_buff",(uchar*) anc_buff,mi_getint(anc_buff));
518
DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
406
521
info->buff_used=1;
434
551
if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0))
436
553
buff_length=mi_getint(buff);
554
DBUG_DUMP("next",(uchar*) buff,buff_length);
438
556
/* find keys to make a big key-page */
439
memcpy(next_keypos - key_reflength, buff + 2, key_reflength);
557
bmove((uchar*) next_keypos-key_reflength,(uchar*) buff+2,
440
559
if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,next_keypos,&length)
441
560
|| !_mi_get_last_key(info,keyinfo,leaf_buff,leaf_key,
442
561
leaf_buff+leaf_length,&length))
445
564
/* merge pages and put parting key from anc_buff between */
446
prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
565
prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
447
566
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,buff+p_length,
448
567
prev_key, prev_key,
449
568
anc_key, &s_temp);
450
569
length=buff_length-p_length;
451
570
endpos=buff+length+leaf_length+t_length;
452
571
/* 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);
572
bmove_upp((uchar*) endpos, (uchar*) buff+buff_length,length);
573
memcpy((uchar*) buff, (uchar*) leaf_buff,(size_t) leaf_length);
455
574
(*keyinfo->store_key)(keyinfo,buff+leaf_length,&s_temp);
456
575
buff_length=(uint) (endpos-buff);
457
576
mi_putint(buff,buff_length,nod_flag);
468
587
if (buff_length <= keyinfo->block_length)
469
588
{ /* Keys in one page */
470
memcpy(leaf_buff, buff, buff_length);
589
memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) buff_length);
471
590
if (_mi_dispose(info,keyinfo,next_page,DFLT_INIT_HITS))
475
594
{ /* Page is full */
476
595
endpos=anc_buff+anc_length;
596
DBUG_PRINT("test",("anc_buff: 0x%lx endpos: 0x%lx",
597
(long) anc_buff, (long) endpos));
477
598
if (keypos != anc_buff+2+key_reflength &&
478
599
!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length))
481
602
&key_length, &after_key)))
483
604
length=(uint) (half_pos-buff);
484
memcpy(leaf_buff, buff, length);
605
memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) length);
485
606
mi_putint(leaf_buff,length,nod_flag);
487
608
/* Correct new keypointer to leaf_page */
488
609
half_pos=after_key;
489
610
_mi_kpointer(info,leaf_key+key_length,next_page);
490
611
/* Save key in anc_buff */
491
prev_key=(keypos == anc_buff+2+key_reflength ? (unsigned char*) 0 : anc_key),
612
prev_key=(keypos == anc_buff+2+key_reflength ? (uchar*) 0 : anc_key),
492
613
t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
493
(keypos == endpos ? (unsigned char*) 0 :
614
(keypos == endpos ? (uchar*) 0 :
495
616
prev_key, prev_key,
496
617
leaf_key, &s_temp);
497
618
if (t_length >= 0)
498
bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,
619
bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,
499
620
(uint) (endpos-keypos));
501
memcpy(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
622
bmove(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
502
623
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
503
624
mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
505
626
/* Store key first in new page */
507
memcpy(buff + 2, half_pos - nod_flag, nod_flag);
628
bmove((uchar*) buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
508
629
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,
631
t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (uchar*) 0,
632
(uchar*) 0, (uchar *) 0,
512
633
leaf_key, &s_temp);
513
634
/* t_length will always be > 0 for a new page !*/
514
635
length=(uint) ((buff+mi_getint(buff))-half_pos);
515
memcpy(buff + p_length + t_length, half_pos, length);
636
bmove((uchar*) buff+p_length+t_length,(uchar*) half_pos,(size_t) length);
516
637
(*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp);
517
638
mi_putint(buff,length+t_length+p_length,nod_flag);
546
671
/* merge pages and put parting key from anc_buff between */
547
prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
672
prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
548
673
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
549
674
(leaf_length == p_length ?
550
(unsigned char*) 0 : leaf_buff+p_length),
675
(uchar*) 0 : leaf_buff+p_length),
551
676
prev_key, prev_key,
552
677
anc_key, &s_temp);
553
678
if (t_length >= 0)
554
memcpy(endpos+t_length,leaf_buff+p_length, leaf_length-p_length);
679
bmove((uchar*) endpos+t_length,(uchar*) leaf_buff+p_length,
680
(size_t) (leaf_length-p_length));
555
681
else /* We gained space */
556
memcpy(endpos, leaf_buff+((int) p_length-t_length),
557
leaf_length - p_length + t_length);
682
bmove((uchar*) endpos,(uchar*) leaf_buff+((int) p_length-t_length),
683
(size_t) (leaf_length-p_length+t_length));
559
685
(*keyinfo->store_key)(keyinfo,endpos,&s_temp);
560
686
buff_length=buff_length+leaf_length-p_length+t_length;
587
713
_mi_kpointer(info,leaf_key+key_length,leaf_page);
588
714
/* Save key in anc_buff */
715
DBUG_DUMP("anc_buff",(uchar*) anc_buff,anc_length);
716
DBUG_DUMP("key_to_anc",(uchar*) leaf_key,key_length);
590
718
temp_pos=anc_buff+anc_length;
591
719
t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
592
keypos == temp_pos ? (unsigned char*) 0
720
keypos == temp_pos ? (uchar*) 0
594
722
anc_pos, anc_pos,
595
723
leaf_key,&s_temp);
596
724
if (t_length > 0)
597
bmove_upp((unsigned char*) temp_pos+t_length,(unsigned char*) temp_pos,
725
bmove_upp((uchar*) temp_pos+t_length,(uchar*) temp_pos,
598
726
(uint) (temp_pos-keypos));
600
memcpy(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
728
bmove(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
601
729
(*keyinfo->store_key)(keyinfo,keypos,&s_temp);
602
730
mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
604
732
/* Store first key on new page */
606
memcpy(leaf_buff+2, half_pos - nod_flag, nod_flag);
734
bmove((uchar*) leaf_buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
607
735
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);
737
DBUG_DUMP("key_to_leaf",(uchar*) leaf_key,length);
738
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
739
(uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
611
740
length=(uint) ((buff+buff_length)-half_pos);
612
memcpy(leaf_buff + p_length + t_length, half_pos, length);
741
DBUG_PRINT("info",("t_length: %d length: %d",t_length,(int) length));
742
bmove((uchar*) leaf_buff+p_length+t_length,(uchar*) half_pos,
613
744
(*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
614
745
mi_putint(leaf_buff,length+t_length+p_length,nod_flag);
615
746
if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
632
763
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 */
766
static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag,
767
uchar *keypos, /* Where key starts */
768
uchar *lastkey, /* key to be removed */
769
uchar *page_end, /* End of page */
639
770
my_off_t *next_block) /* ptr to next block */
642
unsigned char *start;
774
DBUG_ENTER("remove_key");
775
DBUG_PRINT("enter",("keypos: 0x%lx page_end: 0x%lx",(long) keypos, (long) page_end));
645
778
if (!(keyinfo->flag &