~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_delete.c

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

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
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
 
89
  if (info->invalidator != 0)
 
90
  {
 
91
    (*info->invalidator)(info->filename);
 
92
    info->invalidator=0;
 
93
  }
93
94
  return(0);
94
95
 
95
96
err:
96
 
  save_errno=errno;
 
97
  save_errno=my_errno;
97
98
  mi_sizestore(lastpos,info->lastpos);
98
99
  if (save_errno != HA_ERR_RECORD_CHANGED)
99
100
  {
100
101
    mi_print_error(info->s, HA_ERR_CRASHED);
101
102
    mi_mark_crashed(info);              /* mark table crashed */
102
103
  }
103
 
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
104
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
104
105
  info->update|=HA_STATE_WRITTEN;       /* Buffer changed */
105
 
  errno=save_errno;
 
106
  my_errno=save_errno;
106
107
  if (save_errno == HA_ERR_KEY_NOT_FOUND)
107
108
  {
108
109
    mi_print_error(info->s, HA_ERR_CRASHED);
109
 
    errno=HA_ERR_CRASHED;
 
110
    my_errno=HA_ERR_CRASHED;
110
111
  }
111
112
 
112
 
  return(errno);
 
113
  return(my_errno);
113
114
} /* mi_delete */
114
115
 
115
116
 
116
117
        /* Remove a key from the btree index */
117
118
 
118
 
int _mi_ck_delete(register MI_INFO *info, uint32_t keynr, unsigned char *key,
119
 
                  uint32_t key_length)
 
119
int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
 
120
                  uint key_length)
120
121
{
121
122
  return _mi_ck_real_delete(info, info->s->keyinfo+keynr, key, key_length,
122
123
                            &info->s->state.key_root[keynr]);
124
125
 
125
126
 
126
127
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)
 
128
                              uchar *key, uint key_length, my_off_t *root)
128
129
{
129
130
  int error;
130
 
  uint32_t nod_flag;
131
 
  internal::my_off_t old_root;
132
 
  unsigned char *root_buff;
 
131
  uint nod_flag;
 
132
  my_off_t old_root;
 
133
  uchar *root_buff;
133
134
 
134
135
  if ((old_root=*root) == HA_OFFSET_ERROR)
135
136
  {
136
137
    mi_print_error(info->s, HA_ERR_CRASHED);
137
 
    return(errno=HA_ERR_CRASHED);
 
138
    return(my_errno=HA_ERR_CRASHED);
138
139
  }
139
 
  if (!(root_buff= (unsigned char*) malloc(keyinfo->block_length+
 
140
  if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
140
141
                                      MI_MAX_KEY_BUFF*2)))
141
142
  {
142
 
    return(errno=ENOMEM);
 
143
    return(my_errno=ENOMEM);
143
144
  }
144
145
  if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0))
145
146
  {
170
171
    }
171
172
  }
172
173
err:
173
 
  free(root_buff);
 
174
  my_afree((uchar*) root_buff);
174
175
  return(error);
175
176
} /* _mi_ck_real_delete */
176
177
 
184
185
        */
185
186
 
186
187
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)
 
188
                    uint comp_flag, uchar *key, uint key_length,
 
189
                    my_off_t page, uchar *anc_buff)
189
190
{
190
191
  int flag,ret_value,save_flag;
191
 
  uint32_t length,nod_flag,search_key_length;
 
192
  uint length,nod_flag,search_key_length;
192
193
  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
  uchar *leaf_buff,*keypos;
 
195
  my_off_t leaf_page= 0, next_block;
 
196
  uchar lastkey[MI_MAX_KEY_BUFF];
196
197
 
197
198
  search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
198
199
  flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
207
208
  if (nod_flag)
208
209
  {
209
210
    leaf_page=_mi_kpos(nod_flag,keypos);
210
 
    if (!(leaf_buff= (unsigned char*) malloc(keyinfo->block_length+
 
211
    if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
211
212
                                        MI_MAX_KEY_BUFF*2)))
212
213
    {
213
 
      errno=ENOMEM;
 
214
      my_errno=ENOMEM;
214
215
      return(-1);
215
216
    }
216
217
    if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
222
223
    if (!nod_flag)
223
224
    {
224
225
      mi_print_error(info->s, HA_ERR_CRASHED);
225
 
      errno=HA_ERR_CRASHED;             /* This should newer happend */
 
226
      my_errno=HA_ERR_CRASHED;          /* This should newer happend */
226
227
      goto err;
227
228
    }
228
229
    save_flag=0;
231
232
  }
232
233
  else
233
234
  {                                             /* Found key */
234
 
    uint32_t tmp;
 
235
    uint tmp;
235
236
    length=mi_getint(anc_buff);
236
237
    if (!(tmp= remove_key(keyinfo,nod_flag,keypos,lastkey,anc_buff+length,
237
238
                          &next_block)))
266
267
        goto err;
267
268
      }
268
269
      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);
 
270
                           (uchar*) 0,(uchar*) 0,(my_off_t) 0,(bool) 0);
270
271
    }
271
272
  }
272
273
  if (ret_value == 0 && mi_getint(anc_buff) > keyinfo->block_length)
276
277
  }
277
278
  if (save_flag && ret_value != 1)
278
279
    ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
279
 
  free(leaf_buff);
 
280
  my_afree((uchar*) leaf_buff);
280
281
  return(ret_value);
281
282
 
282
283
err:
283
 
  free(leaf_buff);
 
284
  my_afree((uchar*) leaf_buff);
284
285
  return (-1);
285
286
} /* d_search */
286
287
 
287
288
 
288
289
        /* Remove a key that has a page-reference */
289
290
 
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 */
 
291
static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key,
 
292
               uchar *anc_buff, my_off_t leaf_page, uchar *leaf_buff,
 
293
               uchar *keypos,           /* Pos to where deleted key was */
 
294
               my_off_t next_block,
 
295
               uchar *ret_key)          /* key before keypos in anc_buff */
295
296
{
296
297
  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;
 
298
  uint a_length,nod_flag,tmp;
 
299
  my_off_t next_page;
 
300
  uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
300
301
  MYISAM_SHARE *share=info->s;
301
302
  MI_KEY_PARAM s_temp;
302
303
 
308
309
  if ((nod_flag=mi_test_if_nod(leaf_buff)))
309
310
  {
310
311
    next_page= _mi_kpos(nod_flag,endpos);
311
 
    if (!(next_buff= (unsigned char*) malloc(keyinfo->block_length+
 
312
    if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
312
313
                                        MI_MAX_KEY_BUFF*2)))
313
314
      return(-1);
314
315
    if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
334
335
                                &tmp))
335
336
            goto err;
336
337
          ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
337
 
                               (unsigned char*) 0,(unsigned char*) 0,(internal::my_off_t) 0,0);
 
338
                               (uchar*) 0,(uchar*) 0,(my_off_t) 0,0);
338
339
        }
339
340
      }
340
341
      if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
341
342
        goto err;
342
343
    }
343
 
    free(next_buff);
 
344
    my_afree((uchar*) next_buff);
344
345
    return(ret_value);
345
346
  }
346
347
 
360
361
  prev_key=(keypos == anc_buff+2+share->base.key_reflength ?
361
362
            0 : ret_key);
362
363
  length=(*keyinfo->pack_key)(keyinfo,share->base.key_reflength,
363
 
                              keypos == endpos ? (unsigned char*) 0 : keypos,
 
364
                              keypos == endpos ? (uchar*) 0 : keypos,
364
365
                              prev_key, prev_key,
365
366
                              keybuff,&s_temp);
366
367
  if (length > 0)
367
 
    internal::bmove_upp((unsigned char*) endpos+length,(unsigned char*) endpos,(uint) (endpos-keypos));
 
368
    bmove_upp((uchar*) endpos+length,(uchar*) endpos,(uint) (endpos-keypos));
368
369
  else
369
 
    memmove(keypos,keypos-length, (int) (endpos-keypos)+length);
 
370
    memcpy(keypos,keypos-length, (int) (endpos-keypos)+length);
370
371
  (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
371
372
  /* Save pointer to next leaf */
372
373
  if (!(*keyinfo->get_key)(keyinfo,share->base.key_reflength,&keypos,ret_key))
385
386
        /* Balances adjacent pages if underflow occours */
386
387
 
387
388
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 */
 
389
                     uchar *anc_buff,
 
390
                     my_off_t leaf_page,/* Ancestor page and underflow page */
 
391
                     uchar *leaf_buff,
 
392
                     uchar *keypos)     /* Position to pos after key */
392
393
{
393
394
  int t_length;
394
 
  uint32_t length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
 
395
  uint length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
395
396
       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],
 
397
  my_off_t next_page;
 
398
  uchar anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
398
399
        *buff,*endpos,*next_keypos,*anc_pos,*half_pos,*temp_pos,*prev_key,
399
400
        *after_key;
400
401
  MI_KEY_PARAM s_temp;
434
435
    buff_length=mi_getint(buff);
435
436
 
436
437
    /* find keys to make a big key-page */
437
 
    memmove(next_keypos - key_reflength, buff + 2, key_reflength);
 
438
    memcpy(next_keypos - key_reflength, buff + 2, key_reflength);
438
439
    if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,next_keypos,&length)
439
440
        || !_mi_get_last_key(info,keyinfo,leaf_buff,leaf_key,
440
441
                             leaf_buff+leaf_length,&length))
441
442
      goto err;
442
443
 
443
444
    /* merge pages and put parting key from anc_buff between */
444
 
    prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
 
445
    prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
445
446
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,buff+p_length,
446
447
                                  prev_key, prev_key,
447
448
                                  anc_key, &s_temp);
448
449
    length=buff_length-p_length;
449
450
    endpos=buff+length+leaf_length+t_length;
450
451
    /* buff will always be larger than before !*/
451
 
    internal::bmove_upp((unsigned char*) endpos, (unsigned char*) buff+buff_length,length);
 
452
    bmove_upp((uchar*) endpos, (uchar*) buff+buff_length,length);
452
453
    memcpy(buff, leaf_buff, leaf_length);
453
454
    (*keyinfo->store_key)(keyinfo,buff+leaf_length,&s_temp);
454
455
    buff_length=(uint) (endpos-buff);
457
458
    /* remove key from anc_buff */
458
459
 
459
460
    if (!(s_length=remove_key(keyinfo,key_reflength,keypos,anc_key,
460
 
                              anc_buff+anc_length,(internal::my_off_t *) 0)))
 
461
                              anc_buff+anc_length,(my_off_t *) 0)))
461
462
      goto err;
462
463
 
463
464
    anc_length-=s_length;
486
487
      half_pos=after_key;
487
488
      _mi_kpointer(info,leaf_key+key_length,next_page);
488
489
      /* Save key in anc_buff */
489
 
      prev_key=(keypos == anc_buff+2+key_reflength ? (unsigned char*) 0 : anc_key),
 
490
      prev_key=(keypos == anc_buff+2+key_reflength ? (uchar*) 0 : anc_key),
490
491
      t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
491
 
                                    (keypos == endpos ? (unsigned char*) 0 :
 
492
                                    (keypos == endpos ? (uchar*) 0 :
492
493
                                     keypos),
493
494
                                    prev_key, prev_key,
494
495
                                    leaf_key, &s_temp);
495
496
      if (t_length >= 0)
496
 
        internal::bmove_upp((unsigned char*) endpos+t_length,(unsigned char*) endpos,
 
497
        bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,
497
498
                  (uint) (endpos-keypos));
498
499
      else
499
 
        memmove(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
 
500
        memcpy(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
500
501
      (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
501
502
      mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
502
503
 
503
504
        /* Store key first in new page */
504
505
      if (nod_flag)
505
 
        memmove(buff + 2, half_pos - nod_flag, nod_flag);
 
506
        memcpy(buff + 2, half_pos - nod_flag, nod_flag);
506
507
      if (!(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key))
507
508
        goto err;
508
 
      t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (unsigned char*) 0,
509
 
                                          (unsigned char*) 0, (unsigned char *) 0,
 
509
      t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (uchar*) 0,
 
510
                                          (uchar*) 0, (uchar *) 0,
510
511
                                          leaf_key, &s_temp);
511
512
      /* t_length will always be > 0 for a new page !*/
512
513
      length=(uint) ((buff+mi_getint(buff))-half_pos);
513
 
      memmove(buff + p_length + t_length, half_pos, length);
 
514
      memcpy(buff + p_length + t_length, half_pos, length);
514
515
      (*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp);
515
516
      mi_putint(buff,length+t_length+p_length,nod_flag);
516
517
 
533
534
  endpos=buff+buff_length;
534
535
 
535
536
  /* find keys to make a big key-page */
536
 
  memmove(next_keypos - key_reflength, leaf_buff+2, key_reflength);
 
537
  memcpy(next_keypos - key_reflength, leaf_buff+2, key_reflength);
537
538
  next_keypos=keypos;
538
539
  if (!(*keyinfo->get_key)(keyinfo,key_reflength,&next_keypos,
539
540
                           anc_key))
542
543
    goto err;
543
544
 
544
545
  /* merge pages and put parting key from anc_buff between */
545
 
  prev_key=(leaf_length == p_length ? (unsigned char*) 0 : leaf_key);
 
546
  prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
546
547
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
547
548
                                (leaf_length == p_length ?
548
 
                                 (unsigned char*) 0 : leaf_buff+p_length),
 
549
                                 (uchar*) 0 : leaf_buff+p_length),
549
550
                                prev_key, prev_key,
550
551
                                anc_key, &s_temp);
551
552
  if (t_length >= 0)
552
 
    memmove(endpos+t_length,leaf_buff+p_length, leaf_length-p_length);
 
553
    memcpy(endpos+t_length,leaf_buff+p_length, leaf_length-p_length);
553
554
  else                                          /* We gained space */
554
 
    memmove(endpos, leaf_buff+((int) p_length-t_length),
555
 
            leaf_length - p_length + t_length);
 
555
    memcpy(endpos, leaf_buff+((int) p_length-t_length),
 
556
           leaf_length - p_length + t_length);
556
557
 
557
558
  (*keyinfo->store_key)(keyinfo,endpos,&s_temp);
558
559
  buff_length=buff_length+leaf_length-p_length+t_length;
560
561
 
561
562
  /* remove key from anc_buff */
562
563
  if (!(s_length= remove_key(keyinfo,key_reflength,keypos,anc_key,
563
 
                             anc_buff+anc_length,(internal::my_off_t *) 0)))
 
564
                             anc_buff+anc_length,(my_off_t *) 0)))
564
565
    goto err;
565
566
 
566
567
  anc_length-=s_length;
587
588
 
588
589
    temp_pos=anc_buff+anc_length;
589
590
    t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
590
 
                                  keypos == temp_pos ? (unsigned char*) 0
 
591
                                  keypos == temp_pos ? (uchar*) 0
591
592
                                  : keypos,
592
593
                                  anc_pos, anc_pos,
593
594
                                  leaf_key,&s_temp);
594
595
    if (t_length > 0)
595
 
      internal::bmove_upp((unsigned char*) temp_pos+t_length,(unsigned char*) temp_pos,
 
596
      bmove_upp((uchar*) temp_pos+t_length,(uchar*) temp_pos,
596
597
                (uint) (temp_pos-keypos));
597
598
    else
598
 
      memmove(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
 
599
      memcpy(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
599
600
    (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
600
601
    mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
601
602
 
602
603
    /* Store first key on new page */
603
604
    if (nod_flag)
604
 
      memmove(leaf_buff+2, half_pos - nod_flag, nod_flag);
 
605
      memcpy(leaf_buff+2, half_pos - nod_flag, nod_flag);
605
606
    if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key)))
606
607
      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);
 
608
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
 
609
                                  (uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
609
610
    length=(uint) ((buff+buff_length)-half_pos);
610
 
    memmove(leaf_buff + p_length + t_length, half_pos, length);
 
611
    memcpy(leaf_buff + p_length + t_length, half_pos, length);
611
612
    (*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
612
613
    mi_putint(leaf_buff,length+t_length+p_length,nod_flag);
613
614
    if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
630
631
          returns how many chars was removed or 0 on error
631
632
        */
632
633
 
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 */
 
634
static uint remove_key(MI_KEYDEF *keyinfo, uint nod_flag,
 
635
                       uchar *keypos,   /* Where key starts */
 
636
                       uchar *lastkey,  /* key to be removed */
 
637
                       uchar *page_end, /* End of page */
 
638
                       my_off_t *next_block)    /* ptr to next block */
638
639
{
639
640
  int s_length;
640
 
  unsigned char *start;
 
641
  uchar *start;
641
642
 
642
643
  start=keypos;
643
644
  if (!(keyinfo->flag &
661
662
    {
662
663
      if (keyinfo->flag & HA_BINARY_PACK_KEY)
663
664
      {
664
 
        unsigned char *old_key=start;
665
 
        uint32_t next_length,prev_length,prev_pack_length;
 
665
        uchar *old_key=start;
 
666
        uint next_length,prev_length,prev_pack_length;
666
667
        get_key_length(next_length,keypos);
667
668
        get_key_pack_length(prev_length,prev_pack_length,old_key);
668
669
        if (next_length > prev_length)
669
670
        {
670
671
          /* We have to copy data from the current key to the next key */
671
 
          internal::bmove_upp(keypos, (lastkey+next_length),
 
672
          bmove_upp(keypos, (lastkey+next_length),
672
673
                    (next_length-prev_length));
673
674
          keypos-=(next_length-prev_length)+prev_pack_length;
674
675
          store_key_length(keypos,prev_length);
681
682
        if ((keyinfo->seg->flag & HA_PACK_KEY) && *keypos & 128)
682
683
        {
683
684
          /* Next key is packed against the current one */
684
 
          uint32_t next_length,prev_length,prev_pack_length,lastkey_length,
 
685
          uint next_length,prev_length,prev_pack_length,lastkey_length,
685
686
            rest_length;
686
687
          if (keyinfo->seg[0].length >= 127)
687
688
          {
714
715
 
715
716
          if (next_length >= prev_length)
716
717
          {             /* 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));
 
718
            uint pack_length,tmp;
 
719
            bmove_upp(keypos, (lastkey+next_length),
 
720
                      tmp=(next_length-prev_length));
720
721
            rest_length+=tmp;
721
722
            pack_length= prev_length ? get_pack_length(rest_length): 0;
722
723
            keypos-=tmp+pack_length+prev_pack_length;
749
750
  }
750
751
end:
751
752
  assert(page_end-start >= s_length);
752
 
  memmove(start, start + s_length, page_end-start-s_length);
 
753
  memcpy(start, start + s_length, page_end-start-s_length);
753
754
  return s_length;
754
755
} /* remove_key */