~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_write.c

  • Committer: Jay Pipes
  • Date: 2008-07-17 19:43:08 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717194308-l9i4ti57gikm2qbv
Phase 1 removal of DBUG in mysys

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        /* Functions declared in this file */
23
23
 
24
24
static int w_search(MI_INFO *info,MI_KEYDEF *keyinfo,
25
 
                    uint32_t comp_flag, unsigned char *key,
26
 
                    uint32_t key_length, my_off_t pos, unsigned char *father_buff,
27
 
                    unsigned char *father_keypos, my_off_t father_page,
28
 
                    bool insert_last);
29
 
static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
30
 
                            unsigned char *curr_buff,unsigned char *father_buff,
31
 
                            unsigned char *father_keypos,my_off_t father_page);
32
 
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
33
 
                                unsigned char *key, uint32_t *return_key_length,
34
 
                                unsigned char **after_key);
35
 
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
36
 
                      uint32_t key_length);
37
 
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
38
 
                       uint32_t key_length);
 
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,
 
28
                    my_bool insert_last);
 
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,
 
34
                                uchar **after_key);
 
35
int _mi_ck_write_tree(register MI_INFO *info, uint keynr,uchar *key,
 
36
                      uint key_length);
 
37
int _mi_ck_write_btree(register MI_INFO *info, uint keynr,uchar *key,
 
38
                       uint key_length);
39
39
 
40
40
        /* Write new record to database */
41
41
 
42
 
int mi_write(MI_INFO *info, unsigned char *record)
 
42
int mi_write(MI_INFO *info, uchar *record)
43
43
{
44
44
  MYISAM_SHARE *share=info->s;
45
 
  uint32_t i;
 
45
  uint i;
46
46
  int save_errno;
47
47
  my_off_t filepos;
48
 
  unsigned char *buff;
49
 
  bool lock_tree= share->concurrent_insert;
 
48
  uchar *buff;
 
49
  my_bool lock_tree= share->concurrent_insert;
50
50
 
51
51
  if (share->options & HA_OPTION_READ_ONLY_DATA)
52
52
  {
90
90
  {
91
91
    if (mi_is_key_active(share->state.key_map, i))
92
92
    {
93
 
      bool local_lock_tree= (lock_tree &&
 
93
      my_bool local_lock_tree= (lock_tree &&
94
94
                                !(info->bulk_insert &&
95
95
                                  is_tree_inited(&info->bulk_insert[i])));
96
96
      if (local_lock_tree)
130
130
                 HA_STATE_ROW_CHANGED);
131
131
  info->state->records++;
132
132
  info->lastpos=filepos;
133
 
  _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
 
133
  myisam_log_record(MI_LOG_WRITE,info,record,filepos,0);
 
134
  VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
134
135
  if (info->invalidator != 0)
135
136
  {
136
137
    (*info->invalidator)(info->filename);
157
158
  {
158
159
    if (info->bulk_insert)
159
160
    {
160
 
      uint32_t j;
 
161
      uint j;
161
162
      for (j=0 ; j < share->base.keys ; j++)
162
163
        mi_flush_bulk_insert(info, j);
163
164
    }
166
167
    {
167
168
      if (mi_is_key_active(share->state.key_map, i))
168
169
      {
169
 
        bool local_lock_tree= (lock_tree &&
 
170
        my_bool local_lock_tree= (lock_tree &&
170
171
                                  !(info->bulk_insert &&
171
172
                                    is_tree_inited(&info->bulk_insert[i])));
172
173
        if (local_lock_tree)
173
174
          rw_wrlock(&share->key_root_lock[i]);
174
175
        {
175
 
          uint32_t key_length=_mi_make_key(info,i,buff,record,filepos);
 
176
          uint key_length=_mi_make_key(info,i,buff,record,filepos);
176
177
          if (_mi_ck_delete(info,i,buff,key_length))
177
178
          {
178
179
            if (local_lock_tree)
194
195
  my_errno=save_errno;
195
196
err2:
196
197
  save_errno=my_errno;
197
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
198
  myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno);
 
199
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
198
200
  return(my_errno=save_errno);
199
201
} /* mi_write */
200
202
 
201
203
 
202
204
        /* Write one key to btree */
203
205
 
204
 
int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length)
 
206
int _mi_ck_write(MI_INFO *info, uint keynr, uchar *key, uint key_length)
205
207
{
206
208
  if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
207
209
  {
218
220
 *                Normal insert code                                  *
219
221
 **********************************************************************/
220
222
 
221
 
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
222
 
                       uint32_t key_length)
 
223
int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
 
224
                       uint key_length)
223
225
{
224
 
  uint32_t error;
225
 
  uint32_t comp_flag;
 
226
  uint error;
 
227
  uint comp_flag;
226
228
  MI_KEYDEF *keyinfo=info->s->keyinfo+keynr;
227
229
  my_off_t  *root=&info->s->state.key_root[keynr];
228
230
 
243
245
} /* _mi_ck_write_btree */
244
246
 
245
247
int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo,
246
 
    unsigned char *key, uint32_t key_length, my_off_t *root, uint32_t comp_flag)
 
248
    uchar *key, uint key_length, my_off_t *root, uint comp_flag)
247
249
{
248
250
  int error;
249
251
  /* key_length parameter is used only if comp_flag is SEARCH_FIND */
250
252
  if (*root == HA_OFFSET_ERROR ||
251
253
      (error=w_search(info, keyinfo, comp_flag, key, key_length,
252
 
                      *root, (unsigned char *) 0, (unsigned char*) 0,
 
254
                      *root, (uchar *) 0, (uchar*) 0,
253
255
                      (my_off_t) 0, 1)) > 0)
254
256
    error=_mi_enlarge_root(info,keyinfo,key,root);
255
257
  return(error);
258
260
 
259
261
        /* Make a new root with key as only pointer */
260
262
 
261
 
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, unsigned char *key,
 
263
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
262
264
                     my_off_t *root)
263
265
{
264
 
  uint32_t t_length,nod_flag;
 
266
  uint t_length,nod_flag;
265
267
  MI_KEY_PARAM s_temp;
266
268
  MYISAM_SHARE *share=info->s;
267
269
 
268
270
  nod_flag= (*root != HA_OFFSET_ERROR) ?  share->base.key_reflength : 0;
269
271
  _mi_kpointer(info,info->buff+2,*root); /* if nod */
270
 
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char*) 0,
271
 
                                (unsigned char*) 0, (unsigned char*) 0, key,&s_temp);
 
272
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar*) 0,
 
273
                                (uchar*) 0, (uchar*) 0, key,&s_temp);
272
274
  mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
273
275
  (*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
274
276
  info->buff_used=info->page_changed=1;         /* info->buff is used */
287
289
        */
288
290
 
289
291
static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
290
 
                    uint32_t comp_flag, unsigned char *key, uint32_t key_length, my_off_t page,
291
 
                    unsigned char *father_buff, unsigned char *father_keypos,
292
 
                    my_off_t father_page, bool insert_last)
 
292
                    uint comp_flag, uchar *key, uint key_length, my_off_t page,
 
293
                    uchar *father_buff, uchar *father_keypos,
 
294
                    my_off_t father_page, my_bool insert_last)
293
295
{
294
296
  int error,flag;
295
 
  uint32_t nod_flag, search_key_length;
296
 
  unsigned char *temp_buff,*keypos;
297
 
  unsigned char keybuff[MI_MAX_KEY_BUFF];
298
 
  bool was_last_key;
 
297
  uint nod_flag, search_key_length;
 
298
  uchar *temp_buff,*keypos;
 
299
  uchar keybuff[MI_MAX_KEY_BUFF];
 
300
  my_bool was_last_key;
299
301
  my_off_t next_page, dupp_key_pos;
300
302
 
301
303
  search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
302
 
  if (!(temp_buff= (unsigned char*) my_alloca((uint) keyinfo->block_length+
 
304
  if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
303
305
                                      MI_MAX_KEY_BUFF*2)))
304
306
    return(-1);
305
307
  if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0))
310
312
  nod_flag=mi_test_if_nod(temp_buff);
311
313
  if (flag == 0)
312
314
  {
313
 
    uint32_t tmp_key_length;
 
315
    uint tmp_key_length;
314
316
        /* get position to record with duplicated key */
315
317
    tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,keybuff);
316
318
    if (tmp_key_length)
320
322
 
321
323
    {
322
324
      info->dupp_key_pos= dupp_key_pos;
323
 
      my_afree((unsigned char*) temp_buff);
 
325
      my_afree((uchar*) temp_buff);
324
326
      my_errno=HA_ERR_FOUND_DUPP_KEY;
325
327
      return(-1);
326
328
    }
339
341
    if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff))
340
342
      goto err;
341
343
  }
342
 
  my_afree((unsigned char*) temp_buff);
 
344
  my_afree((uchar*) temp_buff);
343
345
  return(error);
344
346
err:
345
 
  my_afree((unsigned char*) temp_buff);
 
347
  my_afree((uchar*) temp_buff);
346
348
  return (-1);
347
349
} /* w_search */
348
350
 
373
375
*/
374
376
 
375
377
int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo,
376
 
               unsigned char *key, unsigned char *anc_buff, unsigned char *key_pos, unsigned char *key_buff,
377
 
               unsigned char *father_buff, unsigned char *father_key_pos, my_off_t father_page,
378
 
               bool insert_last)
 
378
               uchar *key, uchar *anc_buff, uchar *key_pos, uchar *key_buff,
 
379
               uchar *father_buff, uchar *father_key_pos, my_off_t father_page,
 
380
               my_bool insert_last)
379
381
{
380
 
  uint32_t a_length,nod_flag;
 
382
  uint a_length,nod_flag;
381
383
  int t_length;
382
 
  unsigned char *endpos, *prev_key;
 
384
  uchar *endpos, *prev_key;
383
385
  MI_KEY_PARAM s_temp;
384
386
 
385
387
  nod_flag=mi_test_if_nod(anc_buff);
386
388
  a_length=mi_getint(anc_buff);
387
389
  endpos= anc_buff+ a_length;
388
 
  prev_key=(key_pos == anc_buff+2+nod_flag ? (unsigned char*) 0 : key_buff);
 
390
  prev_key=(key_pos == anc_buff+2+nod_flag ? (uchar*) 0 : key_buff);
389
391
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
390
 
                                (key_pos == endpos ? (unsigned char*) 0 : key_pos),
 
392
                                (key_pos == endpos ? (uchar*) 0 : key_pos),
391
393
                                prev_key, prev_key,
392
394
                                key,&s_temp);
393
395
 
399
401
      my_errno=HA_ERR_CRASHED;
400
402
      return(-1);
401
403
    }
402
 
    bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,(uint) (endpos-key_pos));
 
404
    bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,(uint) (endpos-key_pos));
403
405
  }
404
406
  else
405
407
  {
409
411
      my_errno=HA_ERR_CRASHED;
410
412
      return(-1);
411
413
    }
412
 
    memcpy(key_pos, key_pos - t_length, endpos - key_pos + t_length);
 
414
    bmove(key_pos,key_pos-t_length,(uint) (endpos-key_pos)+t_length);
413
415
  }
414
416
  (*keyinfo->store_key)(keyinfo,key_pos,&s_temp);
415
417
  a_length+=t_length;
432
434
        /* split a full page in two and assign emerging item to key */
433
435
 
434
436
int _mi_split_page(register MI_INFO *info, register MI_KEYDEF *keyinfo,
435
 
                   unsigned char *key, unsigned char *buff, unsigned char *key_buff,
436
 
                   bool insert_last_key)
 
437
                   uchar *key, uchar *buff, uchar *key_buff,
 
438
                   my_bool insert_last_key)
437
439
{
438
 
  uint32_t length,a_length,key_ref_length,t_length,nod_flag,key_length;
439
 
  unsigned char *key_pos,*pos, *after_key= NULL;
 
440
  uint length,a_length,key_ref_length,t_length,nod_flag,key_length;
 
441
  uchar *key_pos,*pos, *after_key= NULL;
440
442
  my_off_t new_pos;
441
443
  MI_KEY_PARAM s_temp;
442
444
 
461
463
  if (nod_flag)
462
464
  {
463
465
    pos=key_pos-nod_flag;
464
 
    memcpy(info->buff + 2, pos, nod_flag);
 
466
    memcpy((uchar*) info->buff+2,(uchar*) pos,(size_t) nod_flag);
465
467
  }
466
468
 
467
469
        /* Move middle item to key and pointer to new page */
473
475
  if (!(*keyinfo->get_key)(keyinfo,nod_flag,&key_pos,key_buff))
474
476
    return(-1);
475
477
 
476
 
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char *) 0,
477
 
                                (unsigned char*) 0, (unsigned char*) 0,
 
478
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar *) 0,
 
479
                                (uchar*) 0, (uchar*) 0,
478
480
                                key_buff, &s_temp);
479
481
  length=(uint) ((buff+a_length)-key_pos);
480
 
  memcpy(info->buff+key_ref_length+t_length, key_pos, length);
 
482
  memcpy((uchar*) info->buff+key_ref_length+t_length,(uchar*) key_pos,
 
483
         (size_t) length);
481
484
  (*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp);
482
485
  mi_putint(info->buff,length+t_length+key_ref_length,nod_flag);
483
486
 
495
498
          after_key will contain the position to where the next key starts
496
499
        */
497
500
 
498
 
unsigned char *_mi_find_half_pos(uint32_t nod_flag, MI_KEYDEF *keyinfo, unsigned char *page,
499
 
                         unsigned char *key, uint32_t *return_key_length,
500
 
                         unsigned char **after_key)
 
501
uchar *_mi_find_half_pos(uint nod_flag, MI_KEYDEF *keyinfo, uchar *page,
 
502
                         uchar *key, uint *return_key_length,
 
503
                         uchar **after_key)
501
504
{
502
 
  uint32_t keys,length,key_ref_length;
503
 
  unsigned char *end,*lastpos;
 
505
  uint keys,length,key_ref_length;
 
506
  uchar *end,*lastpos;
504
507
 
505
508
  key_ref_length=2+nod_flag;
506
509
  length=mi_getint(page)-key_ref_length;
538
541
          key will contain the last key
539
542
        */
540
543
 
541
 
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
542
 
                                unsigned char *key, uint32_t *return_key_length,
543
 
                                unsigned char **after_key)
 
544
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
 
545
                                uchar *key, uint *return_key_length,
 
546
                                uchar **after_key)
544
547
{
545
 
  uint32_t keys;
546
 
  uint32_t length;
547
 
  uint32_t last_length= 0;
548
 
  uint32_t key_ref_length;
549
 
  unsigned char *end, *lastpos, *prevpos= NULL;
550
 
  unsigned char key_buff[MI_MAX_KEY_BUFF];
 
548
  uint keys;
 
549
  uint length;
 
550
  uint last_length= 0;
 
551
  uint key_ref_length;
 
552
  uchar *end, *lastpos, *prevpos= NULL;
 
553
  uchar key_buff[MI_MAX_KEY_BUFF];
551
554
 
552
555
  key_ref_length=2;
553
556
  length=mi_getint(page)-key_ref_length;
590
593
        /* returns 0 if balance was done */
591
594
 
592
595
static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo,
593
 
                            unsigned char *key, unsigned char *curr_buff, unsigned char *father_buff,
594
 
                            unsigned char *father_key_pos, my_off_t father_page)
 
596
                            uchar *key, uchar *curr_buff, uchar *father_buff,
 
597
                            uchar *father_key_pos, my_off_t father_page)
595
598
{
596
 
  bool right;
597
 
  uint32_t k_length,father_length,father_keylength,nod_flag,curr_keylength,
 
599
  my_bool right;
 
600
  uint k_length,father_length,father_keylength,nod_flag,curr_keylength,
598
601
       right_length,left_length,new_right_length,new_left_length,extra_length,
599
602
       length,keys;
600
 
  unsigned char *pos,*buff,*extra_buff;
 
603
  uchar *pos,*buff,*extra_buff;
601
604
  my_off_t next_page,new_pos;
602
 
  unsigned char tmp_part_key[MI_MAX_KEY_BUFF];
 
605
  uchar tmp_part_key[MI_MAX_KEY_BUFF];
603
606
 
604
607
  k_length=keyinfo->keylength;
605
608
  father_length=mi_getint(father_buff);
646
649
    if (left_length < new_left_length)
647
650
    {                                           /* Move keys buff -> leaf */
648
651
      pos=curr_buff+left_length;
649
 
      memcpy(pos, father_key_pos, k_length);
650
 
      length= new_left_length - left_length - k_length;
651
 
      memcpy(pos+k_length, buff+2, length);
 
652
      memcpy((uchar*) pos,(uchar*) father_key_pos, (size_t) k_length);
 
653
      memcpy((uchar*) pos+k_length, (uchar*) buff+2,
 
654
             (size_t) (length=new_left_length - left_length - k_length));
652
655
      pos=buff+2+length;
653
 
      memcpy(father_key_pos, pos, k_length);
654
 
      memcpy(buff+2, pos+k_length, new_right_length);
 
656
      memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
 
657
      bmove((uchar*) buff+2,(uchar*) pos+k_length,new_right_length);
655
658
    }
656
659
    else
657
660
    {                                           /* Move keys -> buff */
658
661
 
659
 
      bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) buff+right_length,
 
662
      bmove_upp((uchar*) buff+new_right_length,(uchar*) buff+right_length,
660
663
                right_length-2);
661
664
      length=new_right_length-right_length-k_length;
662
 
      memcpy(buff+2+length,father_key_pos, k_length);
 
665
      memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
663
666
      pos=curr_buff+new_left_length;
664
 
      memcpy(father_key_pos, pos, k_length);
665
 
      memcpy(buff+2, pos+k_length, length);
 
667
      memcpy((uchar*) father_key_pos,(uchar*) pos,(size_t) k_length);
 
668
      memcpy((uchar*) buff+2,(uchar*) pos+k_length,(size_t) length);
666
669
    }
667
670
 
668
671
    if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) ||
685
688
 
686
689
  /* move first largest keys to new page  */
687
690
  pos=buff+right_length-extra_length;
688
 
  memcpy(extra_buff+2, pos, extra_length);
 
691
  memcpy((uchar*) extra_buff+2,pos,(size_t) extra_length);
689
692
  /* Save new parting key */
690
693
  memcpy(tmp_part_key, pos-k_length,k_length);
691
694
  /* Make place for new keys */
692
 
  bmove_upp((unsigned char*) buff+new_right_length,(unsigned char*) pos-k_length,
 
695
  bmove_upp((uchar*) buff+new_right_length,(uchar*) pos-k_length,
693
696
            right_length-extra_length-k_length-2);
694
697
  /* Copy keys from left page */
695
698
  pos= curr_buff+new_left_length;
696
 
  length= left_length - new_left_length - k_length;
697
 
  memcpy(buff+2, pos+k_length, length);
 
699
  memcpy((uchar*) buff+2,(uchar*) pos+k_length,
 
700
         (size_t) (length=left_length-new_left_length-k_length));
698
701
  /* Copy old parting key */
699
 
  memcpy(buff+2+length, father_key_pos, k_length);
 
702
  memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
700
703
 
701
704
  /* Move new parting keys up to caller */
702
 
  memcpy((right ? key : father_key_pos), pos, k_length);
703
 
  memcpy((right ? father_key_pos : key), tmp_part_key, k_length);
 
705
  memcpy((uchar*) (right ? key : father_key_pos),pos,(size_t) k_length);
 
706
  memcpy((uchar*) (right ? father_key_pos : key),tmp_part_key, k_length);
704
707
 
705
708
  if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
706
709
    goto err;
723
726
 
724
727
typedef struct {
725
728
  MI_INFO *info;
726
 
  uint32_t keynr;
 
729
  uint keynr;
727
730
} bulk_insert_param;
728
731
 
729
 
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
730
 
                      uint32_t key_length)
 
732
int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
 
733
                      uint key_length)
731
734
{
732
735
  int error;
733
736
 
741
744
 
742
745
/* typeof(_mi_keys_compare)=qsort_cmp2 */
743
746
 
744
 
static int keys_compare(bulk_insert_param *param, unsigned char *key1, unsigned char *key2)
 
747
static int keys_compare(bulk_insert_param *param, uchar *key1, uchar *key2)
745
748
{
746
 
  uint32_t not_used[2];
 
749
  uint not_used[2];
747
750
  return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg,
748
751
                    key1, key2, USE_WHOLE_KEY, SEARCH_SAME,
749
752
                    not_used);
750
753
}
751
754
 
752
755
 
753
 
static int keys_free(unsigned char *key, TREE_FREE mode, bulk_insert_param *param)
 
756
static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
754
757
{
755
758
  /*
756
759
    Probably I can use info->lastkey here, but I'm not sure,
757
760
    and to be safe I'd better use local lastkey.
758
761
  */
759
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
760
 
  uint32_t keylen;
 
762
  uchar lastkey[MI_MAX_KEY_BUFF];
 
763
  uint keylen;
761
764
  MI_KEYDEF *keyinfo;
762
765
 
763
766
  switch (mode) {
783
786
}
784
787
 
785
788
 
786
 
int mi_init_bulk_insert(MI_INFO *info, uint32_t cache_size, ha_rows rows)
 
789
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows)
787
790
{
788
791
  MYISAM_SHARE *share=info->s;
789
792
  MI_KEYDEF *key=share->keyinfo;
790
793
  bulk_insert_param *params;
791
 
  uint32_t i, num_keys, total_keylength;
 
794
  uint i, num_keys, total_keylength;
792
795
  uint64_t key_map;
793
796
 
794
797
  assert(!info->bulk_insert &&
811
814
    return(0);
812
815
 
813
816
  if (rows && rows*total_keylength < cache_size)
814
 
    cache_size= (uint32_t)rows;
 
817
    cache_size= (ulong)rows;
815
818
  else
816
819
    cache_size/=total_keylength*16;
817
820
 
843
846
  return(0);
844
847
}
845
848
 
846
 
void mi_flush_bulk_insert(MI_INFO *info, uint32_t inx)
 
849
void mi_flush_bulk_insert(MI_INFO *info, uint inx)
847
850
{
848
851
  if (info->bulk_insert)
849
852
  {
856
859
{
857
860
  if (info->bulk_insert)
858
861
  {
859
 
    uint32_t i;
 
862
    uint i;
860
863
    for (i=0 ; i < info->s->base.keys ; i++)
861
864
    {
862
865
      if (is_tree_inited(& info->bulk_insert[i]))
864
867
        delete_tree(& info->bulk_insert[i]);
865
868
      }
866
869
    }
867
 
    free((void *)info->bulk_insert);
 
870
    my_free((void *)info->bulk_insert, MYF(0));
868
871
    info->bulk_insert=0;
869
872
  }
870
873
}