12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
/* Write a row to a MyISAM table */
18
#include "myisam_priv.h"
20
#include "drizzled/internal/m_string.h"
21
#include <drizzled/util/test.h>
23
using namespace drizzled;
25
21
#define MAX_POINTER_LENGTH 8
27
23
/* Functions declared in this file */
29
25
static int w_search(MI_INFO *info,MI_KEYDEF *keyinfo,
30
uint32_t comp_flag, unsigned char *key,
31
uint32_t key_length, internal::my_off_t pos, unsigned char *father_buff,
32
unsigned char *father_keypos, internal::my_off_t father_page,
34
static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
35
unsigned char *curr_buff,unsigned char *father_buff,
36
unsigned char *father_keypos,internal::my_off_t father_page);
37
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
38
unsigned char *key, uint32_t *return_key_length,
39
unsigned char **after_key);
40
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
42
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
26
uint comp_flag, uchar *key,
27
uint key_length, my_off_t pos, uchar *father_buff,
28
uchar *father_keypos, my_off_t father_page,
30
static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
31
uchar *curr_buff,uchar *father_buff,
32
uchar *father_keypos,my_off_t father_page);
33
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
34
uchar *key, uint *return_key_length,
36
int _mi_ck_write_tree(register MI_INFO *info, uint keynr,uchar *key,
38
int _mi_ck_write_btree(register MI_INFO *info, uint keynr,uchar *key,
45
41
/* Write new record to database */
47
int mi_write(MI_INFO *info, unsigned char *record)
43
int mi_write(MI_INFO *info, uchar *record)
49
45
MYISAM_SHARE *share=info->s;
52
internal::my_off_t filepos;
54
bool lock_tree= share->concurrent_insert;
50
my_bool lock_tree= share->concurrent_insert;
51
DBUG_ENTER("mi_write");
52
DBUG_PRINT("enter",("isam: %d data: %d",info->s->kfile,info->dfile));
54
DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
55
mi_print_error(info->s, HA_ERR_CRASHED);
56
DBUG_RETURN(my_errno= HA_ERR_CRASHED););
56
57
if (share->options & HA_OPTION_READ_ONLY_DATA)
59
DBUG_RETURN(my_errno=EACCES);
60
61
if (_mi_readinfo(info,F_WRLCK,1))
62
DBUG_RETURN(my_errno);
63
dont_break(); /* Dont allow SIGHUP or SIGINT */
64
#if !defined(NO_LOCKING) && defined(USE_RECORD_LOCK)
65
if (!info->locked && my_lock(info->dfile,F_WRLCK,0L,F_TO_EOF,
66
MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
62
69
filepos= ((share->state.dellink != HA_OFFSET_ERROR &&
63
70
!info->append_insert_at_end) ?
64
71
share->state.dellink :
96
103
if (mi_is_key_active(share->state.key_map, i))
98
bool local_lock_tree= (lock_tree &&
105
my_bool local_lock_tree= (lock_tree &&
99
106
!(info->bulk_insert &&
100
107
is_tree_inited(&info->bulk_insert[i])));
101
108
if (local_lock_tree)
110
rw_wrlock(&share->key_root_lock[i]);
103
111
share->keyinfo[i].version++;
113
if (share->keyinfo[i].flag & HA_FULLTEXT )
115
if (_mi_ft_add(info,i, buff, record, filepos))
118
rw_unlock(&share->key_root_lock[i]);
119
DBUG_PRINT("error",("Got error: %d on write",my_errno));
106
125
if (share->keyinfo[i].ck_insert(info,i,buff,
107
126
_mi_make_key(info,i,buff,record,filepos)))
129
rw_unlock(&share->key_root_lock[i]);
130
DBUG_PRINT("error",("Got error: %d on write",my_errno));
113
135
/* The above changed info->lastkey2. Inform mi_rnext_same(). */
114
136
info->update&= ~HA_STATE_RNEXT_SAME;
139
rw_unlock(&share->key_root_lock[i]);
117
142
if (share->calc_checksum)
176
228
mi_mark_crashed(info);
178
230
info->update= (HA_STATE_CHANGED | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED);
182
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
183
return(errno=save_errno);
234
myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno);
235
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
236
allow_break(); /* Allow SIGHUP & SIGINT */
237
DBUG_RETURN(my_errno=save_errno);
187
241
/* Write one key to btree */
189
int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length)
243
int _mi_ck_write(MI_INFO *info, uint keynr, uchar *key, uint key_length)
245
DBUG_ENTER("_mi_ck_write");
191
247
if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
193
return(_mi_ck_write_tree(info, keynr, key, key_length));
249
DBUG_RETURN(_mi_ck_write_tree(info, keynr, key, key_length));
197
return(_mi_ck_write_btree(info, keynr, key, key_length));
253
DBUG_RETURN(_mi_ck_write_btree(info, keynr, key, key_length));
199
255
} /* _mi_ck_write */
225
282
error=_mi_ck_real_write_btree(info, keyinfo, key, key_length,
226
283
root, comp_flag);
284
if (info->ft1_to_ft2)
287
error= _mi_ft_convert_to_ft2(info, keynr, key);
288
delete_dynamic(info->ft1_to_ft2);
289
my_free((uchar*)info->ft1_to_ft2, MYF(0));
228
293
} /* _mi_ck_write_btree */
230
295
int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo,
231
unsigned char *key, uint32_t key_length, internal::my_off_t *root, uint32_t comp_flag)
296
uchar *key, uint key_length, my_off_t *root, uint comp_flag)
299
DBUG_ENTER("_mi_ck_real_write_btree");
234
300
/* key_length parameter is used only if comp_flag is SEARCH_FIND */
235
301
if (*root == HA_OFFSET_ERROR ||
236
302
(error=w_search(info, keyinfo, comp_flag, key, key_length,
237
*root, (unsigned char *) 0, (unsigned char*) 0,
238
(internal::my_off_t) 0, 1)) > 0)
303
*root, (uchar *) 0, (uchar*) 0,
304
(my_off_t) 0, 1)) > 0)
239
305
error=_mi_enlarge_root(info,keyinfo,key,root);
241
307
} /* _mi_ck_real_write_btree */
244
310
/* Make a new root with key as only pointer */
246
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, unsigned char *key,
247
internal::my_off_t *root)
312
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
249
uint32_t t_length,nod_flag;
315
uint t_length,nod_flag;
250
316
MI_KEY_PARAM s_temp;
251
317
MYISAM_SHARE *share=info->s;
318
DBUG_ENTER("_mi_enlarge_root");
253
320
nod_flag= (*root != HA_OFFSET_ERROR) ? share->base.key_reflength : 0;
254
321
_mi_kpointer(info,info->buff+2,*root); /* if nod */
255
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char*) 0,
256
(unsigned char*) 0, (unsigned char*) 0, key,&s_temp);
322
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar*) 0,
323
(uchar*) 0, (uchar*) 0, key,&s_temp);
257
324
mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
258
325
(*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
259
326
info->buff_used=info->page_changed=1; /* info->buff is used */
260
327
if ((*root= _mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR ||
261
328
_mi_write_keypage(info,keyinfo,*root,DFLT_INIT_HITS,info->buff))
264
331
} /* _mi_enlarge_root */
274
341
static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
275
uint32_t comp_flag, unsigned char *key, uint32_t key_length, internal::my_off_t page,
276
unsigned char *father_buff, unsigned char *father_keypos,
277
internal::my_off_t father_page, bool insert_last)
342
uint comp_flag, uchar *key, uint key_length, my_off_t page,
343
uchar *father_buff, uchar *father_keypos,
344
my_off_t father_page, my_bool insert_last)
280
uint32_t nod_flag, search_key_length;
281
unsigned char *temp_buff,*keypos;
282
unsigned char keybuff[MI_MAX_KEY_BUFF];
284
internal::my_off_t next_page, dupp_key_pos;
347
uint nod_flag, search_key_length;
348
uchar *temp_buff,*keypos;
349
uchar keybuff[MI_MAX_KEY_BUFF];
350
my_bool was_last_key;
351
my_off_t next_page, dupp_key_pos;
352
DBUG_ENTER("w_search");
353
DBUG_PRINT("enter",("page: %ld", (long) page));
286
355
search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
287
if (!(temp_buff= (unsigned char*) malloc(keyinfo->block_length+
356
if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
290
359
if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0))
304
373
dupp_key_pos= HA_OFFSET_ERROR;
375
if (keyinfo->flag & HA_FULLTEXT)
380
get_key_full_length_rdonly(off, keybuff);
381
subkeys=ft_sintXkorr(keybuff+off);
382
comp_flag=SEARCH_SAME;
385
/* normal word, one-level tree structure */
386
flag=(*keyinfo->bin_search)(info, keyinfo, temp_buff, key,
387
USE_WHOLE_KEY, comp_flag,
388
&keypos, keybuff, &was_last_key);
392
/* popular word. two-level tree. going down */
393
my_off_t root=dupp_key_pos;
394
keyinfo=&info->s->ft2_keyinfo;
395
get_key_full_length_rdonly(off, key);
397
keypos-=keyinfo->keylength+nod_flag; /* we'll modify key entry 'in vivo' */
398
error=_mi_ck_real_write_btree(info, keyinfo, key, 0,
400
_mi_dpointer(info, keypos+HA_FT_WLEN, root);
401
subkeys--; /* should there be underflow protection ? */
402
DBUG_ASSERT(subkeys < 0);
403
ft_intXstore(keypos, subkeys);
405
error=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff);
406
my_afree((uchar*) temp_buff);
410
else /* not HA_FULLTEXT, normal HA_NOSAME key */
307
412
info->dupp_key_pos= dupp_key_pos;
309
errno=HA_ERR_FOUND_DUPP_KEY;
413
my_afree((uchar*) temp_buff);
414
my_errno=HA_ERR_FOUND_DUPP_KEY;
313
418
if (flag == MI_FOUND_WRONG_KEY)
315
420
if (!was_last_key)
317
422
next_page=_mi_kpos(nod_flag,keypos);
360
466
int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo,
361
unsigned char *key, unsigned char *anc_buff, unsigned char *key_pos, unsigned char *key_buff,
362
unsigned char *father_buff, unsigned char *father_key_pos, internal::my_off_t father_page,
467
uchar *key, uchar *anc_buff, uchar *key_pos, uchar *key_buff,
468
uchar *father_buff, uchar *father_key_pos, my_off_t father_page,
365
uint32_t a_length,nod_flag;
471
uint a_length,nod_flag;
367
unsigned char *endpos, *prev_key;
473
uchar *endpos, *prev_key;
368
474
MI_KEY_PARAM s_temp;
475
DBUG_ENTER("_mi_insert");
476
DBUG_PRINT("enter",("key_pos: 0x%lx", (long) key_pos));
477
DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,keyinfo->seg,key,USE_WHOLE_KEY););
370
479
nod_flag=mi_test_if_nod(anc_buff);
371
480
a_length=mi_getint(anc_buff);
372
481
endpos= anc_buff+ a_length;
373
prev_key=(key_pos == anc_buff+2+nod_flag ? (unsigned char*) 0 : key_buff);
482
prev_key=(key_pos == anc_buff+2+nod_flag ? (uchar*) 0 : key_buff);
374
483
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
375
(key_pos == endpos ? (unsigned char*) 0 : key_pos),
484
(key_pos == endpos ? (uchar*) 0 : key_pos),
376
485
prev_key, prev_key,
488
if (key_pos != anc_buff+2+nod_flag && (keyinfo->flag &
489
(HA_BINARY_PACK_KEY | HA_PACK_KEY)))
491
DBUG_DUMP("prev_key",(uchar*) key_buff,_mi_keylength(keyinfo,key_buff));
493
if (keyinfo->flag & HA_PACK_KEY)
495
DBUG_PRINT("test",("t_length: %d ref_len: %d",
496
t_length,s_temp.ref_length));
497
DBUG_PRINT("test",("n_ref_len: %d n_length: %d key_pos: 0x%lx",
498
s_temp.n_ref_length,s_temp.n_length, (long) s_temp.key));
379
501
if (t_length > 0)
381
503
if (t_length >= keyinfo->maxlength*2+MAX_POINTER_LENGTH)
383
505
mi_print_error(info->s, HA_ERR_CRASHED);
384
errno=HA_ERR_CRASHED;
506
my_errno=HA_ERR_CRASHED;
387
internal::bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,(uint) (endpos-key_pos));
509
bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,(uint) (endpos-key_pos));
391
513
if (-t_length >= keyinfo->maxlength*2+MAX_POINTER_LENGTH)
393
515
mi_print_error(info->s, HA_ERR_CRASHED);
394
errno=HA_ERR_CRASHED;
516
my_errno=HA_ERR_CRASHED;
397
memmove(key_pos, key_pos - t_length, endpos - key_pos + t_length);
519
bmove(key_pos,key_pos-t_length,(uint) (endpos-key_pos)+t_length);
399
521
(*keyinfo->store_key)(keyinfo,key_pos,&s_temp);
400
522
a_length+=t_length;
401
523
mi_putint(anc_buff,a_length,nod_flag);
402
524
if (a_length <= keyinfo->block_length)
404
return(0); /* There is room on page */
526
if (keyinfo->block_length - a_length < 32 &&
527
keyinfo->flag & HA_FULLTEXT && key_pos == endpos &&
528
info->s->base.key_reflength <= info->s->base.rec_reflength &&
529
info->s->options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD))
532
Normal word. One-level tree. Page is almost full.
533
Let's consider converting.
534
We'll compare 'key' and the first key at anc_buff
536
uchar *a=key, *b=anc_buff+2+nod_flag;
537
uint alen, blen, ft2len=info->s->ft2_keyinfo.keylength;
538
/* the very first key on the page is always unpacked */
539
DBUG_ASSERT((*b & 128) == 0);
540
#if HA_FT_MAXLEN >= 127
541
blen= mi_uint2korr(b); b+=2;
545
get_key_length(alen,a);
546
DBUG_ASSERT(info->ft1_to_ft2==0);
548
ha_compare_text(keyinfo->seg->charset, a, alen, b, blen, 0, 0)==0)
550
/* yup. converting */
551
info->ft1_to_ft2=(DYNAMIC_ARRAY *)
552
my_malloc(sizeof(DYNAMIC_ARRAY), MYF(MY_WME));
553
my_init_dynamic_array(info->ft1_to_ft2, ft2len, 300, 50);
556
now, adding all keys from the page to dynarray
557
if the page is a leaf (if not keys will be deleted later)
561
/* let's leave the first key on the page, though, because
562
we cannot easily dispatch an empty page here */
564
for (a=anc_buff+a_length ; b < a ; b+=ft2len+2)
565
insert_dynamic(info->ft1_to_ft2, b);
567
/* fixing the page's length - it contains only one key now */
568
mi_putint(anc_buff,2+blen+ft2len+2,0);
570
/* the rest will be done when we're back from recursion */
573
DBUG_RETURN(0); /* There is room on page */
406
575
/* Page is full */
409
578
if (!(keyinfo->flag & (HA_VAR_LENGTH_KEY | HA_BINARY_PACK_KEY)) &&
410
579
father_buff && !insert_last)
411
return(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
580
DBUG_RETURN(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
412
581
father_key_pos,father_page));
413
return(_mi_split_page(info,keyinfo,key,anc_buff,key_buff, insert_last));
582
DBUG_RETURN(_mi_split_page(info,keyinfo,key,anc_buff,key_buff, insert_last));
414
583
} /* _mi_insert */
417
586
/* split a full page in two and assign emerging item to key */
419
588
int _mi_split_page(register MI_INFO *info, register MI_KEYDEF *keyinfo,
420
unsigned char *key, unsigned char *buff, unsigned char *key_buff,
421
bool insert_last_key)
589
uchar *key, uchar *buff, uchar *key_buff,
590
my_bool insert_last_key)
423
uint32_t length,a_length,key_ref_length,t_length,nod_flag,key_length;
424
unsigned char *key_pos,*pos, *after_key= NULL;
425
internal::my_off_t new_pos;
592
uint length,a_length,key_ref_length,t_length,nod_flag,key_length;
593
uchar *key_pos,*pos, *after_key= NULL;
426
595
MI_KEY_PARAM s_temp;
596
DBUG_ENTER("mi_split_page");
597
DBUG_DUMP("buff",(uchar*) buff,mi_getint(buff));
428
599
if (info->s->keyinfo+info->lastinx == keyinfo)
429
600
info->page_changed=1; /* Info->buff is used */
445
616
key_pos=after_key;
619
DBUG_PRINT("test",("Splitting nod"));
448
620
pos=key_pos-nod_flag;
449
memcpy(info->buff + 2, pos, nod_flag);
621
memcpy((uchar*) info->buff+2,(uchar*) pos,(size_t) nod_flag);
452
624
/* Move middle item to key and pointer to new page */
453
625
if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
455
627
_mi_kpointer(info,_mi_move_key(keyinfo,key,key_buff),new_pos);
457
629
/* Store new page */
458
630
if (!(*keyinfo->get_key)(keyinfo,nod_flag,&key_pos,key_buff))
461
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char *) 0,
462
(unsigned char*) 0, (unsigned char*) 0,
633
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar *) 0,
634
(uchar*) 0, (uchar*) 0,
463
635
key_buff, &s_temp);
464
636
length=(uint) ((buff+a_length)-key_pos);
465
memcpy(info->buff+key_ref_length+t_length, key_pos, length);
637
memcpy((uchar*) info->buff+key_ref_length+t_length,(uchar*) key_pos,
466
639
(*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp);
467
640
mi_putint(info->buff,length+t_length+key_ref_length,nod_flag);
469
642
if (_mi_write_keypage(info,keyinfo,new_pos,DFLT_INIT_HITS,info->buff))
471
return(2); /* Middle key up */
644
DBUG_DUMP("key",(uchar*) key,_mi_keylength(keyinfo,key));
645
DBUG_RETURN(2); /* Middle key up */
472
646
} /* _mi_split_page */
575
752
/* returns 0 if balance was done */
577
754
static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo,
578
unsigned char *key, unsigned char *curr_buff, unsigned char *father_buff,
579
unsigned char *father_key_pos, internal::my_off_t father_page)
755
uchar *key, uchar *curr_buff, uchar *father_buff,
756
uchar *father_key_pos, my_off_t father_page)
582
uint32_t k_length,father_length,father_keylength,nod_flag,curr_keylength,
759
uint k_length,father_length,father_keylength,nod_flag,curr_keylength,
583
760
right_length,left_length,new_right_length,new_left_length,extra_length,
585
unsigned char *pos,*buff,*extra_buff;
586
internal::my_off_t next_page,new_pos;
587
unsigned char tmp_part_key[MI_MAX_KEY_BUFF];
762
uchar *pos,*buff,*extra_buff;
763
my_off_t next_page,new_pos;
764
uchar tmp_part_key[MI_MAX_KEY_BUFF];
765
DBUG_ENTER("_mi_balance_page");
589
767
k_length=keyinfo->keylength;
590
768
father_length=mi_getint(father_buff);
631
812
if (left_length < new_left_length)
632
813
{ /* Move keys buff -> leaf */
633
814
pos=curr_buff+left_length;
634
memcpy(pos, father_key_pos, k_length);
635
length= new_left_length - left_length - k_length;
636
memcpy(pos+k_length, buff+2, length);
815
memcpy((uchar*) pos,(uchar*) father_key_pos, (size_t) k_length);
816
memcpy((uchar*) pos+k_length, (uchar*) buff+2,
817
(size_t) (length=new_left_length - left_length - k_length));
637
818
pos=buff+2+length;
638
memcpy(father_key_pos, pos, k_length);
639
memmove(buff+2, pos+k_length, new_right_length);
819
memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
820
bmove((uchar*) buff+2,(uchar*) pos+k_length,new_right_length);
642
823
{ /* Move keys -> buff */
644
internal::bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) buff+right_length,
825
bmove_upp((uchar*) buff+new_right_length,(uchar*) buff+right_length,
646
827
length=new_right_length-right_length-k_length;
647
memcpy(buff+2+length,father_key_pos, k_length);
828
memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
648
829
pos=curr_buff+new_left_length;
649
memcpy(father_key_pos, pos, k_length);
650
memcpy(buff+2, pos+k_length, length);
830
memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
831
memcpy((uchar*) buff+2,(uchar*) pos+k_length,(size_t) length);
653
834
if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) ||
654
835
_mi_write_keypage(info,keyinfo,father_page,DFLT_INIT_HITS,father_buff))
659
840
/* curr_buff[] and buff[] are full, lets split and make new nod */
664
845
new_left_length-=curr_keylength;
665
846
extra_length=nod_flag+left_length+right_length-
666
847
new_left_length-new_right_length-curr_keylength;
848
DBUG_PRINT("info",("left_length: %d right_length: %d new_left_length: %d new_right_length: %d extra_length: %d",
849
left_length, right_length,
850
new_left_length, new_right_length,
667
852
mi_putint(curr_buff,new_left_length,nod_flag);
668
853
mi_putint(buff,new_right_length,nod_flag);
669
854
mi_putint(extra_buff,extra_length+2,nod_flag);
671
856
/* move first largest keys to new page */
672
857
pos=buff+right_length-extra_length;
673
memcpy(extra_buff+2, pos, extra_length);
858
memcpy((uchar*) extra_buff+2,pos,(size_t) extra_length);
674
859
/* Save new parting key */
675
860
memcpy(tmp_part_key, pos-k_length,k_length);
676
861
/* Make place for new keys */
677
internal::bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) pos-k_length,
862
bmove_upp((uchar*) buff+new_right_length,(uchar*) pos-k_length,
678
863
right_length-extra_length-k_length-2);
679
864
/* Copy keys from left page */
680
865
pos= curr_buff+new_left_length;
681
length= left_length - new_left_length - k_length;
682
memcpy(buff+2, pos+k_length, length);
866
memcpy((uchar*) buff+2,(uchar*) pos+k_length,
867
(size_t) (length=left_length-new_left_length-k_length));
683
868
/* Copy old parting key */
684
memcpy(buff+2+length, father_key_pos, k_length);
869
memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
686
871
/* Move new parting keys up to caller */
687
memcpy((right ? key : father_key_pos), pos, k_length);
688
memcpy((right ? father_key_pos : key), tmp_part_key, k_length);
872
memcpy((uchar*) (right ? key : father_key_pos),pos,(size_t) k_length);
873
memcpy((uchar*) (right ? father_key_pos : key),tmp_part_key, k_length);
690
875
if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
712
897
} bulk_insert_param;
714
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
899
int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
903
DBUG_ENTER("_mi_ck_write_tree");
719
905
error= tree_insert(&info->bulk_insert[keynr], key,
720
906
key_length + info->s->rec_reflength,
721
907
info->bulk_insert[keynr].custom_arg) ? 0 : HA_ERR_OUT_OF_MEM ;
724
910
} /* _mi_ck_write_tree */
727
913
/* typeof(_mi_keys_compare)=qsort_cmp2 */
729
static int keys_compare(bulk_insert_param *param, unsigned char *key1, unsigned char *key2)
915
static int keys_compare(bulk_insert_param *param, uchar *key1, uchar *key2)
731
uint32_t not_used[2];
732
918
return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg,
733
919
key1, key2, USE_WHOLE_KEY, SEARCH_SAME,
738
static int keys_free(unsigned char *key, TREE_FREE mode, bulk_insert_param *param)
924
static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
741
927
Probably I can use info->lastkey here, but I'm not sure,
742
928
and to be safe I'd better use local lastkey.
744
unsigned char lastkey[MI_MAX_KEY_BUFF];
930
uchar lastkey[MI_MAX_KEY_BUFF];
746
932
MI_KEYDEF *keyinfo;
750
936
if (param->info->s->concurrent_insert)
938
rw_wrlock(¶m->info->s->key_root_lock[param->keynr]);
752
939
param->info->s->keyinfo[param->keynr].version++;