~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_update.cc

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  Single table and multi table updates of tables.
19
19
  Multi-table updates were introduced by Sinisa & Monty
20
20
*/
21
 
#include <drizzled/server_includes.h>
22
 
#include <drizzled/sql_select.h>
23
 
#include <drizzled/drizzled_error_messages.h>
 
21
 
 
22
#include "mysql_priv.h"
 
23
#include "sql_select.h"
 
24
 
 
25
/* Return 0 if row hasn't changed */
 
26
 
 
27
bool compare_record(TABLE *table)
 
28
{
 
29
  if (table->s->blob_fields + table->s->varchar_fields == 0)
 
30
    return cmp_record(table,record[1]);
 
31
  /* Compare null bits */
 
32
  if (memcmp(table->null_flags,
 
33
             table->null_flags+table->s->rec_buff_length,
 
34
             table->s->null_bytes))
 
35
    return TRUE;                                // Diff in NULL value
 
36
  /* Compare updated fields */
 
37
  for (Field **ptr= table->field ; *ptr ; ptr++)
 
38
  {
 
39
    if (bitmap_is_set(table->write_set, (*ptr)->field_index) &&
 
40
        (*ptr)->cmp_binary_offset(table->s->rec_buff_length))
 
41
      return TRUE;
 
42
  }
 
43
  return FALSE;
 
44
}
 
45
 
24
46
 
25
47
/*
26
48
  check that all fields are real fields
31
53
    items           Items for check
32
54
 
33
55
  RETURN
34
 
    true  Items can't be used in UPDATE
35
 
    false Items are OK
 
56
    TRUE  Items can't be used in UPDATE
 
57
    FALSE Items are OK
36
58
*/
37
59
 
38
60
static bool check_fields(THD *thd, List<Item> &items)
47
69
    {
48
70
      /* item has name, because it comes from VIEW SELECT list */
49
71
      my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name);
50
 
      return true;
 
72
      return TRUE;
51
73
    }
52
74
    /*
53
75
      we make temporary copy of Item_field, to avoid influence of changing
55
77
    */
56
78
    thd->change_item_tree(it.ref(), new Item_field(thd, field));
57
79
  }
58
 
  return false;
 
80
  return FALSE;
59
81
}
60
82
 
61
83
 
71
93
  @param[in] table   table
72
94
*/
73
95
 
74
 
static void prepare_record_for_error_message(int error, Table *table)
 
96
static void prepare_record_for_error_message(int error, TABLE *table)
75
97
{
76
98
  Field **field_p;
77
99
  Field *field;
78
 
  uint32_t keynr;
 
100
  uint keynr;
79
101
  MY_BITMAP unique_map; /* Fields in offended unique. */
80
102
  my_bitmap_map unique_map_buf[bitmap_buffer_size(MAX_FIELDS)];
81
 
  
 
103
  DBUG_ENTER("prepare_record_for_error_message");
 
104
 
82
105
  /*
83
106
    Only duplicate key errors print the key value.
84
107
    If storage engine does always read all columns, we have the value alraedy.
85
108
  */
86
109
  if ((error != HA_ERR_FOUND_DUPP_KEY) ||
87
110
      !(table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ))
88
 
    return;
 
111
    DBUG_VOID_RETURN;
89
112
 
90
113
  /*
91
114
    Get the number of the offended index.
92
115
    We will see MAX_KEY if the engine cannot determine the affected index.
93
116
  */
94
117
  if ((keynr= table->file->get_dup_key(error)) >= MAX_KEY)
95
 
    return;
 
118
    DBUG_VOID_RETURN;
96
119
 
97
120
  /* Create unique_map with all fields used by that index. */
98
 
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, false);
 
121
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, FALSE);
99
122
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
100
123
 
101
124
  /* Subtract read_set and write_set. */
108
131
    Otherwise no need to do anything.
109
132
  */
110
133
  if (bitmap_is_clear_all(&unique_map))
111
 
    return;
 
134
    DBUG_VOID_RETURN;
112
135
 
113
136
  /* Get identifier of last read record into table->file->ref. */
114
137
  table->file->position(table->record[0]);
123
146
    if (bitmap_is_set(&unique_map, field->field_index))
124
147
      field->copy_from_tmp(table->s->rec_buff_length);
125
148
 
126
 
  return;
 
149
  DBUG_VOID_RETURN;
127
150
}
128
151
 
129
152
 
136
159
    fields              fields for update
137
160
    values              values of fields for update
138
161
    conds               WHERE clause expression
139
 
    order_num           number of elemen in order_st BY clause
140
 
    order               order_st BY clause list
 
162
    order_num           number of elemen in ORDER BY clause
 
163
    order               ORDER BY clause list
141
164
    limit               limit clause
142
165
    handle_duplicates   how to handle duplicates
143
166
 
149
172
*/
150
173
 
151
174
int mysql_update(THD *thd,
152
 
                 TableList *table_list,
 
175
                 TABLE_LIST *table_list,
153
176
                 List<Item> &fields,
154
 
                 List<Item> &values,
 
177
                 List<Item> &values,
155
178
                 COND *conds,
156
 
                 uint32_t order_num, order_st *order,
157
 
                 ha_rows limit,
158
 
                 enum enum_duplicates handle_duplicates __attribute__((unused)),
159
 
                 bool ignore)
 
179
                 uint order_num, ORDER *order,
 
180
                 ha_rows limit,
 
181
                 enum enum_duplicates handle_duplicates, bool ignore)
160
182
{
161
183
  bool          using_limit= limit != HA_POS_ERROR;
162
184
  bool          safe_update= test(thd->options & OPTION_SAFE_UPDATES);
164
186
  bool          can_compare_record;
165
187
  int           error, loc_error;
166
188
  uint          used_index= MAX_KEY, dup_key_found;
167
 
  bool          need_sort= true;
168
 
  uint32_t          table_count= 0;
 
189
  bool          need_sort= TRUE;
 
190
  uint          table_count= 0;
169
191
  ha_rows       updated, found;
170
192
  key_map       old_covering_keys;
171
 
  Table         *table;
 
193
  TABLE         *table;
172
194
  SQL_SELECT    *select;
173
195
  READ_RECORD   info;
174
196
  SELECT_LEX    *select_lex= &thd->lex->select_lex;
175
197
  bool          need_reopen;
176
 
  uint64_t     id;
 
198
  ulonglong     id;
177
199
  List<Item> all_fields;
178
200
  THD::killed_state killed_status= THD::NOT_KILLED;
179
 
  
 
201
  DBUG_ENTER("mysql_update");
 
202
 
180
203
  for ( ; ; )
181
204
  {
182
205
    if (open_tables(thd, &table_list, &table_count, 0))
183
 
      return(1);
 
206
      DBUG_RETURN(1);
184
207
 
185
208
    if (!lock_tables(thd, table_list, table_count, &need_reopen))
186
209
      break;
187
210
    if (!need_reopen)
188
 
      return(1);
 
211
      DBUG_RETURN(1);
189
212
    close_tables_for_reopen(thd, &table_list);
190
213
  }
191
214
 
192
215
  if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
193
216
      (thd->fill_derived_tables() &&
194
217
       mysql_handle_derived(thd->lex, &mysql_derived_filling)))
195
 
    return(1);
 
218
    DBUG_RETURN(1);
196
219
 
197
 
  DRIZZLE_UPDATE_START();
198
 
  thd->set_proc_info("init");
 
220
  MYSQL_UPDATE_START();
 
221
  thd_proc_info(thd, "init");
199
222
  table= table_list->table;
200
223
 
201
224
  /* Calculate "table->covering_keys" based on the WHERE */
233
256
  if (select_lex->inner_refs_list.elements &&
234
257
    fix_inner_refs(thd, all_fields, select_lex, select_lex->ref_pointer_array))
235
258
  {
236
 
    DRIZZLE_UPDATE_END();
237
 
    return(-1);
 
259
    MYSQL_UPDATE_END();
 
260
    DBUG_RETURN(-1);
238
261
  }
239
262
 
240
263
  if (conds)
269
292
    free_underlaid_joins(thd, select_lex);
270
293
    if (error)
271
294
      goto abort;                               // Error in where
272
 
    DRIZZLE_UPDATE_END();
 
295
    MYSQL_UPDATE_END();
273
296
    my_ok(thd);                         // No matching records
274
 
    return(0);
 
297
    DBUG_RETURN(0);
275
298
  }
276
299
  if (!select && limit != HA_POS_ERROR)
277
300
  {
278
301
    if ((used_index= get_index_for_order(table, order, limit)) != MAX_KEY)
279
 
      need_sort= false;
 
302
      need_sort= FALSE;
280
303
  }
281
304
  /* If running in safe sql mode, don't allow updates without keys */
282
305
  if (table->quick_keys.is_clear_all())
330
353
    if (order && (need_sort || used_key_is_modified))
331
354
    {
332
355
      /*
333
 
        Doing an order_st BY;  Let filesort find and sort the rows we are going
 
356
        Doing an ORDER BY;  Let filesort find and sort the rows we are going
334
357
        to update
335
358
        NOTE: filesort will call table->prepare_for_position()
336
359
      */
337
 
      uint32_t         length= 0;
 
360
      uint         length= 0;
338
361
      SORT_FIELD  *sortorder;
339
362
      ha_rows examined_rows;
340
363
 
389
412
      else
390
413
        init_read_record_idx(&info, thd, table, 1, used_index);
391
414
 
392
 
      thd->set_proc_info("Searching rows for update");
 
415
      thd_proc_info(thd, "Searching rows for update");
393
416
      ha_rows tmp_limit= limit;
394
417
 
395
418
      while (!(error=info.read_record(&info)) && !thd->killed)
458
481
  thd->count_cuted_fields= ignore ? CHECK_FIELD_WARN
459
482
                                  : CHECK_FIELD_ERROR_FOR_NULL;
460
483
  thd->cuted_fields=0L;
461
 
  thd->set_proc_info("Updating");
 
484
  thd_proc_info(thd, "Updating");
462
485
 
463
486
  transactional_table= table->file->has_transactions();
464
 
  thd->abort_on_warning= test(!ignore);
 
487
  thd->abort_on_warning= test(!ignore &&
 
488
                              (thd->variables.sql_mode &
 
489
                               (MODE_STRICT_TRANS_TABLES |
 
490
                                MODE_STRICT_ALL_TABLES)));
465
491
  will_batch= !table->file->start_bulk_update();
466
492
 
467
493
  /*
493
519
 
494
520
      found++;
495
521
 
496
 
      if (!can_compare_record || table->compare_record())
 
522
      if (!can_compare_record || compare_record(table))
497
523
      {
498
524
        if (will_batch)
499
525
        {
614
640
    The cached value can not change whereas the killed status can
615
641
    (externally) since this point and change of the latter won't affect
616
642
    binlogging.
617
 
    It's assumed that if an error was set in combination with an effective
 
643
    It's assumed that if an error was set in combination with an effective 
618
644
    killed status then the error is due to killing.
619
645
  */
620
 
  killed_status= thd->killed; // get the status of the volatile
 
646
  killed_status= thd->killed; // get the status of the volatile 
621
647
  // simulated killing after the loop must be ineffective for binlogging
 
648
  DBUG_EXECUTE_IF("simulate_kill_bug27571",
 
649
                  {
 
650
                    thd->killed= THD::KILL_QUERY;
 
651
                  };);
622
652
  error= (killed_status == THD::NOT_KILLED)?  error : 1;
623
 
 
 
653
  
624
654
  if (error &&
625
655
      will_batch &&
626
656
      (loc_error= table->file->exec_bulk_update(&dup_key_found)))
646
676
  table->file->try_semi_consistent_read(0);
647
677
 
648
678
  if (!transactional_table && updated > 0)
649
 
    thd->transaction.stmt.modified_non_trans_table= true;
 
679
    thd->transaction.stmt.modified_non_trans_table= TRUE;
650
680
 
651
681
  end_read_record(&info);
652
682
  delete select;
653
 
  thd->set_proc_info("end");
654
 
  table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
 
683
  thd_proc_info(thd, "end");
 
684
  VOID(table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY));
655
685
 
656
686
  /*
657
687
    error < 0 means really no error at all: we processed all rows until the
658
688
    last one without error. error > 0 means an error (e.g. unique key
659
689
    violation and no IGNORE or REPLACE). error == 0 is also an error (if
660
690
    preparing the record or invoking before triggers fails). See
661
 
    ha_autocommit_or_rollback(error>=0) and return(error>=0) below.
 
691
    ha_autocommit_or_rollback(error>=0) and DBUG_RETURN(error>=0) below.
662
692
    Sometimes we want to binlog even if we updated no rows, in case user used
663
693
    it to be sure master and slave are in same state.
664
694
  */
670
700
        thd->clear_error();
671
701
      if (thd->binlog_query(THD::ROW_QUERY_TYPE,
672
702
                            thd->query, thd->query_length,
673
 
                            transactional_table, false, killed_status) &&
 
703
                            transactional_table, FALSE, killed_status) &&
674
704
          transactional_table)
675
705
      {
676
706
        error=1;                                // Rollback update
677
707
      }
678
708
    }
679
709
    if (thd->transaction.stmt.modified_non_trans_table)
680
 
      thd->transaction.all.modified_non_trans_table= true;
 
710
      thd->transaction.all.modified_non_trans_table= TRUE;
681
711
  }
682
 
  assert(transactional_table || !updated || thd->transaction.stmt.modified_non_trans_table);
 
712
  DBUG_ASSERT(transactional_table || !updated || thd->transaction.stmt.modified_non_trans_table);
683
713
  free_underlaid_joins(thd, select_lex);
684
714
 
685
715
  /* If LAST_INSERT_ID(X) was used, report X */
686
716
  id= thd->arg_of_last_insert_id_function ?
687
717
    thd->first_successful_insert_id_in_prev_stmt : 0;
688
718
 
689
 
  DRIZZLE_UPDATE_END();
 
719
  MYSQL_UPDATE_END();
690
720
  if (error < 0)
691
721
  {
692
722
    char buff[STRING_BUFFER_USUAL_SIZE];
695
725
    thd->row_count_func=
696
726
      (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
697
727
    my_ok(thd, (ulong) thd->row_count_func, id, buff);
 
728
    DBUG_PRINT("info",("%ld records updated", (long) updated));
698
729
  }
699
730
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;          /* calc cuted fields */
700
731
  thd->abort_on_warning= 0;
701
 
  return((error >= 0 || thd->is_error()) ? 1 : 0);
 
732
  DBUG_RETURN((error >= 0 || thd->is_error()) ? 1 : 0);
702
733
 
703
734
err:
704
735
  delete select;
711
742
  thd->abort_on_warning= 0;
712
743
 
713
744
abort:
714
 
  DRIZZLE_UPDATE_END();
715
 
  return(1);
 
745
  MYSQL_UPDATE_END();
 
746
  DBUG_RETURN(1);
716
747
}
717
748
 
718
749
/*
723
754
    thd                 - thread handler
724
755
    table_list          - global/local table list
725
756
    conds               - conditions
726
 
    order_num           - number of order_st BY list entries
727
 
    order               - order_st BY clause list
 
757
    order_num           - number of ORDER BY list entries
 
758
    order               - ORDER BY clause list
728
759
 
729
760
  RETURN VALUE
730
 
    false OK
731
 
    true  error
 
761
    FALSE OK
 
762
    TRUE  error
732
763
*/
733
 
bool mysql_prepare_update(THD *thd, TableList *table_list,
734
 
                         Item **conds, uint32_t order_num, order_st *order)
 
764
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
 
765
                         Item **conds, uint order_num, ORDER *order)
735
766
{
 
767
  Item *fake_conds= 0;
736
768
  List<Item> all_fields;
737
769
  SELECT_LEX *select_lex= &thd->lex->select_lex;
738
 
  
 
770
  DBUG_ENTER("mysql_prepare_update");
 
771
 
739
772
  /*
740
773
    Statement-based replication of UPDATE ... LIMIT is not safe as order of
741
774
    rows is not defined, so in mixed mode we go to row-based.
742
775
 
743
 
    Note that we may consider a statement as safe if order_st BY primary_key
 
776
    Note that we may consider a statement as safe if ORDER BY primary_key
744
777
    is present. However it may confuse users to see very similiar statements
745
778
    replicated differently.
746
779
  */
761
794
      select_lex->setup_ref_array(thd, order_num) ||
762
795
      setup_order(thd, select_lex->ref_pointer_array,
763
796
                  table_list, all_fields, all_fields, order))
764
 
    return(true);
 
797
    DBUG_RETURN(TRUE);
765
798
 
766
799
  /* Check that we are not using table that we are updating in a sub select */
767
800
  {
768
 
    TableList *duplicate;
 
801
    TABLE_LIST *duplicate;
769
802
    if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0)))
770
803
    {
771
804
      update_non_unique_table_error(table_list, "UPDATE", duplicate);
772
805
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
773
 
      return(true);
 
806
      DBUG_RETURN(TRUE);
774
807
    }
775
808
  }
776
 
 
777
 
  return(false);
 
809
  select_lex->fix_prepare_information(thd, conds, &fake_conds);
 
810
  DBUG_RETURN(FALSE);
778
811
}
779
812
 
780
813
 
794
827
 
795
828
  while ((item= (Item_field *) item_it++)) 
796
829
    map|= item->used_tables();
 
830
  DBUG_PRINT("info", ("table_map: 0x%08lx", (long) map));
797
831
  return map;
798
832
}
799
833
 
806
840
    thd         thread handler
807
841
 
808
842
  RETURN
809
 
    false OK
810
 
    true  Error
 
843
    FALSE OK
 
844
    TRUE  Error
811
845
*/
812
846
 
813
847
int mysql_multi_update_prepare(THD *thd)
814
848
{
815
849
  LEX *lex= thd->lex;
816
 
  TableList *table_list= lex->query_tables;
817
 
  TableList *tl, *leaves;
 
850
  TABLE_LIST *table_list= lex->query_tables;
 
851
  TABLE_LIST *tl, *leaves;
818
852
  List<Item> *fields= &lex->select_lex.item_list;
819
853
  table_map tables_for_update;
820
854
  bool update_view= 0;
823
857
    counter else junk will be assigned here, but then replaced with real
824
858
    count in open_tables()
825
859
  */
826
 
  uint32_t  table_count= lex->table_count;
 
860
  uint  table_count= lex->table_count;
827
861
  const bool using_lock_tables= thd->locked_tables != 0;
828
862
  bool original_multiupdate= (thd->lex->sql_command == SQLCOM_UPDATE_MULTI);
829
 
  bool need_reopen= false;
830
 
  
 
863
  bool need_reopen= FALSE;
 
864
  DBUG_ENTER("mysql_multi_update_prepare");
831
865
 
832
866
  /* following need for prepared statements, to run next time multi-update */
833
867
  thd->lex->sql_command= SQLCOM_UPDATE_MULTI;
838
872
  if (((original_multiupdate || need_reopen) &&
839
873
       open_tables(thd, &table_list, &table_count, 0)) ||
840
874
      mysql_handle_derived(lex, &mysql_derived_prepare))
841
 
    return(true);
 
875
    DBUG_RETURN(TRUE);
842
876
  /*
843
877
    setup_tables() need for VIEWs. JOIN::prepare() will call setup_tables()
844
878
    second time, but this call will do nothing (there are check for second
849
883
                                    &lex->select_lex.top_join_list,
850
884
                                    table_list,
851
885
                                    &lex->select_lex.leaf_tables, false))
852
 
    return(true);
 
886
    DBUG_RETURN(TRUE);
853
887
 
854
888
  if (setup_fields_with_no_wrap(thd, 0, *fields, MARK_COLUMNS_WRITE, 0, 0))
855
 
    return(true);
 
889
    DBUG_RETURN(TRUE);
856
890
 
857
891
  if (update_view && check_fields(thd, *fields))
858
892
  {
859
 
    return(true);
 
893
    DBUG_RETURN(TRUE);
860
894
  }
861
895
 
862
896
  tables_for_update= get_table_map(fields);
867
901
  leaves= lex->select_lex.leaf_tables;
868
902
  for (tl= leaves; tl; tl= tl->next_leaf)
869
903
  {
870
 
    Table *table= tl->table;
 
904
    TABLE *table= tl->table;
871
905
    /* Only set timestamp column if this is not modified */
872
906
    if (table->timestamp_field &&
873
907
        bitmap_is_set(table->write_set,
878
912
    if (table->map & tables_for_update)
879
913
    {
880
914
      table->mark_columns_needed_for_update();
 
915
      DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
881
916
      /*
882
917
        If table will be updated we should not downgrade lock for it and
883
918
        leave it as is.
885
920
    }
886
921
    else
887
922
    {
 
923
      DBUG_PRINT("info",("setting table `%s` for read-only", tl->alias));
888
924
      /*
889
925
        If we are using the binary log, we need TL_READ_NO_INSERT to get
890
926
        correct order of statements. Otherwise, we use a TL_READ lock to
892
928
      */
893
929
      tl->lock_type= using_update_log ? TL_READ_NO_INSERT : TL_READ;
894
930
      tl->updating= 0;
895
 
      /* Update Table::lock_type accordingly. */
 
931
      /* Update TABLE::lock_type accordingly. */
896
932
      if (!tl->placeholder() && !using_lock_tables)
897
933
        tl->table->reginfo.lock_type= tl->lock_type;
898
934
    }
902
938
  if (lock_tables(thd, table_list, table_count, &need_reopen))
903
939
  {
904
940
    if (!need_reopen)
905
 
      return(true);
 
941
      DBUG_RETURN(TRUE);
906
942
 
907
943
    /*
908
944
      We have to reopen tables since some of them were altered or dropped
916
952
      item->cleanup();
917
953
 
918
954
    /* We have to cleanup translation tables of views. */
919
 
    for (TableList *tbl= table_list; tbl; tbl= tbl->next_global)
 
955
    for (TABLE_LIST *tbl= table_list; tbl; tbl= tbl->next_global)
920
956
      tbl->cleanup_items();
921
957
 
922
958
    close_tables_for_reopen(thd, &table_list);
927
963
    Check that we are not using table that we are updating, but we should
928
964
    skip all tables of UPDATE SELECT itself
929
965
  */
930
 
  lex->select_lex.exclude_from_table_unique_test= true;
 
966
  lex->select_lex.exclude_from_table_unique_test= TRUE;
931
967
  /* We only need SELECT privilege for columns in the values list */
932
968
  for (tl= leaves; tl; tl= tl->next_leaf)
933
969
  {
934
970
    if (tl->lock_type != TL_READ &&
935
971
        tl->lock_type != TL_READ_NO_INSERT)
936
972
    {
937
 
      TableList *duplicate;
 
973
      TABLE_LIST *duplicate;
938
974
      if ((duplicate= unique_table(thd, tl, table_list, 0)))
939
975
      {
940
976
        update_non_unique_table_error(table_list, "UPDATE", duplicate);
941
 
        return(true);
 
977
        DBUG_RETURN(TRUE);
942
978
      }
943
979
    }
944
980
  }
945
981
  /*
946
 
    Set exclude_from_table_unique_test value back to false. It is needed for
 
982
    Set exclude_from_table_unique_test value back to FALSE. It is needed for
947
983
    further check in multi_update::prepare whether to use record cache.
948
984
  */
949
 
  lex->select_lex.exclude_from_table_unique_test= false;
 
985
  lex->select_lex.exclude_from_table_unique_test= FALSE;
950
986
 
951
987
  if (thd->fill_derived_tables() &&
952
988
      mysql_handle_derived(lex, &mysql_derived_filling))
953
 
    return(true);
 
989
    DBUG_RETURN(TRUE);
954
990
 
955
 
  return (false);
 
991
  DBUG_RETURN (FALSE);
956
992
}
957
993
 
958
994
 
961
997
*/
962
998
 
963
999
bool mysql_multi_update(THD *thd,
964
 
                        TableList *table_list,
 
1000
                        TABLE_LIST *table_list,
965
1001
                        List<Item> *fields,
966
1002
                        List<Item> *values,
967
1003
                        COND *conds,
968
 
                        uint64_t options,
 
1004
                        ulonglong options,
969
1005
                        enum enum_duplicates handle_duplicates, bool ignore,
970
1006
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
971
1007
{
972
1008
  multi_update *result;
973
1009
  bool res;
974
 
  
 
1010
  DBUG_ENTER("mysql_multi_update");
 
1011
 
975
1012
  if (!(result= new multi_update(table_list,
976
1013
                                 thd->lex->select_lex.leaf_tables,
977
1014
                                 fields, values,
978
1015
                                 handle_duplicates, ignore)))
979
 
    return(true);
 
1016
    DBUG_RETURN(TRUE);
980
1017
 
981
 
  thd->abort_on_warning= true;
 
1018
  thd->abort_on_warning= test(thd->variables.sql_mode &
 
1019
                              (MODE_STRICT_TRANS_TABLES |
 
1020
                               MODE_STRICT_ALL_TABLES));
982
1021
 
983
1022
  List<Item> total_list;
984
1023
  res= mysql_select(thd, &select_lex->ref_pointer_array,
985
1024
                      table_list, select_lex->with_wild,
986
1025
                      total_list,
987
 
                      conds, 0, (order_st *) NULL, (order_st *)NULL, (Item *) NULL,
988
 
                      (order_st *)NULL,
 
1026
                      conds, 0, (ORDER *) NULL, (ORDER *)NULL, (Item *) NULL,
 
1027
                      (ORDER *)NULL,
989
1028
                      options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
990
1029
                      OPTION_SETUP_TABLES_DONE,
991
1030
                      result, unit, select_lex);
 
1031
  DBUG_PRINT("info",("res: %d  report_error: %d", res,
 
1032
                     (int) thd->is_error()));
992
1033
  res|= thd->is_error();
993
1034
  if (unlikely(res))
994
1035
  {
998
1039
  }
999
1040
  delete result;
1000
1041
  thd->abort_on_warning= 0;
1001
 
  return(false);
 
1042
  DBUG_RETURN(FALSE);
1002
1043
}
1003
1044
 
1004
1045
 
1005
 
multi_update::multi_update(TableList *table_list,
1006
 
                           TableList *leaves_list,
 
1046
multi_update::multi_update(TABLE_LIST *table_list,
 
1047
                           TABLE_LIST *leaves_list,
1007
1048
                           List<Item> *field_list, List<Item> *value_list,
1008
1049
                           enum enum_duplicates handle_duplicates_arg,
1009
1050
                           bool ignore_arg)
1019
1060
  Connect fields with tables and create list of tables that are updated
1020
1061
*/
1021
1062
 
1022
 
int multi_update::prepare(List<Item> &not_used_values __attribute__((unused)),
1023
 
                          SELECT_LEX_UNIT *lex_unit __attribute__((unused)))
 
1063
int multi_update::prepare(List<Item> &not_used_values,
 
1064
                          SELECT_LEX_UNIT *lex_unit)
1024
1065
{
1025
 
  TableList *table_ref;
 
1066
  TABLE_LIST *table_ref;
1026
1067
  SQL_LIST update;
1027
1068
  table_map tables_to_update;
1028
1069
  Item_field *item;
1029
1070
  List_iterator_fast<Item> field_it(*fields);
1030
1071
  List_iterator_fast<Item> value_it(*values);
1031
 
  uint32_t i, max_fields;
1032
 
  uint32_t leaf_table_count= 0;
1033
 
  
 
1072
  uint i, max_fields;
 
1073
  uint leaf_table_count= 0;
 
1074
  DBUG_ENTER("multi_update::prepare");
 
1075
 
1034
1076
  thd->count_cuted_fields= CHECK_FIELD_WARN;
1035
1077
  thd->cuted_fields=0L;
1036
 
  thd->set_proc_info("updating main table");
 
1078
  thd_proc_info(thd, "updating main table");
1037
1079
 
1038
1080
  tables_to_update= get_table_map(fields);
1039
1081
 
1040
1082
  if (!tables_to_update)
1041
1083
  {
1042
1084
    my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
1043
 
    return(1);
 
1085
    DBUG_RETURN(1);
1044
1086
  }
1045
1087
 
1046
1088
  /*
1049
1091
  */
1050
1092
 
1051
1093
  if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
1052
 
    return(1);
 
1094
    DBUG_RETURN(1);
1053
1095
 
1054
1096
  /*
1055
1097
    Save tables beeing updated in update_tables
1061
1103
  for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
1062
1104
  {
1063
1105
    /* TODO: add support of view of join support */
1064
 
    Table *table=table_ref->table;
 
1106
    TABLE *table=table_ref->table;
1065
1107
    leaf_table_count++;
1066
1108
    if (tables_to_update & table->map)
1067
1109
    {
1068
 
      TableList *tl= (TableList*) thd->memdup((char*) table_ref,
 
1110
      TABLE_LIST *tl= (TABLE_LIST*) thd->memdup((char*) table_ref,
1069
1111
                                                sizeof(*tl));
1070
1112
      if (!tl)
1071
 
        return(1);
1072
 
      update.link_in_list((unsigned char*) tl, (unsigned char**) &tl->next_local);
 
1113
        DBUG_RETURN(1);
 
1114
      update.link_in_list((uchar*) tl, (uchar**) &tl->next_local);
1073
1115
      tl->shared= table_count++;
1074
1116
      table->no_keyread=1;
1075
1117
      table->covering_keys.clear_all();
1079
1121
 
1080
1122
 
1081
1123
  table_count=  update.elements;
1082
 
  update_tables= (TableList*) update.first;
 
1124
  update_tables= (TABLE_LIST*) update.first;
1083
1125
 
1084
 
  tmp_tables = (Table**) thd->calloc(sizeof(Table *) * table_count);
 
1126
  tmp_tables = (TABLE**) thd->calloc(sizeof(TABLE *) * table_count);
1085
1127
  tmp_table_param = (TMP_TABLE_PARAM*) thd->calloc(sizeof(TMP_TABLE_PARAM) *
1086
1128
                                                   table_count);
1087
1129
  fields_for_table= (List_item **) thd->alloc(sizeof(List_item *) *
1089
1131
  values_for_table= (List_item **) thd->alloc(sizeof(List_item *) *
1090
1132
                                              table_count);
1091
1133
  if (thd->is_fatal_error)
1092
 
    return(1);
 
1134
    DBUG_RETURN(1);
1093
1135
  for (i=0 ; i < table_count ; i++)
1094
1136
  {
1095
1137
    fields_for_table[i]= new List_item;
1096
1138
    values_for_table[i]= new List_item;
1097
1139
  }
1098
1140
  if (thd->is_fatal_error)
1099
 
    return(1);
 
1141
    DBUG_RETURN(1);
1100
1142
 
1101
1143
  /* Split fields into fields_for_table[] and values_by_table[] */
1102
1144
 
1103
1145
  while ((item= (Item_field *) field_it++))
1104
1146
  {
1105
1147
    Item *value= value_it++;
1106
 
    uint32_t offset= item->field->table->pos_in_table_list->shared;
 
1148
    uint offset= item->field->table->pos_in_table_list->shared;
1107
1149
    fields_for_table[offset]->push_back(item);
1108
1150
    values_for_table[offset]->push_back(value);
1109
1151
  }
1110
1152
  if (thd->is_fatal_error)
1111
 
    return(1);
 
1153
    DBUG_RETURN(1);
1112
1154
 
1113
1155
  /* Allocate copy fields */
1114
1156
  max_fields=0;
1115
1157
  for (i=0 ; i < table_count ; i++)
1116
1158
    set_if_bigger(max_fields, fields_for_table[i]->elements + leaf_table_count);
1117
1159
  copy_field= new Copy_field[max_fields];
1118
 
  return(thd->is_fatal_error != 0);
 
1160
  DBUG_RETURN(thd->is_fatal_error != 0);
1119
1161
}
1120
1162
 
1121
1163
 
1142
1184
    - Table is not joined to itself.
1143
1185
 
1144
1186
    This function gets information about fields to be updated from
1145
 
    the Table::write_set bitmap.
 
1187
    the TABLE::write_set bitmap.
1146
1188
 
1147
1189
  WARNING
1148
1190
    This code is a bit dependent of how make_join_readinfo() works.
1153
1195
*/
1154
1196
 
1155
1197
static bool safe_update_on_fly(THD *thd, JOIN_TAB *join_tab,
1156
 
                               TableList *table_ref, TableList *all_tables)
 
1198
                               TABLE_LIST *table_ref, TABLE_LIST *all_tables)
1157
1199
{
1158
 
  Table *table= join_tab->table;
 
1200
  TABLE *table= join_tab->table;
1159
1201
  if (unique_table(thd, table_ref, all_tables, 0))
1160
1202
    return 0;
1161
1203
  switch (join_tab->type) {
1162
1204
  case JT_SYSTEM:
1163
1205
  case JT_CONST:
1164
1206
  case JT_EQ_REF:
1165
 
    return true;                                // At most one matching row
 
1207
    return TRUE;                                // At most one matching row
1166
1208
  case JT_REF:
1167
1209
  case JT_REF_OR_NULL:
1168
1210
    return !is_key_used(table, join_tab->ref.key, table->write_set);
1174
1216
    if ((table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1175
1217
        table->s->primary_key < MAX_KEY)
1176
1218
      return !is_key_used(table, table->s->primary_key, table->write_set);
1177
 
    return true;
 
1219
    return TRUE;
1178
1220
  default:
1179
1221
    break;                                      // Avoid compler warning
1180
1222
  }
1181
 
  return false;
 
1223
  return FALSE;
1182
1224
 
1183
1225
}
1184
1226
 
1195
1237
bool
1196
1238
multi_update::initialize_tables(JOIN *join)
1197
1239
{
1198
 
  TableList *table_ref;
1199
 
  
 
1240
  TABLE_LIST *table_ref;
 
1241
  DBUG_ENTER("initialize_tables");
 
1242
 
1200
1243
  if ((thd->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
1201
 
    return(1);
 
1244
    DBUG_RETURN(1);
1202
1245
  main_table=join->join_tab->table;
1203
1246
  table_to_update= 0;
1204
1247
 
1205
1248
  /* Any update has at least one pair (field, value) */
1206
 
  assert(fields->elements);
 
1249
  DBUG_ASSERT(fields->elements);
1207
1250
 
1208
1251
  /* Create a temporary table for keys to all tables, except main table */
1209
1252
  for (table_ref= update_tables; table_ref; table_ref= table_ref->next_local)
1210
1253
  {
1211
 
    Table *table=table_ref->table;
1212
 
    uint32_t cnt= table_ref->shared;
 
1254
    TABLE *table=table_ref->table;
 
1255
    uint cnt= table_ref->shared;
1213
1256
    List<Item> temp_fields;
1214
 
    order_st     group;
 
1257
    ORDER     group;
1215
1258
    TMP_TABLE_PARAM *tmp_param;
1216
1259
 
1217
1260
    table->mark_columns_needed_for_update();
1237
1280
      OPTION condition.
1238
1281
    */
1239
1282
 
1240
 
    List_iterator_fast<Table> tbl_it(unupdated_check_opt_tables);
1241
 
    Table *tbl= table;
 
1283
    List_iterator_fast<TABLE> tbl_it(unupdated_check_opt_tables);
 
1284
    TABLE *tbl= table;
1242
1285
    do
1243
1286
    {
1244
1287
      Field_string *field= new Field_string(tbl->file->ref_length, 0,
1245
1288
                                            tbl->alias, &my_charset_bin);
1246
 
#ifdef OLD
1247
 
      Field_varstring *field= new Field_varstring(tbl->file->ref_length, 0,
1248
 
                                                  tbl->alias, tbl->s, &my_charset_bin);
1249
 
#endif
1250
1289
      if (!field)
1251
 
        return(1);
 
1290
        DBUG_RETURN(1);
1252
1291
      field->init(tbl);
1253
1292
      /*
1254
1293
        The field will be converted to varstring when creating tmp table if
1255
1294
        table to be updated was created by mysql 4.1. Deny this.
1256
1295
      */
 
1296
      field->can_alter_field_type= 0;
1257
1297
      Item_field *ifield= new Item_field((Field *) field);
1258
1298
      if (!ifield)
1259
 
         return(1);
 
1299
         DBUG_RETURN(1);
1260
1300
      ifield->maybe_null= 0;
1261
1301
      if (temp_fields.push_back(ifield))
1262
 
        return(1);
 
1302
        DBUG_RETURN(1);
1263
1303
    } while ((tbl= tbl_it++));
1264
1304
 
1265
1305
    temp_fields.concat(fields_for_table[cnt]);
1266
1306
 
1267
1307
    /* Make an unique key over the first field to avoid duplicated updates */
1268
 
    memset(&group, 0, sizeof(group));
 
1308
    bzero((char*) &group, sizeof(group));
1269
1309
    group.asc= 1;
1270
1310
    group.item= (Item**) temp_fields.head_ref();
1271
1311
 
1276
1316
    if (!(tmp_tables[cnt]=create_tmp_table(thd,
1277
1317
                                           tmp_param,
1278
1318
                                           temp_fields,
1279
 
                                           (order_st*) &group, 0, 0,
 
1319
                                           (ORDER*) &group, 0, 0,
1280
1320
                                           TMP_TABLE_ALL_COLUMNS,
1281
1321
                                           HA_POS_ERROR,
1282
1322
                                           (char *) "")))
1283
 
      return(1);
 
1323
      DBUG_RETURN(1);
1284
1324
    tmp_tables[cnt]->file->extra(HA_EXTRA_WRITE_CACHE);
1285
1325
  }
1286
 
  return(0);
 
1326
  DBUG_RETURN(0);
1287
1327
}
1288
1328
 
1289
1329
 
1290
1330
multi_update::~multi_update()
1291
1331
{
1292
 
  TableList *table;
 
1332
  TABLE_LIST *table;
1293
1333
  for (table= update_tables ; table; table= table->next_local)
1294
1334
  {
1295
1335
    table->table->no_keyread= table->table->no_cache= 0;
1299
1339
 
1300
1340
  if (tmp_tables)
1301
1341
  {
1302
 
    for (uint32_t cnt = 0; cnt < table_count; cnt++)
 
1342
    for (uint cnt = 0; cnt < table_count; cnt++)
1303
1343
    {
1304
1344
      if (tmp_tables[cnt])
1305
1345
      {
1306
 
        tmp_tables[cnt]->free_tmp_table(thd);
 
1346
        free_tmp_table(thd, tmp_tables[cnt]);
1307
1347
        tmp_table_param[cnt].cleanup();
1308
1348
      }
1309
1349
    }
1311
1351
  if (copy_field)
1312
1352
    delete [] copy_field;
1313
1353
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;          // Restore this setting
1314
 
  assert(trans_safe || !updated ||
 
1354
  DBUG_ASSERT(trans_safe || !updated || 
1315
1355
              thd->transaction.all.modified_non_trans_table);
1316
1356
}
1317
1357
 
1318
1358
 
1319
 
bool multi_update::send_data(List<Item> &not_used_values __attribute__((unused)))
 
1359
bool multi_update::send_data(List<Item> &not_used_values)
1320
1360
{
1321
 
  TableList *cur_table;
1322
 
  
 
1361
  TABLE_LIST *cur_table;
 
1362
  DBUG_ENTER("multi_update::send_data");
 
1363
 
1323
1364
  for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
1324
1365
  {
1325
 
    Table *table= cur_table->table;
1326
 
    uint32_t offset= cur_table->shared;
 
1366
    TABLE *table= cur_table->table;
 
1367
    uint offset= cur_table->shared;
1327
1368
    /*
1328
1369
      Check if we are using outer join and we didn't find the row
1329
1370
      or if we have already updated this row in the previous call to this
1355
1396
      store_record(table,record[1]);
1356
1397
      if (fill_record(thd, *fields_for_table[offset],
1357
1398
                      *values_for_table[offset], 0))
1358
 
        return(1);
 
1399
        DBUG_RETURN(1);
1359
1400
 
1360
1401
      found++;
1361
 
      if (!can_compare_record || table->compare_record())
 
1402
      if (!can_compare_record || compare_record(table))
1362
1403
      {
1363
1404
        int error;
1364
1405
        if (!updated++)
1389
1430
 
1390
1431
            prepare_record_for_error_message(error, table);
1391
1432
            table->file->print_error(error,MYF(flags));
1392
 
            return(1);
 
1433
            DBUG_RETURN(1);
1393
1434
          }
1394
1435
        }
1395
1436
        else
1406
1447
          else
1407
1448
          {
1408
1449
            trans_safe= 0;
1409
 
            thd->transaction.stmt.modified_non_trans_table= true;
 
1450
            thd->transaction.stmt.modified_non_trans_table= TRUE;
1410
1451
          }
1411
1452
        }
1412
1453
      }
1414
1455
    else
1415
1456
    {
1416
1457
      int error;
1417
 
      Table *tmp_table= tmp_tables[offset];
 
1458
      TABLE *tmp_table= tmp_tables[offset];
1418
1459
      /*
1419
1460
       For updatable VIEW store rowid of the updated table and
1420
1461
       rowids of tables used in the CHECK OPTION condition.
1421
1462
      */
1422
 
      uint32_t field_num= 0;
1423
 
      List_iterator_fast<Table> tbl_it(unupdated_check_opt_tables);
1424
 
      Table *tbl= table;
 
1463
      uint field_num= 0;
 
1464
      List_iterator_fast<TABLE> tbl_it(unupdated_check_opt_tables);
 
1465
      TABLE *tbl= table;
1425
1466
      do
1426
1467
      {
1427
1468
        tbl->file->position(tbl->record[0]);
1428
 
        memcpy(tmp_table->field[field_num]->ptr,
1429
 
               tbl->file->ref, tbl->file->ref_length);
 
1469
        memcpy((char*) tmp_table->field[field_num]->ptr,
 
1470
               (char*) tbl->file->ref, tbl->file->ref_length);
1430
1471
        field_num++;
1431
1472
      } while ((tbl= tbl_it++));
1432
1473
 
1446
1487
                                         error, 1))
1447
1488
        {
1448
1489
          do_update=0;
1449
 
          return(1);                    // Not a table_is_full error
 
1490
          DBUG_RETURN(1);                       // Not a table_is_full error
1450
1491
        }
1451
1492
        found++;
1452
1493
      }
1453
1494
    }
1454
1495
  }
1455
 
  return(0);
 
1496
  DBUG_RETURN(0);
1456
1497
}
1457
1498
 
1458
1499
 
1459
 
void multi_update::send_error(uint32_t errcode,const char *err)
 
1500
void multi_update::send_error(uint errcode,const char *err)
1460
1501
{
1461
1502
  /* First send error what ever it is ... */
1462
1503
  my_error(errcode, MYF(0), err);
1476
1517
 
1477
1518
  if (! trans_safe)
1478
1519
  {
1479
 
    assert(thd->transaction.stmt.modified_non_trans_table);
 
1520
    DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table);
1480
1521
    if (do_update && table_count > 1)
1481
1522
    {
1482
1523
      /* Add warning here */
1484
1525
         todo/fixme: do_update() is never called with the arg 1.
1485
1526
         should it change the signature to become argless?
1486
1527
      */
1487
 
      do_updates();
 
1528
      VOID(do_updates());
1488
1529
    }
1489
1530
  }
1490
1531
  if (thd->transaction.stmt.modified_non_trans_table)
1502
1543
      */
1503
1544
      thd->binlog_query(THD::ROW_QUERY_TYPE,
1504
1545
                        thd->query, thd->query_length,
1505
 
                        transactional_tables, false);
 
1546
                        transactional_tables, FALSE);
1506
1547
    }
1507
 
    thd->transaction.all.modified_non_trans_table= true;
 
1548
    thd->transaction.all.modified_non_trans_table= TRUE;
1508
1549
  }
1509
 
  assert(trans_safe || !updated || thd->transaction.stmt.modified_non_trans_table);
 
1550
  DBUG_ASSERT(trans_safe || !updated || thd->transaction.stmt.modified_non_trans_table);
1510
1551
}
1511
1552
 
1512
1553
 
1513
1554
int multi_update::do_updates()
1514
1555
{
1515
 
  TableList *cur_table;
 
1556
  TABLE_LIST *cur_table;
1516
1557
  int local_error= 0;
1517
1558
  ha_rows org_updated;
1518
 
  Table *table, *tmp_table;
1519
 
  List_iterator_fast<Table> check_opt_it(unupdated_check_opt_tables);
1520
 
  
 
1559
  TABLE *table, *tmp_table;
 
1560
  List_iterator_fast<TABLE> check_opt_it(unupdated_check_opt_tables);
 
1561
  DBUG_ENTER("multi_update::do_updates");
 
1562
 
1521
1563
  do_update= 0;                                 // Don't retry this function
1522
1564
  if (!found)
1523
 
    return(0);
 
1565
    DBUG_RETURN(0);
1524
1566
  for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
1525
1567
  {
1526
1568
    bool can_compare_record;
1527
 
    uint32_t offset= cur_table->shared;
 
1569
    uint offset= cur_table->shared;
1528
1570
 
1529
1571
    table = cur_table->table;
1530
1572
    if (table == table_to_update)
1536
1578
    table->file->extra(HA_EXTRA_NO_CACHE);
1537
1579
 
1538
1580
    check_opt_it.rewind();
1539
 
    while(Table *tbl= check_opt_it++)
 
1581
    while(TABLE *tbl= check_opt_it++)
1540
1582
    {
1541
1583
      if (tbl->file->ha_rnd_init(1))
1542
1584
        goto err;
1580
1622
 
1581
1623
      /* call rnd_pos() using rowids from temporary table */
1582
1624
      check_opt_it.rewind();
1583
 
      Table *tbl= table;
1584
 
      uint32_t field_num= 0;
 
1625
      TABLE *tbl= table;
 
1626
      uint field_num= 0;
1585
1627
      do
1586
1628
      {
1587
1629
        if((local_error=
1588
1630
              tbl->file->rnd_pos(tbl->record[0],
1589
 
                                (unsigned char *) tmp_table->field[field_num]->ptr)))
 
1631
                                (uchar *) tmp_table->field[field_num]->ptr)))
1590
1632
          goto err;
1591
1633
        field_num++;
1592
1634
      } while((tbl= check_opt_it++));
1600
1642
           copy_field_ptr++)
1601
1643
        (*copy_field_ptr->do_copy)(copy_field_ptr);
1602
1644
 
1603
 
      if (!can_compare_record || table->compare_record())
 
1645
      if (!can_compare_record || compare_record(table))
1604
1646
      {
1605
1647
        if ((local_error=table->file->ha_update_row(table->record[1],
1606
1648
                                                    table->record[0])) &&
1624
1666
      else
1625
1667
      {
1626
1668
        trans_safe= 0;                          // Can't do safe rollback
1627
 
        thd->transaction.stmt.modified_non_trans_table= true;
 
1669
        thd->transaction.stmt.modified_non_trans_table= TRUE;
1628
1670
      }
1629
1671
    }
1630
1672
    (void) table->file->ha_rnd_end();
1631
1673
    (void) tmp_table->file->ha_rnd_end();
1632
1674
    check_opt_it.rewind();
1633
 
    while (Table *tbl= check_opt_it++)
 
1675
    while (TABLE *tbl= check_opt_it++)
1634
1676
        tbl->file->ha_rnd_end();
1635
1677
 
1636
1678
  }
1637
 
  return(0);
 
1679
  DBUG_RETURN(0);
1638
1680
 
1639
1681
err:
1640
1682
  {
1645
1687
  (void) table->file->ha_rnd_end();
1646
1688
  (void) tmp_table->file->ha_rnd_end();
1647
1689
  check_opt_it.rewind();
1648
 
  while (Table *tbl= check_opt_it++)
 
1690
  while (TABLE *tbl= check_opt_it++)
1649
1691
      tbl->file->ha_rnd_end();
1650
1692
 
1651
1693
  if (updated != org_updated)
1655
1697
    else
1656
1698
    {
1657
1699
      trans_safe= 0;
1658
 
      thd->transaction.stmt.modified_non_trans_table= true;
 
1700
      thd->transaction.stmt.modified_non_trans_table= TRUE;
1659
1701
    }
1660
1702
  }
1661
 
  return(1);
 
1703
  DBUG_RETURN(1);
1662
1704
}
1663
1705
 
1664
1706
 
1667
1709
bool multi_update::send_eof()
1668
1710
{
1669
1711
  char buff[STRING_BUFFER_USUAL_SIZE];
1670
 
  uint64_t id;
 
1712
  ulonglong id;
1671
1713
  THD::killed_state killed_status= THD::NOT_KILLED;
1672
 
  
1673
 
  thd->set_proc_info("updating reference tables");
 
1714
  DBUG_ENTER("multi_update::send_eof");
 
1715
  thd_proc_info(thd, "updating reference tables");
1674
1716
 
1675
1717
  /* 
1676
1718
     Does updates for the last n - 1 tables, returns 0 if ok;
1682
1724
    later carried out killing should not affect binlogging.
1683
1725
  */
1684
1726
  killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed;
1685
 
  thd->set_proc_info("end");
 
1727
  thd_proc_info(thd, "end");
1686
1728
 
1687
1729
  /*
1688
1730
    Write the SQL statement to the binlog if we updated
1693
1735
    either from the query's list or via a stored routine: bug#13270,23333
1694
1736
  */
1695
1737
 
1696
 
  assert(trans_safe || !updated || 
 
1738
  DBUG_ASSERT(trans_safe || !updated || 
1697
1739
              thd->transaction.stmt.modified_non_trans_table);
1698
1740
  if (local_error == 0 || thd->transaction.stmt.modified_non_trans_table)
1699
1741
  {
1703
1745
        thd->clear_error();
1704
1746
      if (thd->binlog_query(THD::ROW_QUERY_TYPE,
1705
1747
                            thd->query, thd->query_length,
1706
 
                            transactional_tables, false, killed_status) &&
 
1748
                            transactional_tables, FALSE, killed_status) &&
1707
1749
          trans_safe)
1708
1750
      {
1709
 
        local_error= 1;                         // Rollback update
 
1751
        local_error= 1;                         // Rollback update
1710
1752
      }
1711
1753
    }
1712
1754
    if (thd->transaction.stmt.modified_non_trans_table)
1713
 
      thd->transaction.all.modified_non_trans_table= true;
 
1755
      thd->transaction.all.modified_non_trans_table= TRUE;
1714
1756
  }
1715
1757
  if (local_error != 0)
1716
 
    error_handled= true; // to force early leave from ::send_error()
 
1758
    error_handled= TRUE; // to force early leave from ::send_error()
1717
1759
 
1718
1760
  if (local_error > 0) // if the above log write did not fail ...
1719
1761
  {
1720
1762
    /* Safety: If we haven't got an error before (can happen in do_updates) */
1721
1763
    my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update",
1722
1764
               MYF(0));
1723
 
    return(true);
 
1765
    DBUG_RETURN(TRUE);
1724
1766
  }
1725
1767
 
1726
1768
  id= thd->arg_of_last_insert_id_function ?
1730
1772
  thd->row_count_func=
1731
1773
    (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
1732
1774
  ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
1733
 
  return(false);
 
1775
  DBUG_RETURN(FALSE);
1734
1776
}