~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_delete.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
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 */
15
15
 
16
16
/* Remove a row from a MyISAM table */
17
17
 
18
 
#include "myisam_priv.h"
19
 
#include <drizzled/internal/m_string.h>
20
 
#include <drizzled/util/test.h>
21
 
 
22
 
using namespace drizzled;
23
 
 
24
 
static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uint32_t comp_flag,
25
 
                    unsigned char *key,uint32_t key_length,internal::my_off_t page,unsigned char *anc_buff);
26
 
static int del(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,unsigned char *anc_buff,
27
 
               internal::my_off_t leaf_page,unsigned char *leaf_buff,unsigned char *keypos,
28
 
               internal::my_off_t next_block,unsigned char *ret_key);
29
 
static int underflow(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *anc_buff,
30
 
                     internal::my_off_t leaf_page,unsigned char *leaf_buff,unsigned char *keypos);
31
 
static uint32_t remove_key(MI_KEYDEF *keyinfo,uint32_t nod_flag,unsigned char *keypos,
32
 
                       unsigned char *lastkey,unsigned char *page_end,
33
 
                       internal::my_off_t *next_block);
 
18
#include "myisamdef.h"
 
19
 
 
20
static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uint comp_flag,
 
21
                    uchar *key,uint key_length,my_off_t page,uchar *anc_buff);
 
22
static int del(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,uchar *anc_buff,
 
23
               my_off_t leaf_page,uchar *leaf_buff,uchar *keypos,
 
24
               my_off_t next_block,uchar *ret_key);
 
25
static int underflow(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *anc_buff,
 
26
                     my_off_t leaf_page,uchar *leaf_buff,uchar *keypos);
 
27
static uint remove_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar *keypos,
 
28
                       uchar *lastkey,uchar *page_end,
 
29
                       my_off_t *next_block);
34
30
static int _mi_ck_real_delete(register MI_INFO *info,MI_KEYDEF *keyinfo,
35
 
                              unsigned char *key, uint32_t key_length, internal::my_off_t *root);
36
 
 
37
 
 
38
 
int mi_delete(MI_INFO *info,const unsigned char *record)
 
31
                              uchar *key, uint key_length, my_off_t *root);
 
32
 
 
33
 
 
34
int mi_delete(MI_INFO *info,const uchar *record)
39
35
{
40
 
  uint32_t i;
41
 
  unsigned char *old_key;
 
36
  uint i;
 
37
  uchar *old_key;
42
38
  int save_errno;
43
39
  char lastpos[8];
44
40
 
47
43
        /* Test if record is in datafile */
48
44
  if (!(info->update & HA_STATE_AKTIV))
49
45
  {
50
 
    return(errno=HA_ERR_KEY_NOT_FOUND); /* No database read */
 
46
    return(my_errno=HA_ERR_KEY_NOT_FOUND);      /* No database read */
51
47
  }
52
48
  if (share->options & HA_OPTION_READ_ONLY_DATA)
53
49
  {
54
 
    return(errno=EACCES);
 
50
    return(my_errno=EACCES);
55
51
  }
56
52
  if (_mi_readinfo(info,F_WRLCK,1))
57
 
    return(errno);
 
53
    return(my_errno);
58
54
  if (info->s->calc_checksum)
59
55
    info->checksum=(*info->s->calc_checksum)(info,record);
60
56
  if ((*share->compare_record)(info,record))
89
85
  info->state->records--;
90
86
 
91
87
  mi_sizestore(lastpos,info->lastpos);
92
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
88
  myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,sizeof(lastpos),0);
 
89
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
 
90
  if (info->invalidator != 0)
 
91
  {
 
92
    (*info->invalidator)(info->filename);
 
93
    info->invalidator=0;
 
94
  }
93
95
  return(0);
94
96
 
95
97
err:
96
 
  save_errno=errno;
 
98
  save_errno=my_errno;
97
99
  mi_sizestore(lastpos,info->lastpos);
 
100
  myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos, sizeof(lastpos),0);
98
101
  if (save_errno != HA_ERR_RECORD_CHANGED)
99
102
  {
100
103
    mi_print_error(info->s, HA_ERR_CRASHED);
101
104
    mi_mark_crashed(info);              /* mark table crashed */
102
105
  }
103
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
106
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
104
107
  info->update|=HA_STATE_WRITTEN;       /* Buffer changed */
105
 
  errno=save_errno;
 
108
  my_errno=save_errno;
106
109
  if (save_errno == HA_ERR_KEY_NOT_FOUND)
107
110
  {
108
111
    mi_print_error(info->s, HA_ERR_CRASHED);
109
 
    errno=HA_ERR_CRASHED;
 
112
    my_errno=HA_ERR_CRASHED;
110
113
  }
111
114
 
112
 
  return(errno);
 
115
  return(my_errno);
113
116
} /* mi_delete */
114
117
 
115
118
 
116
119
        /* Remove a key from the btree index */
117
120
 
118
 
int _mi_ck_delete(register MI_INFO *info, uint32_t keynr, unsigned char *key,
119
 
                  uint32_t key_length)
 
121
int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
 
122
                  uint key_length)
120
123
{
121
124
  return _mi_ck_real_delete(info, info->s->keyinfo+keynr, key, key_length,
122
125
                            &info->s->state.key_root[keynr]);
124
127
 
125
128
 
126
129
static int _mi_ck_real_delete(register MI_INFO *info, MI_KEYDEF *keyinfo,
127
 
                              unsigned char *key, uint32_t key_length, internal::my_off_t *root)
 
130
                              uchar *key, uint key_length, my_off_t *root)
128
131
{
129
132
  int error;
130
 
  uint32_t nod_flag;
131
 
  internal::my_off_t old_root;
132
 
  unsigned char *root_buff;
 
133
  uint nod_flag;
 
134
  my_off_t old_root;
 
135
  uchar *root_buff;
133
136
 
134
137
  if ((old_root=*root) == HA_OFFSET_ERROR)
135
138
  {
136
139
    mi_print_error(info->s, HA_ERR_CRASHED);
137
 
    return(errno=HA_ERR_CRASHED);
 
140
    return(my_errno=HA_ERR_CRASHED);
138
141
  }
139
 
  if (!(root_buff= (unsigned char*) malloc(keyinfo->block_length+
 
142
  if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
140
143
                                      MI_MAX_KEY_BUFF*2)))
141
144
  {
142
 
    return(errno=ENOMEM);
 
145
    return(my_errno=ENOMEM);
143
146
  }
144
147
  if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0))
145
148
  {
170
173
    }
171
174
  }
172
175
err:
173
 
  free(root_buff);
 
176
  my_afree((uchar*) root_buff);
174
177
  return(error);
175
178
} /* _mi_ck_real_delete */
176
179
 
184
187
        */
185
188
 
186
189
static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
187
 
                    uint32_t comp_flag, unsigned char *key, uint32_t key_length,
188
 
                    internal::my_off_t page, unsigned char *anc_buff)
 
190
                    uint comp_flag, uchar *key, uint key_length,
 
191
                    my_off_t page, uchar *anc_buff)
189
192
{
190
193
  int flag,ret_value,save_flag;
191
 
  uint32_t length,nod_flag,search_key_length;
192
 
  bool last_key;
193
 
  unsigned char *leaf_buff,*keypos;
194
 
  internal::my_off_t leaf_page= 0, next_block;
195
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
194
  uint length,nod_flag,search_key_length;
 
195
  my_bool last_key;
 
196
  uchar *leaf_buff,*keypos;
 
197
  my_off_t leaf_page= 0, next_block;
 
198
  uchar lastkey[MI_MAX_KEY_BUFF];
196
199
 
197
200
  search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
198
201
  flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
207
210
  if (nod_flag)
208
211
  {
209
212
    leaf_page=_mi_kpos(nod_flag,keypos);
210
 
    if (!(leaf_buff= (unsigned char*) malloc(keyinfo->block_length+
 
213
    if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
211
214
                                        MI_MAX_KEY_BUFF*2)))
212
215
    {
213
 
      errno=ENOMEM;
 
216
      my_errno=ENOMEM;
214
217
      return(-1);
215
218
    }
216
219
    if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
222
225
    if (!nod_flag)
223
226
    {
224
227
      mi_print_error(info->s, HA_ERR_CRASHED);
225
 
      errno=HA_ERR_CRASHED;             /* This should newer happend */
 
228
      my_errno=HA_ERR_CRASHED;          /* This should newer happend */
226
229
      goto err;
227
230
    }
228
231
    save_flag=0;
231
234
  }
232
235
  else
233
236
  {                                             /* Found key */
234
 
    uint32_t tmp;
 
237
    uint tmp;
235
238
    length=mi_getint(anc_buff);
236
239
    if (!(tmp= remove_key(keyinfo,nod_flag,keypos,lastkey,anc_buff+length,
237
240
                          &next_block)))
266
269
        goto err;
267
270
      }
268
271
      ret_value=_mi_insert(info,keyinfo,key,anc_buff,keypos,lastkey,
269
 
                           (unsigned char*) 0,(unsigned char*) 0,(internal::my_off_t) 0,(bool) 0);
 
272
                           (uchar*) 0,(uchar*) 0,(my_off_t) 0,(my_bool) 0);
270
273
    }
271
274
  }
272
275
  if (ret_value == 0 && mi_getint(anc_buff) > keyinfo->block_length)
276
279
  }
277
280
  if (save_flag && ret_value != 1)
278
281
    ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
279
 
  free(leaf_buff);
 
282
  my_afree((uchar*) leaf_buff);
280
283
  return(ret_value);
281
284
 
282
285
err:
283
 
  free(leaf_buff);
 
286
  my_afree((uchar*) leaf_buff);
284
287
  return (-1);
285
288
} /* d_search */
286
289
 
287
290
 
288
291
        /* Remove a key that has a page-reference */
289
292
 
290
 
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, unsigned char *key,
291
 
               unsigned char *anc_buff, internal::my_off_t leaf_page, unsigned char *leaf_buff,
292
 
               unsigned char *keypos,           /* Pos to where deleted key was */
293
 
               internal::my_off_t next_block,
294
 
               unsigned char *ret_key)          /* key before keypos in anc_buff */
 
293
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key,
 
294
               uchar *anc_buff, my_off_t leaf_page, uchar *leaf_buff,
 
295
               uchar *keypos,           /* Pos to where deleted key was */
 
296
               my_off_t next_block,
 
297
               uchar *ret_key)          /* key before keypos in anc_buff */
295
298
{
296
299
  int ret_value,length;
297
 
  uint32_t a_length,nod_flag,tmp;
298
 
  internal::my_off_t next_page;
299
 
  unsigned char keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
 
300
  uint a_length,nod_flag,tmp;
 
301
  my_off_t next_page;
 
302
  uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
300
303
  MYISAM_SHARE *share=info->s;
301
304
  MI_KEY_PARAM s_temp;
302
305
 
308
311
  if ((nod_flag=mi_test_if_nod(leaf_buff)))
309
312
  {
310
313
    next_page= _mi_kpos(nod_flag,endpos);
311
 
    if (!(next_buff= (unsigned char*) malloc(keyinfo->block_length+
 
314
    if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
312
315
                                        MI_MAX_KEY_BUFF*2)))
313
316
      return(-1);
314
317
    if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
334
337
                                &tmp))
335
338
            goto err;
336
339
          ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
337
 
                               (unsigned char*) 0,(unsigned char*) 0,(internal::my_off_t) 0,0);
 
340
                               (uchar*) 0,(uchar*) 0,(my_off_t) 0,0);
338
341
        }
339
342
      }
340
343
      if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
341
344
        goto err;
342
345
    }
343
 
    free(next_buff);
 
346
    my_afree((uchar*) next_buff);
344
347
    return(ret_value);
345
348
  }
346
349
 
360
363
  prev_key=(keypos == anc_buff+2+share->base.key_reflength ?
361
364
            0 : ret_key);
362
365
  length=(*keyinfo->pack_key)(keyinfo,share->base.key_reflength,
363
 
                              keypos == endpos ? (unsigned char*) 0 : keypos,
 
366
                              keypos == endpos ? (uchar*) 0 : keypos,
364
367
                              prev_key, prev_key,
365
368
                              keybuff,&s_temp);
366
369
  if (length > 0)
367
 
    internal::bmove_upp((unsigned char*) endpos+length,(unsigned char*) endpos,(uint) (endpos-keypos));
 
370
    bmove_upp((uchar*) endpos+length,(uchar*) endpos,(uint) (endpos-keypos));
368
371
  else
369
 
    memmove(keypos,keypos-length, (int) (endpos-keypos)+length);
 
372
    memcpy(keypos,keypos-length, (int) (endpos-keypos)+length);
370
373
  (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
371
374
  /* Save pointer to next leaf */
372
375
  if (!(*keyinfo->get_key)(keyinfo,share->base.key_reflength,&keypos,ret_key))
385
388
        /* Balances adjacent pages if underflow occours */
386
389
 
387
390
static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo,
388
 
                     unsigned char *anc_buff,
389
 
                     internal::my_off_t leaf_page,/* Ancestor page and underflow page */
390
 
                     unsigned char *leaf_buff,
391
 
                     unsigned char *keypos)     /* Position to pos after key */
 
391
                     uchar *anc_buff,
 
392
                     my_off_t leaf_page,/* Ancestor page and underflow page */
 
393
                     uchar *leaf_buff,
 
394
                     uchar *keypos)     /* Position to pos after key */
392
395
{
393
396
  int t_length;
394
 
  uint32_t length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
 
397
  uint length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
395
398
       key_reflength,key_length;
396
 
  internal::my_off_t next_page;
397
 
  unsigned char anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
 
399
  my_off_t next_page;
 
400
  uchar anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
398
401
        *buff,*endpos,*next_keypos,*anc_pos,*half_pos,*temp_pos,*prev_key,
399
402
        *after_key;
400
403
  MI_KEY_PARAM s_temp;
434
437
    buff_length=mi_getint(buff);
435
438
 
436
439
    /* find keys to make a big key-page */
437
 
    memmove(next_keypos - key_reflength, buff + 2, key_reflength);
 
440
    memcpy((uchar*) next_keypos-key_reflength,(uchar*) buff+2,
 
441
           key_reflength);
438
442
    if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,next_keypos,&length)
439
443
        || !_mi_get_last_key(info,keyinfo,leaf_buff,leaf_key,
440
444
                             leaf_buff+leaf_length,&length))
441
445
      goto err;
442
446
 
443
447
    /* merge pages and put parting key from anc_buff between */
444
 
    prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
 
448
    prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
445
449
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,buff+p_length,
446
450
                                  prev_key, prev_key,
447
451
                                  anc_key, &s_temp);
448
452
    length=buff_length-p_length;
449
453
    endpos=buff+length+leaf_length+t_length;
450
454
    /* buff will always be larger than before !*/
451
 
    internal::bmove_upp((unsigned char*) endpos, (unsigned char*) buff+buff_length,length);
452
 
    memcpy(buff, leaf_buff, leaf_length);
 
455
    bmove_upp((uchar*) endpos, (uchar*) buff+buff_length,length);
 
456
    memcpy((uchar*) buff, (uchar*) leaf_buff,(size_t) leaf_length);
453
457
    (*keyinfo->store_key)(keyinfo,buff+leaf_length,&s_temp);
454
458
    buff_length=(uint) (endpos-buff);
455
459
    mi_putint(buff,buff_length,nod_flag);
457
461
    /* remove key from anc_buff */
458
462
 
459
463
    if (!(s_length=remove_key(keyinfo,key_reflength,keypos,anc_key,
460
 
                              anc_buff+anc_length,(internal::my_off_t *) 0)))
 
464
                              anc_buff+anc_length,(my_off_t *) 0)))
461
465
      goto err;
462
466
 
463
467
    anc_length-=s_length;
465
469
 
466
470
    if (buff_length <= keyinfo->block_length)
467
471
    {                                           /* Keys in one page */
468
 
      memcpy(leaf_buff, buff, buff_length);
 
472
      memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) buff_length);
469
473
      if (_mi_dispose(info,keyinfo,next_page,DFLT_INIT_HITS))
470
474
       goto err;
471
475
    }
479
483
                                       &key_length, &after_key)))
480
484
        goto err;
481
485
      length=(uint) (half_pos-buff);
482
 
      memcpy(leaf_buff, buff, length);
 
486
      memcpy((uchar*) leaf_buff,(uchar*) buff,(size_t) length);
483
487
      mi_putint(leaf_buff,length,nod_flag);
484
488
 
485
489
      /* Correct new keypointer to leaf_page */
486
490
      half_pos=after_key;
487
491
      _mi_kpointer(info,leaf_key+key_length,next_page);
488
492
      /* Save key in anc_buff */
489
 
      prev_key=(keypos == anc_buff+2+key_reflength ? (unsigned char*) 0 : anc_key),
 
493
      prev_key=(keypos == anc_buff+2+key_reflength ? (uchar*) 0 : anc_key),
490
494
      t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
491
 
                                    (keypos == endpos ? (unsigned char*) 0 :
 
495
                                    (keypos == endpos ? (uchar*) 0 :
492
496
                                     keypos),
493
497
                                    prev_key, prev_key,
494
498
                                    leaf_key, &s_temp);
495
499
      if (t_length >= 0)
496
 
        internal::bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,
 
500
        bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,
497
501
                  (uint) (endpos-keypos));
498
502
      else
499
 
        memmove(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
 
503
        memcpy(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
500
504
      (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
501
505
      mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
502
506
 
503
507
        /* Store key first in new page */
504
508
      if (nod_flag)
505
 
        memmove(buff + 2, half_pos - nod_flag, nod_flag);
 
509
        memcpy((uchar*) buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
506
510
      if (!(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key))
507
511
        goto err;
508
 
      t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (unsigned char*) 0,
509
 
                                          (unsigned char*) 0, (unsigned char *) 0,
 
512
      t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (uchar*) 0,
 
513
                                          (uchar*) 0, (uchar *) 0,
510
514
                                          leaf_key, &s_temp);
511
515
      /* t_length will always be > 0 for a new page !*/
512
516
      length=(uint) ((buff+mi_getint(buff))-half_pos);
513
 
      memmove(buff + p_length + t_length, half_pos, length);
 
517
      memcpy((uchar*) buff+p_length+t_length,(uchar*) half_pos,(size_t) length);
514
518
      (*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp);
515
519
      mi_putint(buff,length+t_length+p_length,nod_flag);
516
520
 
533
537
  endpos=buff+buff_length;
534
538
 
535
539
  /* find keys to make a big key-page */
536
 
  memmove(next_keypos - key_reflength, leaf_buff+2, key_reflength);
 
540
  memcpy((uchar*) next_keypos - key_reflength,(uchar*) leaf_buff+2,
 
541
         key_reflength);
537
542
  next_keypos=keypos;
538
543
  if (!(*keyinfo->get_key)(keyinfo,key_reflength,&next_keypos,
539
544
                           anc_key))
542
547
    goto err;
543
548
 
544
549
  /* merge pages and put parting key from anc_buff between */
545
 
  prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
 
550
  prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
546
551
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
547
552
                                (leaf_length == p_length ?
548
 
                                 (unsigned char*) 0 : leaf_buff+p_length),
 
553
                                 (uchar*) 0 : leaf_buff+p_length),
549
554
                                prev_key, prev_key,
550
555
                                anc_key, &s_temp);
551
556
  if (t_length >= 0)
552
 
    memmove(endpos+t_length,leaf_buff+p_length, leaf_length-p_length);
 
557
    memcpy((uchar*) endpos+t_length,(uchar*) leaf_buff+p_length,
 
558
           (size_t) (leaf_length-p_length));
553
559
  else                                          /* We gained space */
554
 
    memmove(endpos, leaf_buff+((int) p_length-t_length),
555
 
            leaf_length - p_length + t_length);
 
560
    memcpy((uchar*) endpos,(uchar*) leaf_buff+((int) p_length-t_length),
 
561
           (size_t) (leaf_length-p_length+t_length));
556
562
 
557
563
  (*keyinfo->store_key)(keyinfo,endpos,&s_temp);
558
564
  buff_length=buff_length+leaf_length-p_length+t_length;
560
566
 
561
567
  /* remove key from anc_buff */
562
568
  if (!(s_length= remove_key(keyinfo,key_reflength,keypos,anc_key,
563
 
                             anc_buff+anc_length,(internal::my_off_t *) 0)))
 
569
                             anc_buff+anc_length,(my_off_t *) 0)))
564
570
    goto err;
565
571
 
566
572
  anc_length-=s_length;
587
593
 
588
594
    temp_pos=anc_buff+anc_length;
589
595
    t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
590
 
                                  keypos == temp_pos ? (unsigned char*) 0
 
596
                                  keypos == temp_pos ? (uchar*) 0
591
597
                                  : keypos,
592
598
                                  anc_pos, anc_pos,
593
599
                                  leaf_key,&s_temp);
594
600
    if (t_length > 0)
595
 
      internal::bmove_upp((unsigned char*) temp_pos+t_length,(unsigned char*) temp_pos,
 
601
      bmove_upp((uchar*) temp_pos+t_length,(uchar*) temp_pos,
596
602
                (uint) (temp_pos-keypos));
597
603
    else
598
 
      memmove(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
 
604
      memcpy(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
599
605
    (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
600
606
    mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
601
607
 
602
608
    /* Store first key on new page */
603
609
    if (nod_flag)
604
 
      memmove(leaf_buff+2, half_pos - nod_flag, nod_flag);
 
610
      memcpy((uchar*) leaf_buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
605
611
    if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key)))
606
612
      goto err;
607
 
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (unsigned char*) 0,
608
 
                                  (unsigned char*) 0, (unsigned char*) 0, leaf_key, &s_temp);
 
613
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
 
614
                                  (uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
609
615
    length=(uint) ((buff+buff_length)-half_pos);
610
 
    memmove(leaf_buff + p_length + t_length, half_pos, length);
 
616
    memcpy((uchar*) leaf_buff+p_length+t_length,(uchar*) half_pos,
 
617
          (size_t) length);
611
618
    (*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
612
619
    mi_putint(leaf_buff,length+t_length+p_length,nod_flag);
613
620
    if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
630
637
          returns how many chars was removed or 0 on error
631
638
        */
632
639
 
633
 
static uint32_t remove_key(MI_KEYDEF *keyinfo, uint32_t nod_flag,
634
 
                       unsigned char *keypos,   /* Where key starts */
635
 
                       unsigned char *lastkey,  /* key to be removed */
636
 
                       unsigned char *page_end, /* End of page */
637
 
                       internal::my_off_t *next_block)  /* ptr to next block */
 
640
static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag,
 
641
                       uchar *keypos,   /* Where key starts */
 
642
                       uchar *lastkey,  /* key to be removed */
 
643
                       uchar *page_end, /* End of page */
 
644
                       my_off_t *next_block)    /* ptr to next block */
638
645
{
639
646
  int s_length;
640
 
  unsigned char *start;
 
647
  uchar *start;
641
648
 
642
649
  start=keypos;
643
650
  if (!(keyinfo->flag &
661
668
    {
662
669
      if (keyinfo->flag & HA_BINARY_PACK_KEY)
663
670
      {
664
 
        unsigned char *old_key=start;
665
 
        uint32_t next_length,prev_length,prev_pack_length;
 
671
        uchar *old_key=start;
 
672
        uint next_length,prev_length,prev_pack_length;
666
673
        get_key_length(next_length,keypos);
667
674
        get_key_pack_length(prev_length,prev_pack_length,old_key);
668
675
        if (next_length > prev_length)
669
676
        {
670
677
          /* We have to copy data from the current key to the next key */
671
 
          internal::bmove_upp(keypos, (lastkey+next_length),
 
678
          bmove_upp(keypos, (lastkey+next_length),
672
679
                    (next_length-prev_length));
673
680
          keypos-=(next_length-prev_length)+prev_pack_length;
674
681
          store_key_length(keypos,prev_length);
681
688
        if ((keyinfo->seg->flag & HA_PACK_KEY) && *keypos & 128)
682
689
        {
683
690
          /* Next key is packed against the current one */
684
 
          uint32_t next_length,prev_length,prev_pack_length,lastkey_length,
 
691
          uint next_length,prev_length,prev_pack_length,lastkey_length,
685
692
            rest_length;
686
693
          if (keyinfo->seg[0].length >= 127)
687
694
          {
714
721
 
715
722
          if (next_length >= prev_length)
716
723
          {             /* Key after is based on deleted key */
717
 
            uint32_t pack_length,tmp;
718
 
            internal::bmove_upp(keypos, (lastkey+next_length),
719
 
                                tmp=(next_length-prev_length));
 
724
            uint pack_length,tmp;
 
725
            bmove_upp(keypos, (lastkey+next_length),
 
726
                      tmp=(next_length-prev_length));
720
727
            rest_length+=tmp;
721
728
            pack_length= prev_length ? get_pack_length(rest_length): 0;
722
729
            keypos-=tmp+pack_length+prev_pack_length;
748
755
    }
749
756
  }
750
757
end:
751
 
  assert(page_end-start >= s_length);
752
 
  memmove(start, start + s_length, page_end-start-s_length);
753
 
  return s_length;
 
758
  memcpy((uchar*) start,(uchar*) start+s_length,
 
759
         (uint) (page_end-start-s_length));
 
760
  return((uint) s_length);
754
761
} /* remove_key */