~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_write.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Write a row to a MyISAM table */
17
17
 
18
 
#include "myisamdef.h"
19
 
 
20
 
#include <mystrings/m_string.h>
21
 
#include <drizzled/util/test.h>
22
 
 
 
18
#include "fulltext.h"
 
19
#include "rt_index.h"
23
20
 
24
21
#define MAX_POINTER_LENGTH 8
25
22
 
26
23
        /* Functions declared in this file */
27
24
 
28
25
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);
 
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,
 
29
                    my_bool insert_last);
 
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,
 
35
                                uchar **after_key);
 
36
int _mi_ck_write_tree(register MI_INFO *info, uint keynr,uchar *key,
 
37
                      uint key_length);
 
38
int _mi_ck_write_btree(register MI_INFO *info, uint keynr,uchar *key,
 
39
                       uint key_length);
43
40
 
44
41
        /* Write new record to database */
45
42
 
46
 
int mi_write(MI_INFO *info, unsigned char *record)
 
43
int mi_write(MI_INFO *info, uchar *record)
47
44
{
48
45
  MYISAM_SHARE *share=info->s;
49
 
  uint32_t i;
 
46
  uint i;
50
47
  int save_errno;
51
48
  my_off_t filepos;
52
 
  unsigned char *buff;
53
 
  bool lock_tree= share->concurrent_insert;
 
49
  uchar *buff;
 
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
53
 
 
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););
55
57
  if (share->options & HA_OPTION_READ_ONLY_DATA)
56
58
  {
57
 
    return(my_errno=EACCES);
 
59
    DBUG_RETURN(my_errno=EACCES);
58
60
  }
59
61
  if (_mi_readinfo(info,F_WRLCK,1))
60
 
    return(my_errno);
 
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))
 
67
    goto err;
 
68
#endif
61
69
  filepos= ((share->state.dellink != HA_OFFSET_ERROR &&
62
70
             !info->append_insert_at_end) ?
63
71
            share->state.dellink :
94
102
  {
95
103
    if (mi_is_key_active(share->state.key_map, i))
96
104
    {
97
 
      bool local_lock_tree= (lock_tree &&
 
105
      my_bool local_lock_tree= (lock_tree &&
98
106
                                !(info->bulk_insert &&
99
107
                                  is_tree_inited(&info->bulk_insert[i])));
100
108
      if (local_lock_tree)
101
109
      {
102
 
        pthread_rwlock_wrlock(&share->key_root_lock[i]);
 
110
        rw_wrlock(&share->key_root_lock[i]);
103
111
        share->keyinfo[i].version++;
104
112
      }
 
113
      if (share->keyinfo[i].flag & HA_FULLTEXT )
 
114
      {
 
115
        if (_mi_ft_add(info,i, buff, record, filepos))
 
116
        {
 
117
          if (local_lock_tree)
 
118
            rw_unlock(&share->key_root_lock[i]);
 
119
          DBUG_PRINT("error",("Got error: %d on write",my_errno));
 
120
          goto err;
 
121
        }
 
122
      }
 
123
      else
105
124
      {
106
125
        if (share->keyinfo[i].ck_insert(info,i,buff,
107
126
                        _mi_make_key(info,i,buff,record,filepos)))
108
127
        {
109
128
          if (local_lock_tree)
110
 
            pthread_rwlock_unlock(&share->key_root_lock[i]);
 
129
            rw_unlock(&share->key_root_lock[i]);
 
130
          DBUG_PRINT("error",("Got error: %d on write",my_errno));
111
131
          goto err;
112
132
        }
113
133
      }
116
136
      info->update&= ~HA_STATE_RNEXT_SAME;
117
137
 
118
138
      if (local_lock_tree)
119
 
        pthread_rwlock_unlock(&share->key_root_lock[i]);
 
139
        rw_unlock(&share->key_root_lock[i]);
120
140
    }
121
141
  }
122
142
  if (share->calc_checksum)
134
154
                 HA_STATE_ROW_CHANGED);
135
155
  info->state->records++;
136
156
  info->lastpos=filepos;
137
 
  _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
 
157
  myisam_log_record(MI_LOG_WRITE,info,record,filepos,0);
 
158
  VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
138
159
  if (info->invalidator != 0)
139
160
  {
 
161
    DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
140
162
    (*info->invalidator)(info->filename);
141
163
    info->invalidator=0;
142
164
  }
152
174
  if (share->is_log_table)
153
175
    mi_update_status((void*) info);
154
176
 
155
 
  return(0);
 
177
  allow_break();                                /* Allow SIGHUP & SIGINT */
 
178
  DBUG_RETURN(0);
156
179
 
157
180
err:
158
181
  save_errno=my_errno;
161
184
  {
162
185
    if (info->bulk_insert)
163
186
    {
164
 
      uint32_t j;
 
187
      uint j;
165
188
      for (j=0 ; j < share->base.keys ; j++)
166
189
        mi_flush_bulk_insert(info, j);
167
190
    }
170
193
    {
171
194
      if (mi_is_key_active(share->state.key_map, i))
172
195
      {
173
 
        bool local_lock_tree= (lock_tree &&
 
196
        my_bool local_lock_tree= (lock_tree &&
174
197
                                  !(info->bulk_insert &&
175
198
                                    is_tree_inited(&info->bulk_insert[i])));
176
199
        if (local_lock_tree)
177
 
          pthread_rwlock_wrlock(&share->key_root_lock[i]);
 
200
          rw_wrlock(&share->key_root_lock[i]);
 
201
        if (share->keyinfo[i].flag & HA_FULLTEXT)
 
202
        {
 
203
          if (_mi_ft_del(info,i, buff,record,filepos))
 
204
          {
 
205
            if (local_lock_tree)
 
206
              rw_unlock(&share->key_root_lock[i]);
 
207
            break;
 
208
          }
 
209
        }
 
210
        else
178
211
        {
179
 
          uint32_t key_length=_mi_make_key(info,i,buff,record,filepos);
 
212
          uint key_length=_mi_make_key(info,i,buff,record,filepos);
180
213
          if (_mi_ck_delete(info,i,buff,key_length))
181
214
          {
182
215
            if (local_lock_tree)
183
 
              pthread_rwlock_unlock(&share->key_root_lock[i]);
 
216
              rw_unlock(&share->key_root_lock[i]);
184
217
            break;
185
218
          }
186
219
        }
187
220
        if (local_lock_tree)
188
 
          pthread_rwlock_unlock(&share->key_root_lock[i]);
 
221
          rw_unlock(&share->key_root_lock[i]);
189
222
      }
190
223
    }
191
224
  }
198
231
  my_errno=save_errno;
199
232
err2:
200
233
  save_errno=my_errno;
201
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
202
 
  return(my_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);
203
238
} /* mi_write */
204
239
 
205
240
 
206
241
        /* Write one key to btree */
207
242
 
208
 
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)
209
244
{
 
245
  DBUG_ENTER("_mi_ck_write");
 
246
 
210
247
  if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
211
248
  {
212
 
    return(_mi_ck_write_tree(info, keynr, key, key_length));
 
249
    DBUG_RETURN(_mi_ck_write_tree(info, keynr, key, key_length));
213
250
  }
214
251
  else
215
252
  {
216
 
    return(_mi_ck_write_btree(info, keynr, key, key_length));
 
253
    DBUG_RETURN(_mi_ck_write_btree(info, keynr, key, key_length));
217
254
  }
218
255
} /* _mi_ck_write */
219
256
 
222
259
 *                Normal insert code                                  *
223
260
 **********************************************************************/
224
261
 
225
 
int _mi_ck_write_btree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
226
 
                       uint32_t key_length)
 
262
int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
 
263
                       uint key_length)
227
264
{
228
 
  uint32_t error;
229
 
  uint32_t comp_flag;
 
265
  int error;
 
266
  uint comp_flag;
230
267
  MI_KEYDEF *keyinfo=info->s->keyinfo+keynr;
231
268
  my_off_t  *root=&info->s->state.key_root[keynr];
 
269
  DBUG_ENTER("_mi_ck_write_btree");
232
270
 
233
271
  if (keyinfo->flag & HA_SORT_ALLOWS_SAME)
234
272
    comp_flag=SEARCH_BIGGER;                    /* Put after same key */
235
 
  else if (keyinfo->flag & (HA_NOSAME))
 
273
  else if (keyinfo->flag & (HA_NOSAME|HA_FULLTEXT))
236
274
  {
237
275
    comp_flag=SEARCH_FIND | SEARCH_UPDATE;      /* No duplicates */
238
276
    if (keyinfo->flag & HA_NULL_ARE_EQUAL)
243
281
 
244
282
  error=_mi_ck_real_write_btree(info, keyinfo, key, key_length,
245
283
                                root, comp_flag);
246
 
  return(error);
 
284
  if (info->ft1_to_ft2)
 
285
  {
 
286
    if (!error)
 
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));
 
290
    info->ft1_to_ft2=0;
 
291
  }
 
292
  DBUG_RETURN(error);
247
293
} /* _mi_ck_write_btree */
248
294
 
249
295
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)
 
296
    uchar *key, uint key_length, my_off_t *root, uint comp_flag)
251
297
{
252
298
  int error;
 
299
  DBUG_ENTER("_mi_ck_real_write_btree");
253
300
  /* key_length parameter is used only if comp_flag is SEARCH_FIND */
254
301
  if (*root == HA_OFFSET_ERROR ||
255
302
      (error=w_search(info, keyinfo, comp_flag, key, key_length,
256
 
                      *root, (unsigned char *) 0, (unsigned char*) 0,
 
303
                      *root, (uchar *) 0, (uchar*) 0,
257
304
                      (my_off_t) 0, 1)) > 0)
258
305
    error=_mi_enlarge_root(info,keyinfo,key,root);
259
 
  return(error);
 
306
  DBUG_RETURN(error);
260
307
} /* _mi_ck_real_write_btree */
261
308
 
262
309
 
263
310
        /* Make a new root with key as only pointer */
264
311
 
265
 
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, unsigned char *key,
 
312
int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
266
313
                     my_off_t *root)
267
314
{
268
 
  uint32_t t_length,nod_flag;
 
315
  uint t_length,nod_flag;
269
316
  MI_KEY_PARAM s_temp;
270
317
  MYISAM_SHARE *share=info->s;
 
318
  DBUG_ENTER("_mi_enlarge_root");
271
319
 
272
320
  nod_flag= (*root != HA_OFFSET_ERROR) ?  share->base.key_reflength : 0;
273
321
  _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);
 
322
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar*) 0,
 
323
                                (uchar*) 0, (uchar*) 0, key,&s_temp);
276
324
  mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
277
325
  (*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
278
326
  info->buff_used=info->page_changed=1;         /* info->buff is used */
279
327
  if ((*root= _mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR ||
280
328
      _mi_write_keypage(info,keyinfo,*root,DFLT_INIT_HITS,info->buff))
281
 
    return(-1);
282
 
  return(0);
 
329
    DBUG_RETURN(-1);
 
330
  DBUG_RETURN(0);
283
331
} /* _mi_enlarge_root */
284
332
 
285
333
 
291
339
        */
292
340
 
293
341
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)
 
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)
297
345
{
298
346
  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;
 
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;
303
351
  my_off_t next_page, dupp_key_pos;
 
352
  DBUG_ENTER("w_search");
 
353
  DBUG_PRINT("enter",("page: %ld", (long) page));
304
354
 
305
355
  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)))
308
 
    return(-1);
 
356
  if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
 
357
                                      MI_MAX_KEY_BUFF*2)))
 
358
    DBUG_RETURN(-1);
309
359
  if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0))
310
360
    goto err;
311
361
 
314
364
  nod_flag=mi_test_if_nod(temp_buff);
315
365
  if (flag == 0)
316
366
  {
317
 
    uint32_t tmp_key_length;
 
367
    uint tmp_key_length;
318
368
        /* get position to record with duplicated key */
319
369
    tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,keybuff);
320
370
    if (tmp_key_length)
322
372
    else
323
373
      dupp_key_pos= HA_OFFSET_ERROR;
324
374
 
 
375
    if (keyinfo->flag & HA_FULLTEXT)
 
376
    {
 
377
      uint off;
 
378
      int  subkeys;
 
379
 
 
380
      get_key_full_length_rdonly(off, keybuff);
 
381
      subkeys=ft_sintXkorr(keybuff+off);
 
382
      comp_flag=SEARCH_SAME;
 
383
      if (subkeys >= 0)
 
384
      {
 
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);
 
389
      }
 
390
      else
 
391
      {
 
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);
 
396
        key+=off;
 
397
        keypos-=keyinfo->keylength+nod_flag; /* we'll modify key entry 'in vivo' */
 
398
        error=_mi_ck_real_write_btree(info, keyinfo, key, 0,
 
399
                                      &root, comp_flag);
 
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);
 
404
        if (!error)
 
405
          error=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff);
 
406
        my_afree((uchar*) temp_buff);
 
407
        DBUG_RETURN(error);
 
408
      }
 
409
    }
 
410
    else /* not HA_FULLTEXT, normal HA_NOSAME key */
325
411
    {
326
412
      info->dupp_key_pos= dupp_key_pos;
327
 
      free(temp_buff);
 
413
      my_afree((uchar*) temp_buff);
328
414
      my_errno=HA_ERR_FOUND_DUPP_KEY;
329
 
      return(-1);
 
415
      DBUG_RETURN(-1);
330
416
    }
331
417
  }
332
418
  if (flag == MI_FOUND_WRONG_KEY)
333
 
    return(-1);
 
419
    DBUG_RETURN(-1);
334
420
  if (!was_last_key)
335
421
    insert_last=0;
336
422
  next_page=_mi_kpos(nod_flag,keypos);
343
429
    if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff))
344
430
      goto err;
345
431
  }
346
 
  free(temp_buff);
347
 
  return(error);
 
432
  my_afree((uchar*) temp_buff);
 
433
  DBUG_RETURN(error);
348
434
err:
349
 
  free(temp_buff);
350
 
  return (-1);
 
435
  my_afree((uchar*) temp_buff);
 
436
  DBUG_PRINT("exit",("Error: %d",my_errno));
 
437
  DBUG_RETURN (-1);
351
438
} /* w_search */
352
439
 
353
440
 
377
464
*/
378
465
 
379
466
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)
 
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,
 
469
               my_bool insert_last)
383
470
{
384
 
  uint32_t a_length,nod_flag;
 
471
  uint a_length,nod_flag;
385
472
  int t_length;
386
 
  unsigned char *endpos, *prev_key;
 
473
  uchar *endpos, *prev_key;
387
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););
388
478
 
389
479
  nod_flag=mi_test_if_nod(anc_buff);
390
480
  a_length=mi_getint(anc_buff);
391
481
  endpos= anc_buff+ a_length;
392
 
  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);
393
483
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
394
 
                                (key_pos == endpos ? (unsigned char*) 0 : key_pos),
 
484
                                (key_pos == endpos ? (uchar*) 0 : key_pos),
395
485
                                prev_key, prev_key,
396
486
                                key,&s_temp);
397
 
 
 
487
#ifndef DBUG_OFF
 
488
  if (key_pos != anc_buff+2+nod_flag && (keyinfo->flag &
 
489
                                         (HA_BINARY_PACK_KEY | HA_PACK_KEY)))
 
490
  {
 
491
    DBUG_DUMP("prev_key",(uchar*) key_buff,_mi_keylength(keyinfo,key_buff));
 
492
  }
 
493
  if (keyinfo->flag & HA_PACK_KEY)
 
494
  {
 
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));
 
499
  }
 
500
#endif
398
501
  if (t_length > 0)
399
502
  {
400
503
    if (t_length >= keyinfo->maxlength*2+MAX_POINTER_LENGTH)
401
504
    {
402
505
      mi_print_error(info->s, HA_ERR_CRASHED);
403
506
      my_errno=HA_ERR_CRASHED;
404
 
      return(-1);
 
507
      DBUG_RETURN(-1);
405
508
    }
406
 
    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));
407
510
  }
408
511
  else
409
512
  {
411
514
    {
412
515
      mi_print_error(info->s, HA_ERR_CRASHED);
413
516
      my_errno=HA_ERR_CRASHED;
414
 
      return(-1);
 
517
      DBUG_RETURN(-1);
415
518
    }
416
 
    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);
417
520
  }
418
521
  (*keyinfo->store_key)(keyinfo,key_pos,&s_temp);
419
522
  a_length+=t_length;
420
523
  mi_putint(anc_buff,a_length,nod_flag);
421
524
  if (a_length <= keyinfo->block_length)
422
525
  {
423
 
    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))
 
530
    {
 
531
      /*
 
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
 
535
       */
 
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;
 
542
#else
 
543
      blen= *b++;
 
544
#endif
 
545
      get_key_length(alen,a);
 
546
      DBUG_ASSERT(info->ft1_to_ft2==0);
 
547
      if (alen == blen &&
 
548
          ha_compare_text(keyinfo->seg->charset, a, alen, b, blen, 0, 0)==0)
 
549
      {
 
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);
 
554
 
 
555
        /*
 
556
          now, adding all keys from the page to dynarray
 
557
          if the page is a leaf (if not keys will be deleted later)
 
558
        */
 
559
        if (!nod_flag)
 
560
        {
 
561
          /* let's leave the first key on the page, though, because
 
562
             we cannot easily dispatch an empty page here */
 
563
          b+=blen+ft2len+2;
 
564
          for (a=anc_buff+a_length ; b < a ; b+=ft2len+2)
 
565
            insert_dynamic(info->ft1_to_ft2, b);
 
566
 
 
567
          /* fixing the page's length - it contains only one key now */
 
568
          mi_putint(anc_buff,2+blen+ft2len+2,0);
 
569
        }
 
570
        /* the rest will be done when we're back from recursion */
 
571
      }
 
572
    }
 
573
    DBUG_RETURN(0);                             /* There is room on page */
424
574
  }
425
575
  /* Page is full */
426
576
  if (nod_flag)
427
577
    insert_last=0;
428
578
  if (!(keyinfo->flag & (HA_VAR_LENGTH_KEY | HA_BINARY_PACK_KEY)) &&
429
579
      father_buff && !insert_last)
430
 
    return(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
 
580
    DBUG_RETURN(_mi_balance_page(info,keyinfo,key,anc_buff,father_buff,
431
581
                                 father_key_pos,father_page));
432
 
  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));
433
583
} /* _mi_insert */
434
584
 
435
585
 
436
586
        /* split a full page in two and assign emerging item to key */
437
587
 
438
588
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)
 
589
                   uchar *key, uchar *buff, uchar *key_buff,
 
590
                   my_bool insert_last_key)
441
591
{
442
 
  uint32_t length,a_length,key_ref_length,t_length,nod_flag,key_length;
443
 
  unsigned char *key_pos,*pos, *after_key= NULL;
 
592
  uint length,a_length,key_ref_length,t_length,nod_flag,key_length;
 
593
  uchar *key_pos,*pos, *after_key= NULL;
444
594
  my_off_t new_pos;
445
595
  MI_KEY_PARAM s_temp;
 
596
  DBUG_ENTER("mi_split_page");
 
597
  DBUG_DUMP("buff",(uchar*) buff,mi_getint(buff));
446
598
 
447
599
  if (info->s->keyinfo+info->lastinx == keyinfo)
448
600
    info->page_changed=1;                       /* Info->buff is used */
455
607
    key_pos=_mi_find_half_pos(nod_flag,keyinfo,buff,key_buff, &key_length,
456
608
                              &after_key);
457
609
  if (!key_pos)
458
 
    return(-1);
 
610
    DBUG_RETURN(-1);
459
611
 
460
612
  length=(uint) (key_pos-buff);
461
613
  a_length=mi_getint(buff);
464
616
  key_pos=after_key;
465
617
  if (nod_flag)
466
618
  {
 
619
    DBUG_PRINT("test",("Splitting nod"));
467
620
    pos=key_pos-nod_flag;
468
 
    memcpy(info->buff + 2, pos, nod_flag);
 
621
    memcpy((uchar*) info->buff+2,(uchar*) pos,(size_t) nod_flag);
469
622
  }
470
623
 
471
624
        /* Move middle item to key and pointer to new page */
472
625
  if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
473
 
    return(-1);
 
626
    DBUG_RETURN(-1);
474
627
  _mi_kpointer(info,_mi_move_key(keyinfo,key,key_buff),new_pos);
475
628
 
476
629
        /* Store new page */
477
630
  if (!(*keyinfo->get_key)(keyinfo,nod_flag,&key_pos,key_buff))
478
 
    return(-1);
 
631
    DBUG_RETURN(-1);
479
632
 
480
 
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(unsigned char *) 0,
481
 
                                (unsigned char*) 0, (unsigned char*) 0,
 
633
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar *) 0,
 
634
                                (uchar*) 0, (uchar*) 0,
482
635
                                key_buff, &s_temp);
483
636
  length=(uint) ((buff+a_length)-key_pos);
484
 
  memcpy(info->buff+key_ref_length+t_length, key_pos, length);
 
637
  memcpy((uchar*) info->buff+key_ref_length+t_length,(uchar*) key_pos,
 
638
         (size_t) length);
485
639
  (*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp);
486
640
  mi_putint(info->buff,length+t_length+key_ref_length,nod_flag);
487
641
 
488
642
  if (_mi_write_keypage(info,keyinfo,new_pos,DFLT_INIT_HITS,info->buff))
489
 
    return(-1);
490
 
  return(2);                            /* Middle key up */
 
643
    DBUG_RETURN(-1);
 
644
  DBUG_DUMP("key",(uchar*) key,_mi_keylength(keyinfo,key));
 
645
  DBUG_RETURN(2);                               /* Middle key up */
491
646
} /* _mi_split_page */
492
647
 
493
648
 
499
654
          after_key will contain the position to where the next key starts
500
655
        */
501
656
 
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)
 
657
uchar *_mi_find_half_pos(uint nod_flag, MI_KEYDEF *keyinfo, uchar *page,
 
658
                         uchar *key, uint *return_key_length,
 
659
                         uchar **after_key)
505
660
{
506
 
  uint32_t keys,length,key_ref_length;
507
 
  unsigned char *end,*lastpos;
 
661
  uint keys,length,key_ref_length;
 
662
  uchar *end,*lastpos;
 
663
  DBUG_ENTER("_mi_find_half_pos");
508
664
 
509
665
  key_ref_length=2+nod_flag;
510
666
  length=mi_getint(page)-key_ref_length;
519
675
    end=page+keys*key_ref_length;
520
676
    *after_key=end+key_ref_length;
521
677
    memcpy(key,end,key_ref_length);
522
 
    return(end);
 
678
    DBUG_RETURN(end);
523
679
  }
524
680
 
525
681
  end=page+length/2-key_ref_length;             /* This is aprox. half */
528
684
  {
529
685
    lastpos=page;
530
686
    if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&page,key)))
531
 
      return(0);
 
687
      DBUG_RETURN(0);
532
688
  } while (page < end);
533
689
  *return_key_length=length;
534
690
  *after_key=page;
535
 
  return(lastpos);
 
691
  DBUG_PRINT("exit",("returns: 0x%lx  page: 0x%lx  half: 0x%lx",
 
692
                     (long) lastpos, (long) page, (long) end));
 
693
  DBUG_RETURN(lastpos);
536
694
} /* _mi_find_half_pos */
537
695
 
538
696
 
542
700
          key will contain the last key
543
701
        */
544
702
 
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)
 
703
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
 
704
                                uchar *key, uint *return_key_length,
 
705
                                uchar **after_key)
548
706
{
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];
 
707
  uint keys, length, last_length, key_ref_length;
 
708
  uchar *end, *lastpos, *prevpos= NULL;
 
709
  uchar key_buff[MI_MAX_KEY_BUFF];
 
710
  DBUG_ENTER("_mi_find_last_pos");
555
711
 
556
712
  key_ref_length=2;
557
713
  length=mi_getint(page)-key_ref_length;
565
721
    end=page+keys*length;
566
722
    *after_key=end+length;
567
723
    memcpy(key,end,length);
568
 
    return(end);
 
724
    DBUG_RETURN(end);
569
725
  }
570
726
 
571
727
  end= page + length - key_ref_length;
581
737
    {
582
738
      mi_print_error(keyinfo->share, HA_ERR_CRASHED);
583
739
      my_errno=HA_ERR_CRASHED;
584
 
      return(0);
 
740
      DBUG_RETURN(0);
585
741
    }
586
742
  }
587
743
  *return_key_length=last_length;
588
744
  *after_key=lastpos;
589
 
  return(prevpos);
 
745
  DBUG_PRINT("exit",("returns: 0x%lx  page: 0x%lx  end: 0x%lx",
 
746
                     (long) prevpos,(long) page,(long) end));
 
747
  DBUG_RETURN(prevpos);
590
748
} /* _mi_find_last_pos */
591
749
 
592
750
 
594
752
        /* returns 0 if balance was done */
595
753
 
596
754
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)
 
755
                            uchar *key, uchar *curr_buff, uchar *father_buff,
 
756
                            uchar *father_key_pos, my_off_t father_page)
599
757
{
600
 
  bool right;
601
 
  uint32_t k_length,father_length,father_keylength,nod_flag,curr_keylength,
 
758
  my_bool right;
 
759
  uint k_length,father_length,father_keylength,nod_flag,curr_keylength,
602
760
       right_length,left_length,new_right_length,new_left_length,extra_length,
603
761
       length,keys;
604
 
  unsigned char *pos,*buff,*extra_buff;
 
762
  uchar *pos,*buff,*extra_buff;
605
763
  my_off_t next_page,new_pos;
606
 
  unsigned char tmp_part_key[MI_MAX_KEY_BUFF];
 
764
  uchar tmp_part_key[MI_MAX_KEY_BUFF];
 
765
  DBUG_ENTER("_mi_balance_page");
607
766
 
608
767
  k_length=keyinfo->keylength;
609
768
  father_length=mi_getint(father_buff);
620
779
    next_page= _mi_kpos(info->s->base.key_reflength,
621
780
                        father_key_pos+father_keylength);
622
781
    buff=info->buff;
 
782
    DBUG_PRINT("test",("use right page: %lu", (ulong) next_page));
623
783
  }
624
784
  else
625
785
  {
628
788
    next_page= _mi_kpos(info->s->base.key_reflength,father_key_pos);
629
789
                                        /* Fix that curr_buff is to left */
630
790
    buff=curr_buff; curr_buff=info->buff;
 
791
    DBUG_PRINT("test",("use left page: %lu", (ulong) next_page));
631
792
  }                                     /* father_key_pos ptr to parting key */
632
793
 
633
794
  if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff,0))
634
795
    goto err;
 
796
  DBUG_DUMP("next",(uchar*) info->buff,mi_getint(info->buff));
635
797
 
636
798
        /* Test if there is room to share keys */
637
799
 
650
812
    if (left_length < new_left_length)
651
813
    {                                           /* Move keys buff -> leaf */
652
814
      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);
 
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));
656
818
      pos=buff+2+length;
657
 
      memcpy(father_key_pos, pos, k_length);
658
 
      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);
659
821
    }
660
822
    else
661
823
    {                                           /* Move keys -> buff */
662
824
 
663
 
      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,
664
826
                right_length-2);
665
827
      length=new_right_length-right_length-k_length;
666
 
      memcpy(buff+2+length,father_key_pos, k_length);
 
828
      memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
667
829
      pos=curr_buff+new_left_length;
668
 
      memcpy(father_key_pos, pos, k_length);
669
 
      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);
670
832
    }
671
833
 
672
834
    if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) ||
673
835
        _mi_write_keypage(info,keyinfo,father_page,DFLT_INIT_HITS,father_buff))
674
836
      goto err;
675
 
    return(0);
 
837
    DBUG_RETURN(0);
676
838
  }
677
839
 
678
840
        /* curr_buff[] and buff[] are full, lets split and make new nod */
683
845
    new_left_length-=curr_keylength;
684
846
  extra_length=nod_flag+left_length+right_length-
685
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,
 
851
                     extra_length));
686
852
  mi_putint(curr_buff,new_left_length,nod_flag);
687
853
  mi_putint(buff,new_right_length,nod_flag);
688
854
  mi_putint(extra_buff,extra_length+2,nod_flag);
689
855
 
690
856
  /* move first largest keys to new page  */
691
857
  pos=buff+right_length-extra_length;
692
 
  memcpy(extra_buff+2, pos, extra_length);
 
858
  memcpy((uchar*) extra_buff+2,pos,(size_t) extra_length);
693
859
  /* Save new parting key */
694
860
  memcpy(tmp_part_key, pos-k_length,k_length);
695
861
  /* Make place for new keys */
696
 
  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,
697
863
            right_length-extra_length-k_length-2);
698
864
  /* Copy keys from left page */
699
865
  pos= curr_buff+new_left_length;
700
 
  length= left_length - new_left_length - k_length;
701
 
  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));
702
868
  /* Copy old parting key */
703
 
  memcpy(buff+2+length, father_key_pos, k_length);
 
869
  memcpy((uchar*) buff+2+length,father_key_pos,(size_t) k_length);
704
870
 
705
871
  /* 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);
 
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);
708
874
 
709
875
  if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR)
710
876
    goto err;
715
881
                        DFLT_INIT_HITS,extra_buff))
716
882
    goto err;
717
883
 
718
 
  return(1);                            /* Middle key up */
 
884
  DBUG_RETURN(1);                               /* Middle key up */
719
885
 
720
886
err:
721
 
  return(-1);
 
887
  DBUG_RETURN(-1);
722
888
} /* _mi_balance_page */
723
889
 
724
890
/**********************************************************************
727
893
 
728
894
typedef struct {
729
895
  MI_INFO *info;
730
 
  uint32_t keynr;
 
896
  uint keynr;
731
897
} bulk_insert_param;
732
898
 
733
 
int _mi_ck_write_tree(register MI_INFO *info, uint32_t keynr, unsigned char *key,
734
 
                      uint32_t key_length)
 
899
int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
 
900
                      uint key_length)
735
901
{
736
902
  int error;
 
903
  DBUG_ENTER("_mi_ck_write_tree");
737
904
 
738
905
  error= tree_insert(&info->bulk_insert[keynr], key,
739
906
         key_length + info->s->rec_reflength,
740
907
         info->bulk_insert[keynr].custom_arg) ? 0 : HA_ERR_OUT_OF_MEM ;
741
908
 
742
 
  return(error);
 
909
  DBUG_RETURN(error);
743
910
} /* _mi_ck_write_tree */
744
911
 
745
912
 
746
913
/* typeof(_mi_keys_compare)=qsort_cmp2 */
747
914
 
748
 
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)
749
916
{
750
 
  uint32_t not_used[2];
 
917
  uint not_used[2];
751
918
  return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg,
752
919
                    key1, key2, USE_WHOLE_KEY, SEARCH_SAME,
753
920
                    not_used);
754
921
}
755
922
 
756
923
 
757
 
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)
758
925
{
759
926
  /*
760
927
    Probably I can use info->lastkey here, but I'm not sure,
761
928
    and to be safe I'd better use local lastkey.
762
929
  */
763
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
764
 
  uint32_t keylen;
 
930
  uchar lastkey[MI_MAX_KEY_BUFF];
 
931
  uint keylen;
765
932
  MI_KEYDEF *keyinfo;
766
933
 
767
934
  switch (mode) {
768
935
  case free_init:
769
936
    if (param->info->s->concurrent_insert)
770
937
    {
771
 
      pthread_rwlock_wrlock(&param->info->s->key_root_lock[param->keynr]);
 
938
      rw_wrlock(&param->info->s->key_root_lock[param->keynr]);
772
939
      param->info->s->keyinfo[param->keynr].version++;
773
940
    }
774
941
    return 0;
780
947
                              keylen - param->info->s->rec_reflength);
781
948
  case free_end:
782
949
    if (param->info->s->concurrent_insert)
783
 
      pthread_rwlock_unlock(&param->info->s->key_root_lock[param->keynr]);
 
950
      rw_unlock(&param->info->s->key_root_lock[param->keynr]);
784
951
    return 0;
785
952
  }
786
953
  return -1;
787
954
}
788
955
 
789
956
 
790
 
int mi_init_bulk_insert(MI_INFO *info, uint32_t cache_size, ha_rows rows)
 
957
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows)
791
958
{
792
959
  MYISAM_SHARE *share=info->s;
793
960
  MI_KEYDEF *key=share->keyinfo;
794
961
  bulk_insert_param *params;
795
 
  uint32_t i, num_keys, total_keylength;
796
 
  uint64_t key_map;
 
962
  uint i, num_keys, total_keylength;
 
963
  ulonglong key_map;
 
964
  DBUG_ENTER("_mi_init_bulk_insert");
 
965
  DBUG_PRINT("enter",("cache_size: %lu", cache_size));
797
966
 
798
 
  assert(!info->bulk_insert &&
 
967
  DBUG_ASSERT(!info->bulk_insert &&
799
968
              (!rows || rows >= MI_MIN_ROWS_TO_USE_BULK_INSERT));
800
969
 
801
970
  mi_clear_all_keys_active(key_map);
812
981
 
813
982
  if (num_keys==0 ||
814
983
      num_keys * MI_MIN_SIZE_BULK_INSERT_TREE > cache_size)
815
 
    return(0);
 
984
    DBUG_RETURN(0);
816
985
 
817
986
  if (rows && rows*total_keylength < cache_size)
818
 
    cache_size= (uint32_t)rows;
 
987
    cache_size= (ulong)rows;
819
988
  else
820
989
    cache_size/=total_keylength*16;
821
990
 
822
991
  info->bulk_insert=(TREE *)
823
 
    malloc((sizeof(TREE)*share->base.keys+
824
 
           sizeof(bulk_insert_param)*num_keys));
 
992
    my_malloc((sizeof(TREE)*share->base.keys+
 
993
               sizeof(bulk_insert_param)*num_keys),MYF(0));
825
994
 
826
995
  if (!info->bulk_insert)
827
 
    return(HA_ERR_OUT_OF_MEM);
 
996
    DBUG_RETURN(HA_ERR_OUT_OF_MEM);
828
997
 
829
998
  params=(bulk_insert_param *)(info->bulk_insert+share->base.keys);
830
999
  for (i=0 ; i < share->base.keys ; i++)
844
1013
     info->bulk_insert[i].root=0;
845
1014
  }
846
1015
 
847
 
  return(0);
 
1016
  DBUG_RETURN(0);
848
1017
}
849
1018
 
850
 
void mi_flush_bulk_insert(MI_INFO *info, uint32_t inx)
 
1019
void mi_flush_bulk_insert(MI_INFO *info, uint inx)
851
1020
{
852
1021
  if (info->bulk_insert)
853
1022
  {
860
1029
{
861
1030
  if (info->bulk_insert)
862
1031
  {
863
 
    uint32_t i;
 
1032
    uint i;
864
1033
    for (i=0 ; i < info->s->base.keys ; i++)
865
1034
    {
866
1035
      if (is_tree_inited(& info->bulk_insert[i]))
868
1037
        delete_tree(& info->bulk_insert[i]);
869
1038
      }
870
1039
    }
871
 
    free((void *)info->bulk_insert);
 
1040
    my_free((void *)info->bulk_insert, MYF(0));
872
1041
    info->bulk_insert=0;
873
1042
  }
874
1043
}