~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_delete.cc

  • Committer: Brian Aker
  • Date: 2008-07-08 16:53:50 UTC
  • mfrom: (51.1.8 remove-dbug)
  • Revision ID: brian@tangent.org-20080708165350-y246k7585xv56c0m
Merging in Jay's Tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
  uint usable_index= MAX_KEY;
47
47
  SELECT_LEX   *select_lex= &thd->lex->select_lex;
48
48
  THD::killed_state killed_status= THD::NOT_KILLED;
49
 
  DBUG_ENTER("mysql_delete");
 
49
  
50
50
 
51
51
  if (open_and_lock_tables(thd, table_list))
52
 
    DBUG_RETURN(TRUE);
 
52
    return(TRUE);
53
53
  /* TODO look at this error */
54
54
  if (!(table= table_list->table))
55
55
  {
56
56
    my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), "", "");
57
 
    DBUG_RETURN(TRUE);
 
57
    return(TRUE);
58
58
  }
59
59
  thd_proc_info(thd, "init");
60
60
  table->map=1;
98
98
  if (thd->is_error())
99
99
  {
100
100
    /* Error evaluating val_int(). */
101
 
    DBUG_RETURN(TRUE);
 
101
    return(TRUE);
102
102
  }
103
103
 
104
104
  /*
128
128
    /* Update the table->file->stats.records number */
129
129
    table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
130
130
    ha_rows const maybe_deleted= table->file->stats.records;
131
 
    DBUG_PRINT("debug", ("Trying to use delete_all_rows()"));
132
131
    if (!(error=table->file->ha_delete_all_rows()))
133
132
    {
134
133
      error= -1;                                // ok
171
170
      mysql_truncate always gives a NULL conds argument, hence we never
172
171
      get here.
173
172
    */
174
 
    DBUG_RETURN(0);                             // Nothing to delete
 
173
    return(0);                          // Nothing to delete
175
174
  }
176
175
 
177
176
  /* If running in safe sql mode, don't allow updates without keys */
339
338
    if (thd->transaction.stmt.modified_non_trans_table)
340
339
      thd->transaction.all.modified_non_trans_table= TRUE;
341
340
  }
342
 
  DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
 
341
  assert(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
343
342
  free_underlaid_joins(thd, select_lex);
344
343
 
345
344
  MYSQL_DELETE_END();
347
346
  {
348
347
    thd->row_count_func= deleted;
349
348
    my_ok(thd, (ha_rows) thd->row_count_func);
350
 
    DBUG_PRINT("info",("%ld records deleted",(long) deleted));
351
349
  }
352
 
  DBUG_RETURN(error >= 0 || thd->is_error());
 
350
  return(error >= 0 || thd->is_error());
353
351
 
354
352
err:
355
353
  MYSQL_DELETE_END();
356
 
  DBUG_RETURN(TRUE);
 
354
  return(TRUE);
357
355
}
358
356
 
359
357
 
374
372
{
375
373
  Item *fake_conds= 0;
376
374
  SELECT_LEX *select_lex= &thd->lex->select_lex;
377
 
  DBUG_ENTER("mysql_prepare_delete");
 
375
  
378
376
  List<Item> all_fields;
379
377
 
380
378
  /*
396
394
                                    table_list, 
397
395
                                    &select_lex->leaf_tables, false) ||
398
396
      setup_conds(thd, table_list, select_lex->leaf_tables, conds))
399
 
    DBUG_RETURN(TRUE);
 
397
    return(TRUE);
400
398
  {
401
399
    TABLE_LIST *duplicate;
402
400
    if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0)))
403
401
    {
404
402
      update_non_unique_table_error(table_list, "DELETE", duplicate);
405
 
      DBUG_RETURN(TRUE);
 
403
      return(TRUE);
406
404
    }
407
405
  }
408
406
 
409
407
  if (select_lex->inner_refs_list.elements &&
410
408
    fix_inner_refs(thd, all_fields, select_lex, select_lex->ref_pointer_array))
411
 
    DBUG_RETURN(-1);
 
409
    return(-1);
412
410
 
413
411
  select_lex->fix_prepare_information(thd, conds, &fake_conds);
414
 
  DBUG_RETURN(FALSE);
 
412
  return(FALSE);
415
413
}
416
414
 
417
415
 
444
442
  LEX *lex= thd->lex;
445
443
  TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxiliary_table_list.first;
446
444
  TABLE_LIST *target_tbl;
447
 
  DBUG_ENTER("mysql_multi_delete_prepare");
 
445
  
448
446
 
449
447
  /*
450
448
    setup_tables() need for VIEWs. JOIN::prepare() will not do it second
456
454
                                    &thd->lex->select_lex.top_join_list,
457
455
                                    lex->query_tables,
458
456
                                    &lex->select_lex.leaf_tables, false))
459
 
    DBUG_RETURN(TRUE);
 
457
    return(TRUE);
460
458
 
461
459
 
462
460
  /*
471
469
  {
472
470
    if (!(target_tbl->table= target_tbl->correspondent_table->table))
473
471
    {
474
 
      DBUG_ASSERT(target_tbl->correspondent_table->merge_underlying_list &&
 
472
      assert(target_tbl->correspondent_table->merge_underlying_list &&
475
473
                  target_tbl->correspondent_table->merge_underlying_list->
476
474
                  next_local);
477
475
      my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), "", "");
478
 
      DBUG_RETURN(TRUE);
 
476
      return(TRUE);
479
477
    }
480
478
 
481
479
    /*
489
487
      {
490
488
        update_non_unique_table_error(target_tbl->correspondent_table,
491
489
                                      "DELETE", duplicate);
492
 
        DBUG_RETURN(TRUE);
 
490
        return(TRUE);
493
491
      }
494
492
    }
495
493
  }
496
 
  DBUG_RETURN(FALSE);
 
494
  return(FALSE);
497
495
}
498
496
 
499
497
 
509
507
int
510
508
multi_delete::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
511
509
{
512
 
  DBUG_ENTER("multi_delete::prepare");
 
510
  
513
511
  unit= u;
514
512
  do_delete= 1;
515
513
  thd_proc_info(thd, "deleting from main table");
516
 
  DBUG_RETURN(0);
 
514
  return(0);
517
515
}
518
516
 
519
517
 
522
520
{
523
521
  TABLE_LIST *walk;
524
522
  Unique **tempfiles_ptr;
525
 
  DBUG_ENTER("initialize_tables");
 
523
  
526
524
 
527
525
  if ((thd->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
528
 
    DBUG_RETURN(1);
 
526
    return(1);
529
527
 
530
528
  table_map tables_to_delete_from=0;
531
529
  for (walk= delete_tables; walk; walk= walk->next_local)
580
578
                                  table->file->ref_length,
581
579
                                  MEM_STRIP_BUF_SIZE);
582
580
  }
583
 
  DBUG_RETURN(thd->is_fatal_error != 0);
 
581
  return(thd->is_fatal_error != 0);
584
582
}
585
583
 
586
584
 
606
604
{
607
605
  int secure_counter= delete_while_scanning ? -1 : 0;
608
606
  TABLE_LIST *del_table;
609
 
  DBUG_ENTER("multi_delete::send_data");
 
607
  
610
608
 
611
609
  for (del_table= delete_tables;
612
610
       del_table;
624
622
    if (secure_counter < 0)
625
623
    {
626
624
      /* We are scanning the current table */
627
 
      DBUG_ASSERT(del_table == table_being_deleted);
 
625
      assert(del_table == table_being_deleted);
628
626
      table->status|= STATUS_DELETED;
629
627
      if (!(error=table->file->ha_delete_row(table->record[0])))
630
628
      {
635
633
      else
636
634
      {
637
635
        table->file->print_error(error,MYF(0));
638
 
        DBUG_RETURN(1);
 
636
        return(1);
639
637
      }
640
638
    }
641
639
    else
644
642
      if (error)
645
643
      {
646
644
        error= 1;                               // Fatal error
647
 
        DBUG_RETURN(1);
 
645
        return(1);
648
646
      }
649
647
    }
650
648
  }
651
 
  DBUG_RETURN(0);
 
649
  return(0);
652
650
}
653
651
 
654
652
 
655
653
void multi_delete::send_error(uint errcode,const char *err)
656
654
{
657
 
  DBUG_ENTER("multi_delete::send_error");
 
655
  
658
656
 
659
657
  /* First send error what ever it is ... */
660
658
  my_message(errcode, err, MYF(0));
661
659
 
662
 
  DBUG_VOID_RETURN;
 
660
  return;
663
661
}
664
662
 
665
663
 
666
664
void multi_delete::abort()
667
665
{
668
 
  DBUG_ENTER("multi_delete::abort");
 
666
  
669
667
 
670
668
  /* the error was handled or nothing deleted and no side effects return */
671
669
  if (error_handled ||
672
670
      (!thd->transaction.stmt.modified_non_trans_table && !deleted))
673
 
    DBUG_VOID_RETURN;
 
671
    return;
674
672
 
675
673
  /*
676
674
    If rows from the first table only has been deleted and it is
688
686
    */
689
687
    error= 1;
690
688
    send_eof();
691
 
    DBUG_ASSERT(error_handled);
692
 
    DBUG_VOID_RETURN;
 
689
    assert(error_handled);
 
690
    return;
693
691
  }
694
692
  
695
693
  if (thd->transaction.stmt.modified_non_trans_table)
705
703
    }
706
704
    thd->transaction.all.modified_non_trans_table= true;
707
705
  }
708
 
  DBUG_VOID_RETURN;
 
706
  return;
709
707
}
710
708
 
711
709
 
721
719
{
722
720
  int local_error= 0, counter= 0, tmp_error;
723
721
  bool will_batch;
724
 
  DBUG_ENTER("do_deletes");
725
 
  DBUG_ASSERT(do_delete);
 
722
  
 
723
  assert(do_delete);
726
724
 
727
725
  do_delete= 0;                                 // Mark called
728
726
  if (!found)
729
 
    DBUG_RETURN(0);
 
727
    return(0);
730
728
 
731
729
  table_being_deleted= (delete_while_scanning ? delete_tables->next_local :
732
730
                        delete_tables);
775
773
    if (local_error == -1)                              // End of file
776
774
      local_error = 0;
777
775
  }
778
 
  DBUG_RETURN(local_error);
 
776
  return(local_error);
779
777
}
780
778
 
781
779
 
852
850
  TABLE *table;
853
851
  bool error;
854
852
  uint path_length;
855
 
  DBUG_ENTER("mysql_truncate");
 
853
  
856
854
 
857
855
  bzero((char*) &create_info,sizeof(create_info));
858
856
  /* If it is a temporary table, close and regenerate it */
896
894
    {
897
895
      my_error(ER_NO_SUCH_TABLE, MYF(0),
898
896
               table_list->db, table_list->table_name);
899
 
      DBUG_RETURN(TRUE);
 
897
      return(TRUE);
900
898
    }
901
899
 
902
900
    if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type),
904
902
      goto trunc_by_del;
905
903
 
906
904
    if (lock_and_wait_for_table_name(thd, table_list))
907
 
      DBUG_RETURN(TRUE);
 
905
      return(TRUE);
908
906
  }
909
907
 
910
908
  // Remove the .frm extension AIX 5.2 64-bit compiler bug (BUG#16155): this
938
936
    unlock_table_name(thd, table_list);
939
937
    VOID(pthread_mutex_unlock(&LOCK_open));
940
938
  }
941
 
  DBUG_RETURN(error);
 
939
  return(error);
942
940
 
943
941
trunc_by_del:
944
942
  /* Probably InnoDB table */
960
958
  ha_commit(thd);
961
959
  thd->options= save_options;
962
960
  thd->current_stmt_binlog_row_based= save_binlog_row_based;
963
 
  DBUG_RETURN(error);
 
961
  return(error);
964
962
}