~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_write.c

Removed dead variable, sorted authors file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "myisamdef.h"
19
19
 
20
 
#include <mystrings/m_string.h>
21
 
#include <drizzled/util/test.h>
22
 
 
23
 
 
24
20
#define MAX_POINTER_LENGTH 8
25
21
 
26
22
        /* Functions declared in this file */
27
23
 
28
24
static int w_search(MI_INFO *info,MI_KEYDEF *keyinfo,
29
 
                    uint32_t comp_flag, unsigned char *key,
30
 
                    uint32_t key_length, my_off_t pos, unsigned char *father_buff,
31
 
                    unsigned char *father_keypos, my_off_t father_page,
32
 
                    bool insert_last);
33
 
static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
34
 
                            unsigned char *curr_buff,unsigned char *father_buff,
35
 
                            unsigned char *father_keypos,my_off_t father_page);
36
 
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
37
 
                                unsigned char *key, uint32_t *return_key_length,
38
 
                                unsigned char **after_key);
39
 
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
40
 
                      uint32_t key_length);
41
 
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr,unsigned char *key,
42
 
                       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);
43
39
 
44
40
        /* Write new record to database */
45
41
 
46
 
int mi_write(MI_INFO *info, unsigned char *record)
 
42
int mi_write(MI_INFO *info, uchar *record)
47
43
{
48
44
  MYISAM_SHARE *share=info->s;
49
 
  uint32_t i;
 
45
  uint i;
50
46
  int save_errno;
51
47
  my_off_t filepos;
52
 
  unsigned char *buff;
53
 
  bool lock_tree= share->concurrent_insert;
 
48
  uchar *buff;
 
49
  my_bool lock_tree= share->concurrent_insert;
54
50
 
55
51
  if (share->options & HA_OPTION_READ_ONLY_DATA)
56
52
  {
94
90
  {
95
91
    if (mi_is_key_active(share->state.key_map, i))
96
92
    {
97
 
      bool local_lock_tree= (lock_tree &&
 
93
      my_bool local_lock_tree= (lock_tree &&
98
94
                                !(info->bulk_insert &&
99
95
                                  is_tree_inited(&info->bulk_insert[i])));
100
96
      if (local_lock_tree)
101
97
      {
102
 
        pthread_rwlock_wrlock(&share->key_root_lock[i]);
 
98
        rw_wrlock(&share->key_root_lock[i]);
103
99
        share->keyinfo[i].version++;
104
100
      }
105
101
      {
107
103
                        _mi_make_key(info,i,buff,record,filepos)))
108
104
        {
109
105
          if (local_lock_tree)
110
 
            pthread_rwlock_unlock(&share->key_root_lock[i]);
 
106
            rw_unlock(&share->key_root_lock[i]);
111
107
          goto err;
112
108
        }
113
109
      }
116
112
      info->update&= ~HA_STATE_RNEXT_SAME;
117
113
 
118
114
      if (local_lock_tree)
119
 
        pthread_rwlock_unlock(&share->key_root_lock[i]);
 
115
        rw_unlock(&share->key_root_lock[i]);
120
116
    }
121
117
  }
122
118
  if (share->calc_checksum)
134
130
                 HA_STATE_ROW_CHANGED);
135
131
  info->state->records++;
136
132
  info->lastpos=filepos;
137
 
  _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));
138
135
  if (info->invalidator != 0)
139
136
  {
140
137
    (*info->invalidator)(info->filename);
161
158
  {
162
159
    if (info->bulk_insert)
163
160
    {
164
 
      uint32_t j;
 
161
      uint j;
165
162
      for (j=0 ; j < share->base.keys ; j++)
166
163
        mi_flush_bulk_insert(info, j);
167
164
    }
170
167
    {
171
168
      if (mi_is_key_active(share->state.key_map, i))
172
169
      {
173
 
        bool local_lock_tree= (lock_tree &&
 
170
        my_bool local_lock_tree= (lock_tree &&
174
171
                                  !(info->bulk_insert &&
175
172
                                    is_tree_inited(&info->bulk_insert[i])));
176
173
        if (local_lock_tree)
177
 
          pthread_rwlock_wrlock(&share->key_root_lock[i]);
 
174
          rw_wrlock(&share->key_root_lock[i]);
178
175
        {
179
 
          uint32_t key_length=_mi_make_key(info,i,buff,record,filepos);
 
176
          uint key_length=_mi_make_key(info,i,buff,record,filepos);
180
177
          if (_mi_ck_delete(info,i,buff,key_length))
181
178
          {
182
179
            if (local_lock_tree)
183
 
              pthread_rwlock_unlock(&share->key_root_lock[i]);
 
180
              rw_unlock(&share->key_root_lock[i]);
184
181
            break;
185
182
          }
186
183
        }
187
184
        if (local_lock_tree)
188
 
          pthread_rwlock_unlock(&share->key_root_lock[i]);
 
185
          rw_unlock(&share->key_root_lock[i]);
189
186
      }
190
187
    }
191
188
  }
198
195
  my_errno=save_errno;
199
196
err2:
200
197
  save_errno=my_errno;
201
 
  _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));
202
200
  return(my_errno=save_errno);
203
201
} /* mi_write */
204
202
 
205
203
 
206
204
        /* Write one key to btree */
207
205
 
208
 
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)
209
207
{
210
208
  if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
211
209
  {
222
220
 *                Normal insert code                                  *
223
221
 **********************************************************************/
224
222
 
225
 
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
226
 
                       uint32_t key_length)
 
223
int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
 
224
                       uint key_length)
227
225
{
228
 
  uint32_t error;
229
 
  uint32_t comp_flag;
 
226
  uint error;
 
227
  uint comp_flag;
230
228
  MI_KEYDEF *keyinfo=info->s->keyinfo+keynr;
231
229
  my_off_t  *root=&info->s->state.key_root[keynr];
232
230
 
247
245
} /* _mi_ck_write_btree */
248
246
 
249
247
int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo,
250
 
    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)
251
249
{
252
250
  int error;
253
251
  /* key_length parameter is used only if comp_flag is SEARCH_FIND */
254
252
  if (*root == HA_OFFSET_ERROR ||
255
253
      (error=w_search(info, keyinfo, comp_flag, key, key_length,
256
 
                      *root, (unsigned char *) 0, (unsigned char*) 0,
 
254
                      *root, (uchar *) 0, (uchar*) 0,
257
255
                      (my_off_t) 0, 1)) > 0)
258
256
    error=_mi_enlarge_root(info,keyinfo,key,root);
259
257
  return(error);
262
260
 
263
261
        /* Make a new root with key as only pointer */
264
262
 
265
 
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,
266
264
                     my_off_t *root)
267
265
{
268
 
  uint32_t t_length,nod_flag;
 
266
  uint t_length,nod_flag;
269
267
  MI_KEY_PARAM s_temp;
270
268
  MYISAM_SHARE *share=info->s;
271
269
 
272
270
  nod_flag= (*root != HA_OFFSET_ERROR) ?  share->base.key_reflength : 0;
273
271
  _mi_kpointer(info,info->buff+2,*root); /* if nod */
274
 
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char*) 0,
275
 
                                (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);
276
274
  mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
277
275
  (*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
278
276
  info->buff_used=info->page_changed=1;         /* info->buff is used */
291
289
        */
292
290
 
293
291
static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
294
 
                    uint32_t comp_flag, unsigned char *key, uint32_t key_length, my_off_t page,
295
 
                    unsigned char *father_buff, unsigned char *father_keypos,
296
 
                    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)
297
295
{
298
296
  int error,flag;
299
 
  uint32_t nod_flag, search_key_length;
300
 
  unsigned char *temp_buff,*keypos;
301
 
  unsigned char keybuff[MI_MAX_KEY_BUFF];
302
 
  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;
303
301
  my_off_t next_page, dupp_key_pos;
304
302
 
305
303
  search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
306
 
  if (!(temp_buff= (unsigned char*) malloc(keyinfo->block_length+
307
 
                                           MI_MAX_KEY_BUFF*2)))
 
304
  if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
 
305
                                      MI_MAX_KEY_BUFF*2)))
308
306
    return(-1);
309
307
  if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0))
310
308
    goto err;
314
312
  nod_flag=mi_test_if_nod(temp_buff);
315
313
  if (flag == 0)
316
314
  {
317
 
    uint32_t tmp_key_length;
 
315
    uint tmp_key_length;
318
316
        /* get position to record with duplicated key */
319
317
    tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,keybuff);
320
318
    if (tmp_key_length)
324
322
 
325
323
    {
326
324
      info->dupp_key_pos= dupp_key_pos;
327
 
      free(temp_buff);
 
325
      my_afree((uchar*) temp_buff);
328
326
      my_errno=HA_ERR_FOUND_DUPP_KEY;
329
327
      return(-1);
330
328
    }
343
341
    if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff))
344
342
      goto err;
345
343
  }
346
 
  free(temp_buff);
 
344
  my_afree((uchar*) temp_buff);
347
345
  return(error);
348
346
err:
349
 
  free(temp_buff);
 
347
  my_afree((uchar*) temp_buff);
350
348
  return (-1);
351
349
} /* w_search */
352
350
 
377
375
*/
378
376
 
379
377
int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo,
380
 
               unsigned char *key, unsigned char *anc_buff, unsigned char *key_pos, unsigned char *key_buff,
381
 
               unsigned char *father_buff, unsigned char *father_key_pos, my_off_t father_page,
382
 
               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)
383
381
{
384
 
  uint32_t a_length,nod_flag;
 
382
  uint a_length,nod_flag;
385
383
  int t_length;
386
 
  unsigned char *endpos, *prev_key;
 
384
  uchar *endpos, *prev_key;
387
385
  MI_KEY_PARAM s_temp;
388
386
 
389
387
  nod_flag=mi_test_if_nod(anc_buff);
390
388
  a_length=mi_getint(anc_buff);
391
389
  endpos= anc_buff+ a_length;
392
 
  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);
393
391
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
394
 
                                (key_pos == endpos ? (unsigned char*) 0 : key_pos),
 
392
                                (key_pos == endpos ? (uchar*) 0 : key_pos),
395
393
                                prev_key, prev_key,
396
394
                                key,&s_temp);
397
395
 
403
401
      my_errno=HA_ERR_CRASHED;
404
402
      return(-1);
405
403
    }
406
 
    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));
407
405
  }
408
406
  else
409
407
  {
413
411
      my_errno=HA_ERR_CRASHED;
414
412
      return(-1);
415
413
    }
416
 
    memmove(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);
417
415
  }
418
416
  (*keyinfo->store_key)(keyinfo,key_pos,&s_temp);
419
417
  a_length+=t_length;
436
434
        /* split a full page in two and assign emerging item to key */
437
435
 
438
436
int _mi_split_page(register MI_INFO *info, register MI_KEYDEF *keyinfo,
439
 
                   unsigned char *key, unsigned char *buff, unsigned char *key_buff,
440
 
                   bool insert_last_key)
 
437
                   uchar *key, uchar *buff, uchar *key_buff,
 
438
                   my_bool insert_last_key)
441
439
{
442
 
  uint32_t length,a_length,key_ref_length,t_length,nod_flag,key_length;
443
 
  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;
444
442
  my_off_t new_pos;
445
443
  MI_KEY_PARAM s_temp;
446
444
 
465
463
  if (nod_flag)
466
464
  {
467
465
    pos=key_pos-nod_flag;
468
 
    memcpy(info->buff + 2, pos, nod_flag);
 
466
    memcpy((uchar*) info->buff+2,(uchar*) pos,(size_t) nod_flag);
469
467
  }
470
468
 
471
469
        /* Move middle item to key and pointer to new page */
477
475
  if (!(*keyinfo->get_key)(keyinfo,nod_flag,&key_pos,key_buff))
478
476
    return(-1);
479
477
 
480
 
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char *) 0,
481
 
                                (unsigned char*) 0, (unsigned char*) 0,
 
478
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar *) 0,
 
479
                                (uchar*) 0, (uchar*) 0,
482
480
                                key_buff, &s_temp);
483
481
  length=(uint) ((buff+a_length)-key_pos);
484
 
  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);
485
484
  (*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp);
486
485
  mi_putint(info->buff,length+t_length+key_ref_length,nod_flag);
487
486
 
499
498
          after_key will contain the position to where the next key starts
500
499
        */
501
500
 
502
 
unsigned char *_mi_find_half_pos(uint32_t nod_flag, MI_KEYDEF *keyinfo, unsigned char *page,
503
 
                         unsigned char *key, uint32_t *return_key_length,
504
 
                         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)
505
504
{
506
 
  uint32_t keys,length,key_ref_length;
507
 
  unsigned char *end,*lastpos;
 
505
  uint keys,length,key_ref_length;
 
506
  uchar *end,*lastpos;
508
507
 
509
508
  key_ref_length=2+nod_flag;
510
509
  length=mi_getint(page)-key_ref_length;
542
541
          key will contain the last key
543
542
        */
544
543
 
545
 
static unsigned char *_mi_find_last_pos(MI_KEYDEF *keyinfo, unsigned char *page,
546
 
                                unsigned char *key, uint32_t *return_key_length,
547
 
                                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)
548
547
{
549
 
  uint32_t keys;
550
 
  uint32_t length;
551
 
  uint32_t last_length= 0;
552
 
  uint32_t key_ref_length;
553
 
  unsigned char *end, *lastpos, *prevpos= NULL;
554
 
  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];
555
554
 
556
555
  key_ref_length=2;
557
556
  length=mi_getint(page)-key_ref_length;
594
593
        /* returns 0 if balance was done */
595
594
 
596
595
static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo,
597
 
                            unsigned char *key, unsigned char *curr_buff, unsigned char *father_buff,
598
 
                            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)
599
598
{
600
 
  bool right;
601
 
  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,
602
601
       right_length,left_length,new_right_length,new_left_length,extra_length,
603
602
       length,keys;
604
 
  unsigned char *pos,*buff,*extra_buff;
 
603
  uchar *pos,*buff,*extra_buff;
605
604
  my_off_t next_page,new_pos;
606
 
  unsigned char tmp_part_key[MI_MAX_KEY_BUFF];
 
605
  uchar tmp_part_key[MI_MAX_KEY_BUFF];
607
606
 
608
607
  k_length=keyinfo->keylength;
609
608
  father_length=mi_getint(father_buff);
650
649
    if (left_length < new_left_length)
651
650
    {                                           /* Move keys buff -> leaf */
652
651
      pos=curr_buff+left_length;
653
 
      memcpy(pos, father_key_pos, k_length);
654
 
      length= new_left_length - left_length - k_length;
655
 
      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));
656
655
      pos=buff+2+length;
657
 
      memcpy(father_key_pos, pos, k_length);
658
 
      memmove(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);
659
658
    }
660
659
    else
661
660
    {                                           /* Move keys -> buff */
662
661
 
663
 
      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,
664
663
                right_length-2);
665
664
      length=new_right_length-right_length-k_length;
666
 
      memcpy(buff+2+length,father_key_pos, k_length);
 
665
      memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
667
666
      pos=curr_buff+new_left_length;
668
 
      memcpy(father_key_pos, pos, k_length);
669
 
      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);
670
669
    }
671
670
 
672
671
    if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) ||
689
688
 
690
689
  /* move first largest keys to new page  */
691
690
  pos=buff+right_length-extra_length;
692
 
  memcpy(extra_buff+2, pos, extra_length);
 
691
  memcpy((uchar*) extra_buff+2,pos,(size_t) extra_length);
693
692
  /* Save new parting key */
694
693
  memcpy(tmp_part_key, pos-k_length,k_length);
695
694
  /* Make place for new keys */
696
 
  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,
697
696
            right_length-extra_length-k_length-2);
698
697
  /* Copy keys from left page */
699
698
  pos= curr_buff+new_left_length;
700
 
  length= left_length - new_left_length - k_length;
701
 
  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));
702
701
  /* Copy old parting key */
703
 
  memcpy(buff+2+length, father_key_pos, k_length);
 
702
  memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
704
703
 
705
704
  /* Move new parting keys up to caller */
706
 
  memcpy((right ? key : father_key_pos), pos, k_length);
707
 
  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);
708
707
 
709
708
  if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
710
709
    goto err;
727
726
 
728
727
typedef struct {
729
728
  MI_INFO *info;
730
 
  uint32_t keynr;
 
729
  uint keynr;
731
730
} bulk_insert_param;
732
731
 
733
 
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
734
 
                      uint32_t key_length)
 
732
int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
 
733
                      uint key_length)
735
734
{
736
735
  int error;
737
736
 
745
744
 
746
745
/* typeof(_mi_keys_compare)=qsort_cmp2 */
747
746
 
748
 
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)
749
748
{
750
 
  uint32_t not_used[2];
 
749
  uint not_used[2];
751
750
  return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg,
752
751
                    key1, key2, USE_WHOLE_KEY, SEARCH_SAME,
753
752
                    not_used);
754
753
}
755
754
 
756
755
 
757
 
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)
758
757
{
759
758
  /*
760
759
    Probably I can use info->lastkey here, but I'm not sure,
761
760
    and to be safe I'd better use local lastkey.
762
761
  */
763
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
764
 
  uint32_t keylen;
 
762
  uchar lastkey[MI_MAX_KEY_BUFF];
 
763
  uint keylen;
765
764
  MI_KEYDEF *keyinfo;
766
765
 
767
766
  switch (mode) {
768
767
  case free_init:
769
768
    if (param->info->s->concurrent_insert)
770
769
    {
771
 
      pthread_rwlock_wrlock(&param->info->s->key_root_lock[param->keynr]);
 
770
      rw_wrlock(&param->info->s->key_root_lock[param->keynr]);
772
771
      param->info->s->keyinfo[param->keynr].version++;
773
772
    }
774
773
    return 0;
780
779
                              keylen - param->info->s->rec_reflength);
781
780
  case free_end:
782
781
    if (param->info->s->concurrent_insert)
783
 
      pthread_rwlock_unlock(&param->info->s->key_root_lock[param->keynr]);
 
782
      rw_unlock(&param->info->s->key_root_lock[param->keynr]);
784
783
    return 0;
785
784
  }
786
785
  return -1;
787
786
}
788
787
 
789
788
 
790
 
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)
791
790
{
792
791
  MYISAM_SHARE *share=info->s;
793
792
  MI_KEYDEF *key=share->keyinfo;
794
793
  bulk_insert_param *params;
795
 
  uint32_t i, num_keys, total_keylength;
 
794
  uint i, num_keys, total_keylength;
796
795
  uint64_t key_map;
797
796
 
798
797
  assert(!info->bulk_insert &&
815
814
    return(0);
816
815
 
817
816
  if (rows && rows*total_keylength < cache_size)
818
 
    cache_size= (uint32_t)rows;
 
817
    cache_size= (ulong)rows;
819
818
  else
820
819
    cache_size/=total_keylength*16;
821
820
 
822
821
  info->bulk_insert=(TREE *)
823
 
    malloc((sizeof(TREE)*share->base.keys+
824
 
           sizeof(bulk_insert_param)*num_keys));
 
822
    my_malloc((sizeof(TREE)*share->base.keys+
 
823
               sizeof(bulk_insert_param)*num_keys),MYF(0));
825
824
 
826
825
  if (!info->bulk_insert)
827
826
    return(HA_ERR_OUT_OF_MEM);
847
846
  return(0);
848
847
}
849
848
 
850
 
void mi_flush_bulk_insert(MI_INFO *info, uint32_t inx)
 
849
void mi_flush_bulk_insert(MI_INFO *info, uint inx)
851
850
{
852
851
  if (info->bulk_insert)
853
852
  {
860
859
{
861
860
  if (info->bulk_insert)
862
861
  {
863
 
    uint32_t i;
 
862
    uint i;
864
863
    for (i=0 ; i < info->s->base.keys ; i++)
865
864
    {
866
865
      if (is_tree_inited(& info->bulk_insert[i]))
868
867
        delete_tree(& info->bulk_insert[i]);
869
868
      }
870
869
    }
871
 
    free((void *)info->bulk_insert);
 
870
    my_free((void *)info->bulk_insert, MYF(0));
872
871
    info->bulk_insert=0;
873
872
  }
874
873
}