~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_delete.c

  • Committer: Monty Taylor
  • Date: 2008-07-16 19:10:24 UTC
  • mfrom: (51.1.127 remove-dbug)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: monty@inaugust.com-20080716191024-prjgoh7fbri7rx26
MergedĀ fromĀ remove-dbug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
  char lastpos[8];
40
40
 
41
41
  MYISAM_SHARE *share=info->s;
42
 
  DBUG_ENTER("mi_delete");
43
42
 
44
43
        /* Test if record is in datafile */
45
 
 
46
 
  DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
47
 
                  mi_print_error(info->s, HA_ERR_CRASHED);
48
 
                  DBUG_RETURN(my_errno= HA_ERR_CRASHED););
49
 
  DBUG_EXECUTE_IF("my_error_test_undefined_error",
50
 
                  mi_print_error(info->s, INT_MAX);
51
 
                  DBUG_RETURN(my_errno= INT_MAX););
52
44
  if (!(info->update & HA_STATE_AKTIV))
53
45
  {
54
 
    DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND); /* No database read */
 
46
    return(my_errno=HA_ERR_KEY_NOT_FOUND);      /* No database read */
55
47
  }
56
48
  if (share->options & HA_OPTION_READ_ONLY_DATA)
57
49
  {
58
 
    DBUG_RETURN(my_errno=EACCES);
 
50
    return(my_errno=EACCES);
59
51
  }
60
52
  if (_mi_readinfo(info,F_WRLCK,1))
61
 
    DBUG_RETURN(my_errno);
 
53
    return(my_errno);
62
54
  if (info->s->calc_checksum)
63
55
    info->checksum=(*info->s->calc_checksum)(info,record);
64
56
  if ((*share->compare_record)(info,record))
97
89
  VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
98
90
  if (info->invalidator != 0)
99
91
  {
100
 
    DBUG_PRINT("info", ("invalidator... '%s' (delete)", info->filename));
101
92
    (*info->invalidator)(info->filename);
102
93
    info->invalidator=0;
103
94
  }
104
 
  DBUG_RETURN(0);
 
95
  return(0);
105
96
 
106
97
err:
107
98
  save_errno=my_errno;
121
112
    my_errno=HA_ERR_CRASHED;
122
113
  }
123
114
 
124
 
  DBUG_RETURN(my_errno);
 
115
  return(my_errno);
125
116
} /* mi_delete */
126
117
 
127
118
 
142
133
  uint nod_flag;
143
134
  my_off_t old_root;
144
135
  uchar *root_buff;
145
 
  DBUG_ENTER("_mi_ck_real_delete");
146
136
 
147
137
  if ((old_root=*root) == HA_OFFSET_ERROR)
148
138
  {
149
139
    mi_print_error(info->s, HA_ERR_CRASHED);
150
 
    DBUG_RETURN(my_errno=HA_ERR_CRASHED);
 
140
    return(my_errno=HA_ERR_CRASHED);
151
141
  }
152
142
  if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
153
143
                                      MI_MAX_KEY_BUFF*2)))
154
144
  {
155
 
    DBUG_PRINT("error",("Couldn't allocate memory"));
156
 
    DBUG_RETURN(my_errno=ENOMEM);
 
145
    return(my_errno=ENOMEM);
157
146
  }
158
 
  DBUG_PRINT("info",("root_page: %ld", (long) old_root));
159
147
  if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0))
160
148
  {
161
149
    error= -1;
165
153
  {
166
154
    if (error == 2)
167
155
    {
168
 
      DBUG_PRINT("test",("Enlarging of root when deleting"));
169
156
      error=_mi_enlarge_root(info,keyinfo,key,root);
170
157
    }
171
158
    else /* error == 1 */
187
174
  }
188
175
err:
189
176
  my_afree((uchar*) root_buff);
190
 
  DBUG_PRINT("exit",("Return: %d",error));
191
 
  DBUG_RETURN(error);
 
177
  return(error);
192
178
} /* _mi_ck_real_delete */
193
179
 
194
180
 
210
196
  uchar *leaf_buff,*keypos;
211
197
  my_off_t leaf_page= 0, next_block;
212
198
  uchar lastkey[MI_MAX_KEY_BUFF];
213
 
  DBUG_ENTER("d_search");
214
 
  DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
215
199
 
216
200
  search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
217
201
  flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
218
202
                              comp_flag, &keypos, lastkey, &last_key);
219
203
  if (flag == MI_FOUND_WRONG_KEY)
220
204
  {
221
 
    DBUG_PRINT("error",("Found wrong key"));
222
 
    DBUG_RETURN(-1);
 
205
    return(-1);
223
206
  }
224
207
  nod_flag=mi_test_if_nod(anc_buff);
225
208
 
230
213
    if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
231
214
                                        MI_MAX_KEY_BUFF*2)))
232
215
    {
233
 
      DBUG_PRINT("error",("Couldn't allocate memory"));
234
216
      my_errno=ENOMEM;
235
 
      DBUG_PRINT("exit",("Return: %d",-1));
236
 
      DBUG_RETURN(-1);
 
217
      return(-1);
237
218
    }
238
219
    if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
239
220
      goto err;
243
224
  {
244
225
    if (!nod_flag)
245
226
    {
246
 
      DBUG_PRINT("error",("Didn't find key"));
247
227
      mi_print_error(info->s, HA_ERR_CRASHED);
248
228
      my_errno=HA_ERR_CRASHED;          /* This should newer happend */
249
229
      goto err;
267
247
    {                                           /* On leaf page */
268
248
      if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff))
269
249
      {
270
 
        DBUG_PRINT("exit",("Return: %d",-1));
271
 
        DBUG_RETURN(-1);
 
250
        return(-1);
272
251
      }
273
252
      /* Page will be update later if we return 1 */
274
 
      DBUG_RETURN(test(length <= (info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
 
253
      return(test(length <= (info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
275
254
                                  (uint) keyinfo->underflow_block_length)));
276
255
    }
277
256
    save_flag=1;
285
264
      ret_value= underflow(info,keyinfo,anc_buff,leaf_page,leaf_buff,keypos);
286
265
    else
287
266
    {                           /* This happens only with packed keys */
288
 
      DBUG_PRINT("test",("Enlarging of key when deleting"));
289
267
      if (!_mi_get_last_key(info,keyinfo,anc_buff,lastkey,keypos,&length))
290
268
      {
291
269
        goto err;
301
279
  }
302
280
  if (save_flag && ret_value != 1)
303
281
    ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
304
 
  else
305
 
  {
306
 
    DBUG_DUMP("page",(uchar*) anc_buff,mi_getint(anc_buff));
307
 
  }
308
282
  my_afree((uchar*) leaf_buff);
309
 
  DBUG_PRINT("exit",("Return: %d",ret_value));
310
 
  DBUG_RETURN(ret_value);
 
283
  return(ret_value);
311
284
 
312
285
err:
313
286
  my_afree((uchar*) leaf_buff);
314
 
  DBUG_PRINT("exit",("Error: %d",my_errno));
315
 
  DBUG_RETURN (-1);
 
287
  return (-1);
316
288
} /* d_search */
317
289
 
318
290
 
330
302
  uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
331
303
  MYISAM_SHARE *share=info->s;
332
304
  MI_KEY_PARAM s_temp;
333
 
  DBUG_ENTER("del");
334
 
  DBUG_PRINT("enter",("leaf_page: %ld  keypos: 0x%lx", (long) leaf_page,
335
 
                      (ulong) keypos));
336
 
  DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
337
305
 
338
306
  endpos=leaf_buff+mi_getint(leaf_buff);
339
307
  if (!(key_start=_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
340
308
                                   &tmp)))
341
 
    DBUG_RETURN(-1);
 
309
    return(-1);
342
310
 
343
311
  if ((nod_flag=mi_test_if_nod(leaf_buff)))
344
312
  {
345
313
    next_page= _mi_kpos(nod_flag,endpos);
346
314
    if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
347
315
                                        MI_MAX_KEY_BUFF*2)))
348
 
      DBUG_RETURN(-1);
 
316
      return(-1);
349
317
    if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
350
318
      ret_value= -1;
351
319
    else
352
320
    {
353
 
      DBUG_DUMP("next_page",(uchar*) next_buff,mi_getint(next_buff));
354
321
      if ((ret_value=del(info,keyinfo,key,anc_buff,next_page,next_buff,
355
322
                         keypos,next_block,ret_key)) >0)
356
323
      {
366
333
        }
367
334
        else
368
335
        {
369
 
          DBUG_PRINT("test",("Inserting of key when deleting"));
370
336
          if (!_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
371
337
                                &tmp))
372
338
            goto err;
378
344
        goto err;
379
345
    }
380
346
    my_afree((uchar*) next_buff);
381
 
    DBUG_RETURN(ret_value);
 
347
    return(ret_value);
382
348
  }
383
349
 
384
350
        /* Remove last key from leaf page */
411
377
  _mi_kpointer(info,keypos - share->base.key_reflength,next_block);
412
378
  mi_putint(anc_buff,a_length+length,share->base.key_reflength);
413
379
 
414
 
  DBUG_RETURN( mi_getint(leaf_buff) <=
 
380
  return( mi_getint(leaf_buff) <=
415
381
               (info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
416
382
                (uint) keyinfo->underflow_block_length));
417
383
err:
418
 
  DBUG_RETURN(-1);
 
384
  return(-1);
419
385
} /* del */
420
386
 
421
387
 
436
402
        *after_key;
437
403
  MI_KEY_PARAM s_temp;
438
404
  MYISAM_SHARE *share=info->s;
439
 
  DBUG_ENTER("underflow");
440
 
  DBUG_PRINT("enter",("leaf_page: %ld  keypos: 0x%lx",(long) leaf_page,
441
 
                      (ulong) keypos));
442
 
  DBUG_DUMP("anc_buff",(uchar*) anc_buff,mi_getint(anc_buff));
443
 
  DBUG_DUMP("leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
444
405
 
445
406
  buff=info->buff;
446
407
  info->buff_used=1;
456
417
  if ((keypos < anc_buff+anc_length && (info->state->records & 1)) ||
457
418
      keypos == anc_buff+2+key_reflength)
458
419
  {                                     /* Use page right of anc-page */
459
 
    DBUG_PRINT("test",("use right page"));
460
 
 
461
420
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
462
421
    {
463
422
      if (!(next_keypos=_mi_get_key(info, keyinfo,
476
435
    if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0))
477
436
      goto err;
478
437
    buff_length=mi_getint(buff);
479
 
    DBUG_DUMP("next",(uchar*) buff,buff_length);
480
438
 
481
439
    /* find keys to make a big key-page */
482
440
    bmove((uchar*) next_keypos-key_reflength,(uchar*) buff+2,
518
476
    else
519
477
    {                                           /* Page is full */
520
478
      endpos=anc_buff+anc_length;
521
 
      DBUG_PRINT("test",("anc_buff: 0x%lx  endpos: 0x%lx",
522
 
                         (long) anc_buff, (long) endpos));
523
479
      if (keypos != anc_buff+2+key_reflength &&
524
480
          !_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length))
525
481
        goto err;
567
523
    }
568
524
    if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
569
525
      goto err;
570
 
    DBUG_RETURN(anc_length <= ((info->quick_mode ? MI_MIN_BLOCK_LENGTH :
 
526
    return(anc_length <= ((info->quick_mode ? MI_MIN_BLOCK_LENGTH :
571
527
                                (uint) keyinfo->underflow_block_length)));
572
528
  }
573
529
 
574
 
  DBUG_PRINT("test",("use left page"));
575
 
 
576
530
  keypos=_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length);
577
531
  if (!keypos)
578
532
    goto err;
581
535
      goto err;
582
536
  buff_length=mi_getint(buff);
583
537
  endpos=buff+buff_length;
584
 
  DBUG_DUMP("prev",(uchar*) buff,buff_length);
585
538
 
586
539
  /* find keys to make a big key-page */
587
540
  bmove((uchar*) next_keypos - key_reflength,(uchar*) leaf_buff+2,
637
590
      goto err;
638
591
    _mi_kpointer(info,leaf_key+key_length,leaf_page);
639
592
    /* Save key in anc_buff */
640
 
    DBUG_DUMP("anc_buff",(uchar*) anc_buff,anc_length);
641
 
    DBUG_DUMP("key_to_anc",(uchar*) leaf_key,key_length);
642
593
 
643
594
    temp_pos=anc_buff+anc_length;
644
595
    t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
659
610
      bmove((uchar*) leaf_buff+2,(uchar*) half_pos-nod_flag,(size_t) nod_flag);
660
611
    if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key)))
661
612
      goto err;
662
 
    DBUG_DUMP("key_to_leaf",(uchar*) leaf_key,length);
663
613
    t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
664
614
                                  (uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
665
615
    length=(uint) ((buff+buff_length)-half_pos);
666
 
    DBUG_PRINT("info",("t_length: %d  length: %d",t_length,(int) length));
667
616
    bmove((uchar*) leaf_buff+p_length+t_length,(uchar*) half_pos,
668
617
          (size_t) length);
669
618
    (*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
674
623
  }
675
624
  if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff))
676
625
    goto err;
677
 
  DBUG_RETURN(anc_length <= (uint) keyinfo->block_length/2);
 
626
  return(anc_length <= (uint) keyinfo->block_length/2);
678
627
 
679
628
err:
680
 
  DBUG_RETURN(-1);
 
629
  return(-1);
681
630
} /* underflow */
682
631
 
683
632
 
696
645
{
697
646
  int s_length;
698
647
  uchar *start;
699
 
  DBUG_ENTER("remove_key");
700
 
  DBUG_PRINT("enter",("keypos: 0x%lx  page_end: 0x%lx",(long) keypos, (long) page_end));
701
648
 
702
649
  start=keypos;
703
650
  if (!(keyinfo->flag &
712
659
  {                                      /* Let keypos point at next key */
713
660
    /* Calculate length of key */
714
661
    if (!(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,lastkey))
715
 
      DBUG_RETURN(0);                           /* Error */
 
662
      return(0);                                /* Error */
716
663
 
717
664
    if (next_block && nod_flag)
718
665
      *next_block= _mi_kpos(nod_flag,keypos);
810
757
  end:
811
758
  bmove((uchar*) start,(uchar*) start+s_length,
812
759
        (uint) (page_end-start-s_length));
813
 
  DBUG_RETURN((uint) s_length);
 
760
  return((uint) s_length);
814
761
} /* remove_key */