~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

  • Committer: Monty Taylor
  • Date: 2008-11-13 22:41:09 UTC
  • mto: (589.1.3 devel) (584.1.7 devel)
  • mto: This revision was merged to the branch mainline in revision 585.
  • Revision ID: monty@inaugust.com-20081113224109-4rkzdtn5f2ppzf9q
Check gnu ld status rather than gcc status (you never know)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/error.h>
24
24
#include <drizzled/probes.h>
25
25
#include <drizzled/sql_parse.h>
26
 
#include <drizzled/sql_base.h>
27
26
 
28
27
/**
29
28
  Implement DELETE SQL word.
49
48
  uint32_t usable_index= MAX_KEY;
50
49
  SELECT_LEX   *select_lex= &session->lex->select_lex;
51
50
  Session::killed_state killed_status= Session::NOT_KILLED;
52
 
 
 
51
  
53
52
 
54
53
  if (open_and_lock_tables(session, table_list))
55
54
    return(true);
194
193
    uint32_t         length= 0;
195
194
    SORT_FIELD  *sortorder;
196
195
    ha_rows examined_rows;
197
 
 
 
196
    
198
197
    if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR)
199
198
      usable_index= get_index_for_order(table, (order_st*)(order->first), limit);
200
199
 
201
200
    if (usable_index == MAX_KEY)
202
201
    {
203
 
      table->sort.io_cache= (IO_CACHE *) malloc(sizeof(IO_CACHE));
204
 
      memset(table->sort.io_cache, 0, sizeof(IO_CACHE));
205
 
 
206
 
 
 
202
      table->sort.io_cache= (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
 
203
                                                   MYF(MY_FAE | MY_ZEROFILL));
 
204
    
207
205
      if (!(sortorder= make_unireg_sortorder((order_st*) order->first,
208
206
                                             &length, NULL)) ||
209
207
          (table->sort.found_records = filesort(session, table, sortorder, length,
313
311
 
314
312
  if (!transactional_table && deleted > 0)
315
313
    session->transaction.stmt.modified_non_trans_table= true;
316
 
 
 
314
  
317
315
  /* See similar binlogging code in sql_update.cc, for comments */
318
316
  if ((error < 0) || session->transaction.stmt.modified_non_trans_table)
319
317
  {
 
318
    if (mysql_bin_log.is_open())
 
319
    {
 
320
      if (error < 0)
 
321
        session->clear_error();
 
322
      /*
 
323
        [binlog]: If 'handler::delete_all_rows()' was called and the
 
324
        storage engine does not inject the rows itself, we replicate
 
325
        statement-based; otherwise, 'ha_delete_row()' was used to
 
326
        delete specific rows which we might log row-based.
 
327
      */
 
328
      int log_result= session->binlog_query(Session::ROW_QUERY_TYPE,
 
329
                                        session->query, session->query_length,
 
330
                                        transactional_table, false, killed_status);
 
331
 
 
332
      if (log_result && transactional_table)
 
333
      {
 
334
        error=1;
 
335
      }
 
336
    }
320
337
    if (session->transaction.stmt.modified_non_trans_table)
321
338
      session->transaction.all.modified_non_trans_table= true;
322
339
  }
353
370
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds)
354
371
{
355
372
  SELECT_LEX *select_lex= &session->lex->select_lex;
356
 
 
 
373
  
357
374
  List<Item> all_fields;
358
375
 
359
376
  session->lex->allow_sum_func= 0;
360
377
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
361
378
                                    &session->lex->select_lex.top_join_list,
362
 
                                    table_list,
 
379
                                    table_list, 
363
380
                                    &select_lex->leaf_tables, false) ||
364
381
      setup_conds(session, table_list, select_lex->leaf_tables, conds))
365
382
    return(true);
381
398
 
382
399
 
383
400
/***************************************************************************
384
 
  Delete multiple tables from join
 
401
  Delete multiple tables from join 
385
402
***************************************************************************/
386
403
 
387
404
#define MEM_STRIP_BUF_SIZE current_session->variables.sortbuff_size
409
426
  LEX *lex= session->lex;
410
427
  TableList *aux_tables= (TableList *)lex->auxiliary_table_list.first;
411
428
  TableList *target_tbl;
412
 
 
 
429
  
413
430
 
414
431
  /*
415
432
    setup_tables() need for VIEWs. JOIN::prepare() will not do it second
474
491
int
475
492
multi_delete::prepare(List<Item> &, SELECT_LEX_UNIT *u)
476
493
{
477
 
 
 
494
  
478
495
  unit= u;
479
496
  do_delete= 1;
480
497
  session->set_proc_info("deleting from main table");
487
504
{
488
505
  TableList *walk;
489
506
  Unique **tempfiles_ptr;
490
 
 
 
507
  
491
508
 
492
509
  if ((session->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
493
510
    return(1);
619
636
 
620
637
void multi_delete::send_error(uint32_t errcode,const char *err)
621
638
{
622
 
 
 
639
  
623
640
 
624
641
  /* First send error what ever it is ... */
625
642
  my_message(errcode, err, MYF(0));
630
647
 
631
648
void multi_delete::abort()
632
649
{
633
 
 
 
650
  
634
651
 
635
652
  /* the error was handled or nothing deleted and no side effects return */
636
653
  if (error_handled ||
656
673
    assert(error_handled);
657
674
    return;
658
675
  }
659
 
 
 
676
  
660
677
  if (session->transaction.stmt.modified_non_trans_table)
661
678
  {
 
679
    /* 
 
680
       there is only side effects; to binlog with the error
 
681
    */
 
682
    if (mysql_bin_log.is_open())
 
683
    {
 
684
      session->binlog_query(Session::ROW_QUERY_TYPE,
 
685
                        session->query, session->query_length,
 
686
                        transactional_tables, false);
 
687
    }
662
688
    session->transaction.all.modified_non_trans_table= true;
663
689
  }
664
690
  return;
677
703
{
678
704
  int local_error= 0, counter= 0, tmp_error;
679
705
  bool will_batch;
680
 
 
 
706
  
681
707
  assert(do_delete);
682
708
 
683
709
  do_delete= 0;                                 // Mark called
686
712
 
687
713
  table_being_deleted= (delete_while_scanning ? delete_tables->next_local :
688
714
                        delete_tables);
689
 
 
 
715
 
690
716
  for (; table_being_deleted;
691
717
       table_being_deleted= table_being_deleted->next_local, counter++)
692
 
  {
 
718
  { 
693
719
    ha_rows last_deleted= deleted;
694
720
    Table *table = table_being_deleted->table;
695
721
    if (tempfiles[counter]->get(table))
758
784
 
759
785
  if ((local_error == 0) || session->transaction.stmt.modified_non_trans_table)
760
786
  {
 
787
    if (mysql_bin_log.is_open())
 
788
    {
 
789
      if (local_error == 0)
 
790
        session->clear_error();
 
791
      if (session->binlog_query(Session::ROW_QUERY_TYPE,
 
792
                            session->query, session->query_length,
 
793
                            transactional_tables, false, killed_status) &&
 
794
          !normal_tables)
 
795
      {
 
796
        local_error=1;  // Log write failed: roll back the SQL statement
 
797
      }
 
798
    }
761
799
    if (session->transaction.stmt.modified_non_trans_table)
762
800
      session->transaction.all.modified_non_trans_table= true;
763
801
  }
796
834
  Table *table;
797
835
  bool error;
798
836
  uint32_t path_length;
799
 
 
 
837
  
800
838
 
801
839
  memset(&create_info, 0, sizeof(create_info));
802
840
  /* If it is a temporary table, close and regenerate it */
804
842
  {
805
843
    handlerton *table_type= table->s->db_type();
806
844
    TABLE_SHARE *share= table->s;
 
845
    bool frm_only= (share->tmp_table == TMP_TABLE_FRM_FILE_ONLY);
807
846
 
808
 
    if (!ha_check_storage_engine_flag(table_type, HTON_BIT_CAN_RECREATE))
 
847
    if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
809
848
      goto trunc_by_del;
810
849
 
811
850
    table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
812
 
 
 
851
    
813
852
    close_temporary_table(session, table, 0, 0);    // Don't free share
814
853
    ha_create_table(session, share->normalized_path.str,
815
854
                    share->db.str, share->table_name.str, &create_info, 1);
818
857
                                             share->db.str,
819
858
                                             share->table_name.str, 1,
820
859
                                             OTM_OPEN))))
821
 
      (void) rm_temporary_table(table_type, path);
 
860
      (void) rm_temporary_table(table_type, path, frm_only);
822
861
    free_table_share(share);
823
862
    free((char*) table);
824
863
    /*