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;
18
#include "myisamdef.h"
25
20
#define MAX_POINTER_LENGTH 8
27
22
/* Functions declared in this file */
29
24
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,
25
uint comp_flag, uchar *key,
26
uint key_length, my_off_t pos, uchar *father_buff,
27
uchar *father_keypos, my_off_t father_page,
29
static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
30
uchar *curr_buff,uchar *father_buff,
31
uchar *father_keypos,my_off_t father_page);
32
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
33
uchar *key, uint *return_key_length,
35
int _mi_ck_write_tree(register MI_INFO *info, uint keynr,uchar *key,
37
int _mi_ck_write_btree(register MI_INFO *info, uint keynr,uchar *key,
45
40
/* Write new record to database */
47
int mi_write(MI_INFO *info, unsigned char *record)
42
int mi_write(MI_INFO *info, uchar *record)
49
44
MYISAM_SHARE *share=info->s;
52
internal::my_off_t filepos;
54
bool lock_tree= share->concurrent_insert;
49
my_bool lock_tree= share->concurrent_insert;
50
DBUG_ENTER("mi_write");
51
DBUG_PRINT("enter",("isam: %d data: %d",info->s->kfile,info->dfile));
53
DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
54
mi_print_error(info->s, HA_ERR_CRASHED);
55
DBUG_RETURN(my_errno= HA_ERR_CRASHED););
56
56
if (share->options & HA_OPTION_READ_ONLY_DATA)
58
DBUG_RETURN(my_errno=EACCES);
60
60
if (_mi_readinfo(info,F_WRLCK,1))
61
DBUG_RETURN(my_errno);
62
62
filepos= ((share->state.dellink != HA_OFFSET_ERROR &&
63
63
!info->append_insert_at_end) ?
64
64
share->state.dellink :
96
96
if (mi_is_key_active(share->state.key_map, i))
98
bool local_lock_tree= (lock_tree &&
98
my_bool local_lock_tree= (lock_tree &&
99
99
!(info->bulk_insert &&
100
100
is_tree_inited(&info->bulk_insert[i])));
101
101
if (local_lock_tree)
103
rw_wrlock(&share->key_root_lock[i]);
103
104
share->keyinfo[i].version++;
106
107
if (share->keyinfo[i].ck_insert(info,i,buff,
107
108
_mi_make_key(info,i,buff,record,filepos)))
111
rw_unlock(&share->key_root_lock[i]);
112
DBUG_PRINT("error",("Got error: %d on write",my_errno));
113
117
/* The above changed info->lastkey2. Inform mi_rnext_same(). */
114
118
info->update&= ~HA_STATE_RNEXT_SAME;
121
rw_unlock(&share->key_root_lock[i]);
117
124
if (share->calc_checksum)
176
199
mi_mark_crashed(info);
178
201
info->update= (HA_STATE_CHANGED | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED);
182
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
183
return(errno=save_errno);
205
myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno);
206
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
207
DBUG_RETURN(my_errno=save_errno);
187
211
/* Write one key to btree */
189
int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length)
213
int _mi_ck_write(MI_INFO *info, uint keynr, uchar *key, uint key_length)
215
DBUG_ENTER("_mi_ck_write");
191
217
if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
193
return(_mi_ck_write_tree(info, keynr, key, key_length));
219
DBUG_RETURN(_mi_ck_write_tree(info, keynr, key, key_length));
197
return(_mi_ck_write_btree(info, keynr, key, key_length));
223
DBUG_RETURN(_mi_ck_write_btree(info, keynr, key, key_length));
199
225
} /* _mi_ck_write */
225
252
error=_mi_ck_real_write_btree(info, keyinfo, key, key_length,
226
253
root, comp_flag);
228
255
} /* _mi_ck_write_btree */
230
257
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)
258
uchar *key, uint key_length, my_off_t *root, uint comp_flag)
261
DBUG_ENTER("_mi_ck_real_write_btree");
234
262
/* key_length parameter is used only if comp_flag is SEARCH_FIND */
235
263
if (*root == HA_OFFSET_ERROR ||
236
264
(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)
265
*root, (uchar *) 0, (uchar*) 0,
266
(my_off_t) 0, 1)) > 0)
239
267
error=_mi_enlarge_root(info,keyinfo,key,root);
241
269
} /* _mi_ck_real_write_btree */
244
272
/* 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)
274
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
249
uint32_t t_length,nod_flag;
277
uint t_length,nod_flag;
250
278
MI_KEY_PARAM s_temp;
251
279
MYISAM_SHARE *share=info->s;
280
DBUG_ENTER("_mi_enlarge_root");
253
282
nod_flag= (*root != HA_OFFSET_ERROR) ? share->base.key_reflength : 0;
254
283
_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);
284
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar*) 0,
285
(uchar*) 0, (uchar*) 0, key,&s_temp);
257
286
mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
258
287
(*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
259
288
info->buff_used=info->page_changed=1; /* info->buff is used */
260
289
if ((*root= _mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR ||
261
290
_mi_write_keypage(info,keyinfo,*root,DFLT_INIT_HITS,info->buff))
264
293
} /* _mi_enlarge_root */
274
303
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)
304
uint comp_flag, uchar *key, uint key_length, my_off_t page,
305
uchar *father_buff, uchar *father_keypos,
306
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;
309
uint nod_flag, search_key_length;
310
uchar *temp_buff,*keypos;
311
uchar keybuff[MI_MAX_KEY_BUFF];
312
my_bool was_last_key;
313
my_off_t next_page, dupp_key_pos;
314
DBUG_ENTER("w_search");
315
DBUG_PRINT("enter",("page: %ld", (long) page));
286
317
search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
287
if (!(temp_buff= (unsigned char*) malloc(keyinfo->block_length+
318
if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
290
321
if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0))
360
392
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,
393
uchar *key, uchar *anc_buff, uchar *key_pos, uchar *key_buff,
394
uchar *father_buff, uchar *father_key_pos, my_off_t father_page,
365
uint32_t a_length,nod_flag;
397
uint a_length,nod_flag;
367
unsigned char *endpos, *prev_key;
399
uchar *endpos, *prev_key;
368
400
MI_KEY_PARAM s_temp;
401
DBUG_ENTER("_mi_insert");
402
DBUG_PRINT("enter",("key_pos: 0x%lx", (long) key_pos));
403
DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,keyinfo->seg,key,USE_WHOLE_KEY););
370
405
nod_flag=mi_test_if_nod(anc_buff);
371
406
a_length=mi_getint(anc_buff);
372
407
endpos= anc_buff+ a_length;
373
prev_key=(key_pos == anc_buff+2+nod_flag ? (unsigned char*) 0 : key_buff);
408
prev_key=(key_pos == anc_buff+2+nod_flag ? (uchar*) 0 : key_buff);
374
409
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
375
(key_pos == endpos ? (unsigned char*) 0 : key_pos),
410
(key_pos == endpos ? (uchar*) 0 : key_pos),
376
411
prev_key, prev_key,
414
if (key_pos != anc_buff+2+nod_flag && (keyinfo->flag &
415
(HA_BINARY_PACK_KEY | HA_PACK_KEY)))
417
DBUG_DUMP("prev_key",(uchar*) key_buff,_mi_keylength(keyinfo,key_buff));
419
if (keyinfo->flag & HA_PACK_KEY)
421
DBUG_PRINT("test",("t_length: %d ref_len: %d",
422
t_length,s_temp.ref_length));
423
DBUG_PRINT("test",("n_ref_len: %d n_length: %d key_pos: 0x%lx",
424
s_temp.n_ref_length,s_temp.n_length, (long) s_temp.key));
379
427
if (t_length > 0)
381
429
if (t_length >= keyinfo->maxlength*2+MAX_POINTER_LENGTH)
383
431
mi_print_error(info->s, HA_ERR_CRASHED);
384
errno=HA_ERR_CRASHED;
432
my_errno=HA_ERR_CRASHED;
387
internal::bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,(uint) (endpos-key_pos));
435
bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,(uint) (endpos-key_pos));
391
439
if (-t_length >= keyinfo->maxlength*2+MAX_POINTER_LENGTH)
393
441
mi_print_error(info->s, HA_ERR_CRASHED);
394
errno=HA_ERR_CRASHED;
442
my_errno=HA_ERR_CRASHED;
397
memmove(key_pos, key_pos - t_length, endpos - key_pos + t_length);
445
bmove(key_pos,key_pos-t_length,(uint) (endpos-key_pos)+t_length);
399
447
(*keyinfo->store_key)(keyinfo,key_pos,&s_temp);
400
448
a_length+=t_length;
401
449
mi_putint(anc_buff,a_length,nod_flag);
402
450
if (a_length <= keyinfo->block_length)
404
return(0); /* There is room on page */
452
DBUG_RETURN(0); /* There is room on page */
406
454
/* Page is full */
409
457
if (!(keyinfo->flag & (HA_VAR_LENGTH_KEY | HA_BINARY_PACK_KEY)) &&
410
458
father_buff && !insert_last)
411
return(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
459
DBUG_RETURN(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
412
460
father_key_pos,father_page));
413
return(_mi_split_page(info,keyinfo,key,anc_buff,key_buff, insert_last));
461
DBUG_RETURN(_mi_split_page(info,keyinfo,key,anc_buff,key_buff, insert_last));
414
462
} /* _mi_insert */
417
465
/* split a full page in two and assign emerging item to key */
419
467
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)
468
uchar *key, uchar *buff, uchar *key_buff,
469
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;
471
uint length,a_length,key_ref_length,t_length,nod_flag,key_length;
472
uchar *key_pos,*pos, *after_key= NULL;
426
474
MI_KEY_PARAM s_temp;
475
DBUG_ENTER("mi_split_page");
476
DBUG_DUMP("buff",(uchar*) buff,mi_getint(buff));
428
478
if (info->s->keyinfo+info->lastinx == keyinfo)
429
479
info->page_changed=1; /* Info->buff is used */
445
495
key_pos=after_key;
498
DBUG_PRINT("test",("Splitting nod"));
448
499
pos=key_pos-nod_flag;
449
memcpy(info->buff + 2, pos, nod_flag);
500
memcpy((uchar*) info->buff+2,(uchar*) pos,(size_t) nod_flag);
452
503
/* Move middle item to key and pointer to new page */
453
504
if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
455
506
_mi_kpointer(info,_mi_move_key(keyinfo,key,key_buff),new_pos);
457
508
/* Store new page */
458
509
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,
512
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar *) 0,
513
(uchar*) 0, (uchar*) 0,
463
514
key_buff, &s_temp);
464
515
length=(uint) ((buff+a_length)-key_pos);
465
memcpy(info->buff+key_ref_length+t_length, key_pos, length);
516
memcpy((uchar*) info->buff+key_ref_length+t_length,(uchar*) key_pos,
466
518
(*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp);
467
519
mi_putint(info->buff,length+t_length+key_ref_length,nod_flag);
469
521
if (_mi_write_keypage(info,keyinfo,new_pos,DFLT_INIT_HITS,info->buff))
471
return(2); /* Middle key up */
523
DBUG_DUMP("key",(uchar*) key,_mi_keylength(keyinfo,key));
524
DBUG_RETURN(2); /* Middle key up */
472
525
} /* _mi_split_page */
480
533
after_key will contain the position to where the next key starts
483
unsigned char *_mi_find_half_pos(uint32_t nod_flag, MI_KEYDEF *keyinfo, unsigned char *page,
484
unsigned char *key, uint32_t *return_key_length,
485
unsigned char **after_key)
536
uchar *_mi_find_half_pos(uint nod_flag, MI_KEYDEF *keyinfo, uchar *page,
537
uchar *key, uint *return_key_length,
487
uint32_t keys,length,key_ref_length;
488
unsigned char *end,*lastpos;
540
uint keys,length,key_ref_length;
542
DBUG_ENTER("_mi_find_half_pos");
490
544
key_ref_length=2+nod_flag;
491
545
length=mi_getint(page)-key_ref_length;
523
579
key will contain the last key
526
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
527
unsigned char *key, uint32_t *return_key_length,
528
unsigned char **after_key)
582
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
583
uchar *key, uint *return_key_length,
532
uint32_t last_length= 0;
533
uint32_t key_ref_length;
534
unsigned char *end, *lastpos, *prevpos= NULL;
535
unsigned char key_buff[MI_MAX_KEY_BUFF];
586
uint keys, length, last_length=0, key_ref_length;
587
uchar *end, *lastpos, *prevpos= NULL;
588
uchar key_buff[MI_MAX_KEY_BUFF];
589
DBUG_ENTER("_mi_find_last_pos");
537
591
key_ref_length=2;
538
592
length=mi_getint(page)-key_ref_length;
575
631
/* returns 0 if balance was done */
577
633
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)
634
uchar *key, uchar *curr_buff, uchar *father_buff,
635
uchar *father_key_pos, my_off_t father_page)
582
uint32_t k_length,father_length,father_keylength,nod_flag,curr_keylength,
638
uint k_length,father_length,father_keylength,nod_flag,curr_keylength,
583
639
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];
641
uchar *pos,*buff,*extra_buff;
642
my_off_t next_page,new_pos;
643
uchar tmp_part_key[MI_MAX_KEY_BUFF];
644
DBUG_ENTER("_mi_balance_page");
589
646
k_length=keyinfo->keylength;
590
647
father_length=mi_getint(father_buff);
631
691
if (left_length < new_left_length)
632
692
{ /* Move keys buff -> leaf */
633
693
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);
694
memcpy((uchar*) pos,(uchar*) father_key_pos, (size_t) k_length);
695
memcpy((uchar*) pos+k_length, (uchar*) buff+2,
696
(size_t) (length=new_left_length - left_length - k_length));
637
697
pos=buff+2+length;
638
memcpy(father_key_pos, pos, k_length);
639
memmove(buff+2, pos+k_length, new_right_length);
698
memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
699
bmove((uchar*) buff+2,(uchar*) pos+k_length,new_right_length);
642
702
{ /* Move keys -> buff */
644
internal::bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) buff+right_length,
704
bmove_upp((uchar*) buff+new_right_length,(uchar*) buff+right_length,
646
706
length=new_right_length-right_length-k_length;
647
memcpy(buff+2+length,father_key_pos, k_length);
707
memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
648
708
pos=curr_buff+new_left_length;
649
memcpy(father_key_pos, pos, k_length);
650
memcpy(buff+2, pos+k_length, length);
709
memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
710
memcpy((uchar*) buff+2,(uchar*) pos+k_length,(size_t) length);
653
713
if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) ||
654
714
_mi_write_keypage(info,keyinfo,father_page,DFLT_INIT_HITS,father_buff))
659
719
/* curr_buff[] and buff[] are full, lets split and make new nod */
664
724
new_left_length-=curr_keylength;
665
725
extra_length=nod_flag+left_length+right_length-
666
726
new_left_length-new_right_length-curr_keylength;
727
DBUG_PRINT("info",("left_length: %d right_length: %d new_left_length: %d new_right_length: %d extra_length: %d",
728
left_length, right_length,
729
new_left_length, new_right_length,
667
731
mi_putint(curr_buff,new_left_length,nod_flag);
668
732
mi_putint(buff,new_right_length,nod_flag);
669
733
mi_putint(extra_buff,extra_length+2,nod_flag);
671
735
/* move first largest keys to new page */
672
736
pos=buff+right_length-extra_length;
673
memcpy(extra_buff+2, pos, extra_length);
737
memcpy((uchar*) extra_buff+2,pos,(size_t) extra_length);
674
738
/* Save new parting key */
675
739
memcpy(tmp_part_key, pos-k_length,k_length);
676
740
/* Make place for new keys */
677
internal::bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) pos-k_length,
741
bmove_upp((uchar*) buff+new_right_length,(uchar*) pos-k_length,
678
742
right_length-extra_length-k_length-2);
679
743
/* Copy keys from left page */
680
744
pos= curr_buff+new_left_length;
681
length= left_length - new_left_length - k_length;
682
memcpy(buff+2, pos+k_length, length);
745
memcpy((uchar*) buff+2,(uchar*) pos+k_length,
746
(size_t) (length=left_length-new_left_length-k_length));
683
747
/* Copy old parting key */
684
memcpy(buff+2+length, father_key_pos, k_length);
748
memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
686
750
/* 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);
751
memcpy((uchar*) (right ? key : father_key_pos),pos,(size_t) k_length);
752
memcpy((uchar*) (right ? father_key_pos : key),tmp_part_key, k_length);
690
754
if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
712
776
} bulk_insert_param;
714
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
778
int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
782
DBUG_ENTER("_mi_ck_write_tree");
719
784
error= tree_insert(&info->bulk_insert[keynr], key,
720
785
key_length + info->s->rec_reflength,
721
786
info->bulk_insert[keynr].custom_arg) ? 0 : HA_ERR_OUT_OF_MEM ;
724
789
} /* _mi_ck_write_tree */
727
792
/* typeof(_mi_keys_compare)=qsort_cmp2 */
729
static int keys_compare(bulk_insert_param *param, unsigned char *key1, unsigned char *key2)
794
static int keys_compare(bulk_insert_param *param, uchar *key1, uchar *key2)
731
uint32_t not_used[2];
732
797
return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg,
733
798
key1, key2, USE_WHOLE_KEY, SEARCH_SAME,
738
static int keys_free(unsigned char *key, TREE_FREE mode, bulk_insert_param *param)
803
static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
741
806
Probably I can use info->lastkey here, but I'm not sure,
742
807
and to be safe I'd better use local lastkey.
744
unsigned char lastkey[MI_MAX_KEY_BUFF];
809
uchar lastkey[MI_MAX_KEY_BUFF];
746
811
MI_KEYDEF *keyinfo;
750
815
if (param->info->s->concurrent_insert)
817
rw_wrlock(¶m->info->s->key_root_lock[param->keynr]);
752
818
param->info->s->keyinfo[param->keynr].version++;
759
825
return _mi_ck_write_btree(param->info,param->keynr,lastkey,
760
826
keylen - param->info->s->rec_reflength);
828
if (param->info->s->concurrent_insert)
829
rw_unlock(¶m->info->s->key_root_lock[param->keynr]);
768
int mi_init_bulk_insert(MI_INFO *info, uint32_t cache_size, ha_rows rows)
836
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows)
770
838
MYISAM_SHARE *share=info->s;
771
839
MI_KEYDEF *key=share->keyinfo;
772
840
bulk_insert_param *params;
773
uint32_t i, num_keys, total_keylength;
841
uint i, num_keys, total_keylength;
774
842
uint64_t key_map;
843
DBUG_ENTER("_mi_init_bulk_insert");
844
DBUG_PRINT("enter",("cache_size: %lu", cache_size));
776
assert(!info->bulk_insert &&
846
DBUG_ASSERT(!info->bulk_insert &&
777
847
(!rows || rows >= MI_MIN_ROWS_TO_USE_BULK_INSERT));
779
849
mi_clear_all_keys_active(key_map);