591
731
Item **conds, uint32_t order_num, order_st *order)
593
733
List<Item> all_fields;
594
Select_Lex *select_lex= &session->lex->select_lex;
734
SELECT_LEX *select_lex= &session->lex->select_lex;
737
Statement-based replication of UPDATE ... LIMIT is not safe as order of
738
rows is not defined, so in mixed mode we go to row-based.
740
Note that we may consider a statement as safe if order_st BY primary_key
741
is present. However it may confuse users to see very similiar statements
742
replicated differently.
744
if (session->lex->current_select->select_limit)
746
session->lex->set_stmt_unsafe();
747
session->set_current_stmt_binlog_row_based();
596
750
session->lex->allow_sum_func= 0;
598
if (setup_tables_and_check_access(session, &select_lex->context,
752
if (setup_tables_and_check_access(session, &select_lex->context,
599
753
&select_lex->top_join_list,
601
755
&select_lex->leaf_tables,
603
session->setup_conds(table_list, conds) ||
757
setup_conds(session, table_list, select_lex->leaf_tables, conds) ||
604
758
select_lex->setup_ref_array(session, order_num) ||
605
759
setup_order(session, select_lex->ref_pointer_array,
606
760
table_list, all_fields, all_fields, order))
609
763
/* Check that we are not using table that we are updating in a sub select */
611
765
TableList *duplicate;
612
if ((duplicate= unique_table(table_list, table_list->next_global)))
766
if ((duplicate= unique_table(session, table_list, table_list->next_global, 0)))
768
update_non_unique_table_error(table_list, "UPDATE", duplicate);
614
769
my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
778
/***************************************************************************
779
Update multiple tables from join
780
***************************************************************************/
783
Get table map for list of Item_field
786
static table_map get_table_map(List<Item> *items)
788
List_iterator_fast<Item> item_it(*items);
792
while ((item= (Item_field *) item_it++))
793
map|= item->used_tables();
799
make update specific preparation and checks after opening tables
802
mysql_multi_update_prepare()
803
session thread handler
810
int mysql_multi_update_prepare(Session *session)
812
LEX *lex= session->lex;
813
TableList *table_list= lex->query_tables;
814
TableList *tl, *leaves;
815
List<Item> *fields= &lex->select_lex.item_list;
816
table_map tables_for_update;
819
if this multi-update was converted from usual update, here is table
820
counter else junk will be assigned here, but then replaced with real
821
count in open_tables()
823
uint32_t table_count= lex->table_count;
824
const bool using_lock_tables= session->locked_tables != 0;
825
bool original_multiupdate= (session->lex->sql_command == SQLCOM_UPDATE_MULTI);
826
bool need_reopen= false;
829
/* following need for prepared statements, to run next time multi-update */
830
session->lex->sql_command= SQLCOM_UPDATE_MULTI;
834
/* open tables and create derived ones, but do not lock and fill them */
835
if (((original_multiupdate || need_reopen) &&
836
open_tables(session, &table_list, &table_count, 0)) ||
837
mysql_handle_derived(lex, &mysql_derived_prepare))
840
setup_tables() need for VIEWs. JOIN::prepare() will call setup_tables()
841
second time, but this call will do nothing (there are check for second
842
call in setup_tables()).
845
if (setup_tables_and_check_access(session, &lex->select_lex.context,
846
&lex->select_lex.top_join_list,
848
&lex->select_lex.leaf_tables, false))
851
if (setup_fields_with_no_wrap(session, 0, *fields, MARK_COLUMNS_WRITE, 0, 0))
854
if (update_view && check_fields(session, *fields))
859
tables_for_update= get_table_map(fields);
862
Setup timestamp handling and locking mode
864
leaves= lex->select_lex.leaf_tables;
865
for (tl= leaves; tl; tl= tl->next_leaf)
867
Table *table= tl->table;
868
/* Only set timestamp column if this is not modified */
869
if (table->timestamp_field &&
870
bitmap_is_set(table->write_set,
871
table->timestamp_field->field_index))
872
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
874
/* if table will be updated then check that it is unique */
875
if (table->map & tables_for_update)
877
table->mark_columns_needed_for_update();
879
If table will be updated we should not downgrade lock for it and
886
If we are using the binary log, we need TL_READ_NO_INSERT to get
887
correct order of statements. Otherwise, we use a TL_READ lock to
890
tl->lock_type= using_update_log ? TL_READ_NO_INSERT : TL_READ;
892
/* Update Table::lock_type accordingly. */
893
if (!tl->placeholder() && !using_lock_tables)
894
tl->table->reginfo.lock_type= tl->lock_type;
898
/* now lock and fill tables */
899
if (lock_tables(session, table_list, table_count, &need_reopen))
905
We have to reopen tables since some of them were altered or dropped
906
during lock_tables() or something was done with their triggers.
907
Let us do some cleanups to be able do setup_table() and setup_fields()
910
List_iterator_fast<Item> it(*fields);
915
/* We have to cleanup translation tables of views. */
916
for (TableList *tbl= table_list; tbl; tbl= tbl->next_global)
917
tbl->cleanup_items();
919
close_tables_for_reopen(session, &table_list);
924
Check that we are not using table that we are updating, but we should
925
skip all tables of UPDATE SELECT itself
927
lex->select_lex.exclude_from_table_unique_test= true;
928
/* We only need SELECT privilege for columns in the values list */
929
for (tl= leaves; tl; tl= tl->next_leaf)
931
if (tl->lock_type != TL_READ &&
932
tl->lock_type != TL_READ_NO_INSERT)
934
TableList *duplicate;
935
if ((duplicate= unique_table(session, tl, table_list, 0)))
937
update_non_unique_table_error(table_list, "UPDATE", duplicate);
943
Set exclude_from_table_unique_test value back to false. It is needed for
944
further check in multi_update::prepare whether to use record cache.
946
lex->select_lex.exclude_from_table_unique_test= false;
948
if (session->fill_derived_tables() &&
949
mysql_handle_derived(lex, &mysql_derived_filling))
957
Setup multi-update handling and call SELECT to do the join
960
bool mysql_multi_update(Session *session,
961
TableList *table_list,
966
enum enum_duplicates handle_duplicates, bool ignore,
967
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
969
multi_update *result;
972
if (!(result= new multi_update(table_list,
973
session->lex->select_lex.leaf_tables,
975
handle_duplicates, ignore)))
978
session->abort_on_warning= true;
980
List<Item> total_list;
981
res= mysql_select(session, &select_lex->ref_pointer_array,
982
table_list, select_lex->with_wild,
984
conds, 0, (order_st *) NULL, (order_st *)NULL, (Item *) NULL,
986
options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
987
OPTION_SETUP_TABLES_DONE,
988
result, unit, select_lex);
989
res|= session->is_error();
992
/* If we had a another error reported earlier then this will be ignored */
993
result->send_error(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR));
997
session->abort_on_warning= 0;
1002
multi_update::multi_update(TableList *table_list,
1003
TableList *leaves_list,
1004
List<Item> *field_list, List<Item> *value_list,
1005
enum enum_duplicates handle_duplicates_arg,
1007
:all_tables(table_list), leaves(leaves_list), update_tables(0),
1008
tmp_tables(0), updated(0), found(0), fields(field_list),
1009
values(value_list), table_count(0), copy_field(0),
1010
handle_duplicates(handle_duplicates_arg), do_update(1), trans_safe(1),
1011
transactional_tables(0), ignore(ignore_arg), error_handled(0)
1016
Connect fields with tables and create list of tables that are updated
1019
int multi_update::prepare(List<Item> &,
1022
TableList *table_ref;
1024
table_map tables_to_update;
1026
List_iterator_fast<Item> field_it(*fields);
1027
List_iterator_fast<Item> value_it(*values);
1028
uint32_t i, max_fields;
1029
uint32_t leaf_table_count= 0;
1031
session->count_cuted_fields= CHECK_FIELD_WARN;
1032
session->cuted_fields=0L;
1033
session->set_proc_info("updating main table");
1035
tables_to_update= get_table_map(fields);
1037
if (!tables_to_update)
1039
my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
1044
We have to check values after setup_tables to get covering_keys right in
1048
if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
1052
Save tables beeing updated in update_tables
1053
update_table->shared is position for table
1054
Don't use key read on tables that are updated
1058
for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
1060
/* TODO: add support of view of join support */
1061
Table *table=table_ref->table;
1063
if (tables_to_update & table->map)
1065
TableList *tl= (TableList*) session->memdup((char*) table_ref,
1069
update.link_in_list((unsigned char*) tl, (unsigned char**) &tl->next_local);
1070
tl->shared= table_count++;
1071
table->no_keyread=1;
1072
table->covering_keys.clear_all();
1073
table->pos_in_table_list= tl;
1078
table_count= update.elements;
1079
update_tables= (TableList*) update.first;
1081
tmp_tables = (Table**) session->calloc(sizeof(Table *) * table_count);
1082
tmp_table_param = (TMP_TABLE_PARAM*) session->calloc(sizeof(TMP_TABLE_PARAM) *
1084
fields_for_table= (List_item **) session->alloc(sizeof(List_item *) *
1086
values_for_table= (List_item **) session->alloc(sizeof(List_item *) *
1088
if (session->is_fatal_error)
1090
for (i=0 ; i < table_count ; i++)
1092
fields_for_table[i]= new List_item;
1093
values_for_table[i]= new List_item;
1095
if (session->is_fatal_error)
1098
/* Split fields into fields_for_table[] and values_by_table[] */
1100
while ((item= (Item_field *) field_it++))
1102
Item *value= value_it++;
1103
uint32_t offset= item->field->table->pos_in_table_list->shared;
1104
fields_for_table[offset]->push_back(item);
1105
values_for_table[offset]->push_back(value);
1107
if (session->is_fatal_error)
1110
/* Allocate copy fields */
1112
for (i=0 ; i < table_count ; i++)
1113
set_if_bigger(max_fields, fields_for_table[i]->elements + leaf_table_count);
1114
copy_field= new Copy_field[max_fields];
1115
return(session->is_fatal_error != 0);
1120
Check if table is safe to update on fly
1123
safe_update_on_fly()
1124
session Thread handler
1125
join_tab How table is used in join
1126
all_tables List of tables
1129
We can update the first table in join on the fly if we know that
1130
a row in this table will never be read twice. This is true under
1131
the following conditions:
1133
- We are doing a table scan and the data is in a separate file (MyISAM) or
1134
if we don't update a clustered key.
1136
- We are doing a range scan and we don't update the scan key or
1137
the primary key for a clustered table handler.
1139
- Table is not joined to itself.
1141
This function gets information about fields to be updated from
1142
the Table::write_set bitmap.
1145
This code is a bit dependent of how make_join_readinfo() works.
1148
0 Not safe to update
1152
static bool safe_update_on_fly(Session *session, JOIN_TAB *join_tab,
1153
TableList *table_ref, TableList *all_tables)
1155
Table *table= join_tab->table;
1156
if (unique_table(session, table_ref, all_tables, 0))
1158
switch (join_tab->type) {
1162
return true; // At most one matching row
1164
case JT_REF_OR_NULL:
1165
return !is_key_used(table, join_tab->ref.key, table->write_set);
1167
/* If range search on index */
1168
if (join_tab->quick)
1169
return !join_tab->quick->is_keys_used(table->write_set);
1170
/* If scanning in clustered key */
1171
if ((table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1172
table->s->primary_key < MAX_KEY)
1173
return !is_key_used(table, table->s->primary_key, table->write_set);
1176
break; // Avoid compler warning
622
} /* namespace drizzled */
1184
Initialize table for multi table
1187
- Update first table in join on the fly, if possible
1188
- Create temporary tables to store changed values for all other tables
1189
that are updated (and main_table if the above doesn't hold).
1193
multi_update::initialize_tables(JOIN *join)
1195
TableList *table_ref;
1197
if ((session->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
1199
main_table=join->join_tab->table;
1202
/* Any update has at least one pair (field, value) */
1203
assert(fields->elements);
1205
/* Create a temporary table for keys to all tables, except main table */
1206
for (table_ref= update_tables; table_ref; table_ref= table_ref->next_local)
1208
Table *table=table_ref->table;
1209
uint32_t cnt= table_ref->shared;
1210
List<Item> temp_fields;
1212
TMP_TABLE_PARAM *tmp_param;
1214
table->mark_columns_needed_for_update();
1216
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
1217
if (table == main_table) // First table in join
1219
if (safe_update_on_fly(session, join->join_tab, table_ref, all_tables))
1221
table_to_update= main_table; // Update table on the fly
1225
table->prepare_for_position();
1227
tmp_param= tmp_table_param+cnt;
1230
Create a temporary table to store all fields that are changed for this
1231
table. The first field in the temporary table is a pointer to the
1232
original row so that we can find and update it. For the updatable
1233
VIEW a few following fields are rowids of tables used in the CHECK
1237
List_iterator_fast<Table> tbl_it(unupdated_check_opt_tables);
1241
Field_string *field= new Field_string(tbl->file->ref_length, 0,
1242
tbl->alias, &my_charset_bin);
1244
Field_varstring *field= new Field_varstring(tbl->file->ref_length, 0,
1245
tbl->alias, tbl->s, &my_charset_bin);
1251
The field will be converted to varstring when creating tmp table if
1252
table to be updated was created by mysql 4.1. Deny this.
1254
Item_field *ifield= new Item_field((Field *) field);
1257
ifield->maybe_null= 0;
1258
if (temp_fields.push_back(ifield))
1260
} while ((tbl= tbl_it++));
1262
temp_fields.concat(fields_for_table[cnt]);
1264
/* Make an unique key over the first field to avoid duplicated updates */
1265
memset(&group, 0, sizeof(group));
1267
group.item= (Item**) temp_fields.head_ref();
1269
tmp_param->quick_group=1;
1270
tmp_param->field_count=temp_fields.elements;
1271
tmp_param->group_parts=1;
1272
tmp_param->group_length= table->file->ref_length;
1273
if (!(tmp_tables[cnt]=create_tmp_table(session,
1276
(order_st*) &group, 0, 0,
1277
TMP_TABLE_ALL_COLUMNS,
1281
tmp_tables[cnt]->file->extra(HA_EXTRA_WRITE_CACHE);
1287
multi_update::~multi_update()
1290
for (table= update_tables ; table; table= table->next_local)
1292
table->table->no_keyread= table->table->no_cache= 0;
1294
table->table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1299
for (uint32_t cnt = 0; cnt < table_count; cnt++)
1301
if (tmp_tables[cnt])
1303
tmp_tables[cnt]->free_tmp_table(session);
1304
tmp_table_param[cnt].cleanup();
1309
delete [] copy_field;
1310
session->count_cuted_fields= CHECK_FIELD_IGNORE; // Restore this setting
1311
assert(trans_safe || !updated ||
1312
session->transaction.all.modified_non_trans_table);
1316
bool multi_update::send_data(List<Item> &)
1318
TableList *cur_table;
1320
for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
1322
Table *table= cur_table->table;
1323
uint32_t offset= cur_table->shared;
1325
Check if we are using outer join and we didn't find the row
1326
or if we have already updated this row in the previous call to this
1329
The same row may be presented here several times in a join of type
1330
UPDATE t1 FROM t1,t2 SET t1.a=t2.a
1332
In this case we will do the update for the first found row combination.
1333
The join algorithm guarantees that we will not find the a row in
1336
if (table->status & (STATUS_NULL_ROW | STATUS_UPDATED))
1340
We can use compare_record() to optimize away updates if
1341
the table handler is returning all columns OR if
1342
if all updated columns are read
1344
if (table == table_to_update)
1346
bool can_compare_record;
1347
can_compare_record= (!(table->file->ha_table_flags() &
1348
HA_PARTIAL_COLUMN_READ) ||
1349
bitmap_is_subset(table->write_set,
1351
table->status|= STATUS_UPDATED;
1352
store_record(table,record[1]);
1353
if (fill_record(session, *fields_for_table[offset],
1354
*values_for_table[offset], 0))
1358
if (!can_compare_record || table->compare_record())
1364
Inform the main table that we are going to update the table even
1365
while we may be scanning it. This will flush the read cache
1368
main_table->file->extra(HA_EXTRA_PREPARE_FOR_UPDATE);
1370
if ((error=table->file->ha_update_row(table->record[1],
1371
table->record[0])) &&
1372
error != HA_ERR_RECORD_IS_THE_SAME)
1376
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
1379
If (ignore && error == is ignorable) we don't have to
1380
do anything; otherwise...
1384
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
1385
flags|= ME_FATALERROR; /* Other handler errors are fatal */
1387
prepare_record_for_error_message(error, table);
1388
table->file->print_error(error,MYF(flags));
1394
if (error == HA_ERR_RECORD_IS_THE_SAME)
1399
/* non-transactional or transactional table got modified */
1400
/* either multi_update class' flag is raised in its branch */
1401
if (table->file->has_transactions())
1402
transactional_tables= 1;
1406
session->transaction.stmt.modified_non_trans_table= true;
1414
Table *tmp_table= tmp_tables[offset];
1416
For updatable VIEW store rowid of the updated table and
1417
rowids of tables used in the CHECK OPTION condition.
1419
uint32_t field_num= 0;
1420
List_iterator_fast<Table> tbl_it(unupdated_check_opt_tables);
1424
tbl->file->position(tbl->record[0]);
1425
memcpy(tmp_table->field[field_num]->ptr,
1426
tbl->file->ref, tbl->file->ref_length);
1428
} while ((tbl= tbl_it++));
1430
/* Store regular updated fields in the row. */
1431
fill_record(session,
1432
tmp_table->field + 1 + unupdated_check_opt_tables.elements,
1433
*values_for_table[offset], 1);
1435
/* Write row, ignoring duplicated updates to a row */
1436
error= tmp_table->file->ha_write_row(tmp_table->record[0]);
1437
if (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)
1440
create_myisam_from_heap(session, tmp_table,
1441
tmp_table_param[offset].start_recinfo,
1442
&tmp_table_param[offset].recinfo,
1446
return(1); // Not a table_is_full error
1456
void multi_update::send_error(uint32_t errcode,const char *err)
1458
/* First send error what ever it is ... */
1459
my_error(errcode, MYF(0), err);
1463
void multi_update::abort()
1465
/* the error was handled or nothing deleted and no side effects return */
1466
if (error_handled ||
1467
(!session->transaction.stmt.modified_non_trans_table && !updated))
1470
If all tables that has been updated are trans safe then just do rollback.
1471
If not attempt to do remaining updates.
1476
assert(session->transaction.stmt.modified_non_trans_table);
1477
if (do_update && table_count > 1)
1479
/* Add warning here */
1481
todo/fixme: do_update() is never called with the arg 1.
1482
should it change the signature to become argless?
1487
if (session->transaction.stmt.modified_non_trans_table)
1490
The query has to binlog because there's a modified non-transactional table
1491
either from the query's list or via a stored routine: bug#13270,23333
1493
if (mysql_bin_log.is_open())
1496
Session::killed status might not have been set ON at time of an error
1497
got caught and if happens later the killed error is written
1500
session->binlog_query(Session::ROW_QUERY_TYPE,
1501
session->query, session->query_length,
1502
transactional_tables, false);
1504
session->transaction.all.modified_non_trans_table= true;
1506
assert(trans_safe || !updated || session->transaction.stmt.modified_non_trans_table);
1510
int multi_update::do_updates()
1512
TableList *cur_table;
1514
ha_rows org_updated;
1515
Table *table, *tmp_table;
1516
List_iterator_fast<Table> check_opt_it(unupdated_check_opt_tables);
1518
do_update= 0; // Don't retry this function
1521
for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
1523
bool can_compare_record;
1524
uint32_t offset= cur_table->shared;
1526
table = cur_table->table;
1527
if (table == table_to_update)
1528
continue; // Already updated
1529
org_updated= updated;
1530
tmp_table= tmp_tables[cur_table->shared];
1531
tmp_table->file->extra(HA_EXTRA_CACHE); // Change to read cache
1532
(void) table->file->ha_rnd_init(0);
1533
table->file->extra(HA_EXTRA_NO_CACHE);
1535
check_opt_it.rewind();
1536
while(Table *tbl= check_opt_it++)
1538
if (tbl->file->ha_rnd_init(1))
1540
tbl->file->extra(HA_EXTRA_CACHE);
1544
Setup copy functions to copy fields from temporary table
1546
List_iterator_fast<Item> field_it(*fields_for_table[offset]);
1547
Field **field= tmp_table->field +
1548
1 + unupdated_check_opt_tables.elements; // Skip row pointers
1549
Copy_field *copy_field_ptr= copy_field, *copy_field_end;
1550
for ( ; *field ; field++)
1552
Item_field *item= (Item_field* ) field_it++;
1553
(copy_field_ptr++)->set(item->field, *field, 0);
1555
copy_field_end=copy_field_ptr;
1557
if ((local_error = tmp_table->file->ha_rnd_init(1)))
1560
can_compare_record= (!(table->file->ha_table_flags() &
1561
HA_PARTIAL_COLUMN_READ) ||
1562
bitmap_is_subset(table->write_set,
1567
if (session->killed && trans_safe)
1569
if ((local_error=tmp_table->file->rnd_next(tmp_table->record[0])))
1571
if (local_error == HA_ERR_END_OF_FILE)
1573
if (local_error == HA_ERR_RECORD_DELETED)
1574
continue; // May happen on dup key
1578
/* call rnd_pos() using rowids from temporary table */
1579
check_opt_it.rewind();
1581
uint32_t field_num= 0;
1585
tbl->file->rnd_pos(tbl->record[0],
1586
(unsigned char *) tmp_table->field[field_num]->ptr)))
1589
} while((tbl= check_opt_it++));
1591
table->status|= STATUS_UPDATED;
1592
store_record(table,record[1]);
1594
/* Copy data from temporary table to current table */
1595
for (copy_field_ptr=copy_field;
1596
copy_field_ptr != copy_field_end;
1598
(*copy_field_ptr->do_copy)(copy_field_ptr);
1600
if (!can_compare_record || table->compare_record())
1602
if ((local_error=table->file->ha_update_row(table->record[1],
1603
table->record[0])) &&
1604
local_error != HA_ERR_RECORD_IS_THE_SAME)
1607
table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY))
1610
if (local_error != HA_ERR_RECORD_IS_THE_SAME)
1617
if (updated != org_updated)
1619
if (table->file->has_transactions())
1620
transactional_tables= 1;
1623
trans_safe= 0; // Can't do safe rollback
1624
session->transaction.stmt.modified_non_trans_table= true;
1627
(void) table->file->ha_rnd_end();
1628
(void) tmp_table->file->ha_rnd_end();
1629
check_opt_it.rewind();
1630
while (Table *tbl= check_opt_it++)
1631
tbl->file->ha_rnd_end();
1638
prepare_record_for_error_message(local_error, table);
1639
table->file->print_error(local_error,MYF(ME_FATALERROR));
1642
(void) table->file->ha_rnd_end();
1643
(void) tmp_table->file->ha_rnd_end();
1644
check_opt_it.rewind();
1645
while (Table *tbl= check_opt_it++)
1646
tbl->file->ha_rnd_end();
1648
if (updated != org_updated)
1650
if (table->file->has_transactions())
1651
transactional_tables= 1;
1655
session->transaction.stmt.modified_non_trans_table= true;
1662
/* out: 1 if error, 0 if success */
1664
bool multi_update::send_eof()
1666
char buff[STRING_BUFFER_USUAL_SIZE];
1668
Session::killed_state killed_status= Session::NOT_KILLED;
1670
session->set_proc_info("updating reference tables");
1673
Does updates for the last n - 1 tables, returns 0 if ok;
1674
error takes into account killed status gained in do_updates()
1676
int local_error = (table_count) ? do_updates() : 0;
1678
if local_error is not set ON until after do_updates() then
1679
later carried out killing should not affect binlogging.
1681
killed_status= (local_error == 0)? Session::NOT_KILLED : session->killed;
1682
session->set_proc_info("end");
1685
Write the SQL statement to the binlog if we updated
1686
rows and we succeeded or if we updated some non
1687
transactional tables.
1689
The query has to binlog because there's a modified non-transactional table
1690
either from the query's list or via a stored routine: bug#13270,23333
1693
assert(trans_safe || !updated ||
1694
session->transaction.stmt.modified_non_trans_table);
1695
if (local_error == 0 || session->transaction.stmt.modified_non_trans_table)
1697
if (mysql_bin_log.is_open())
1699
if (local_error == 0)
1700
session->clear_error();
1701
if (session->binlog_query(Session::ROW_QUERY_TYPE,
1702
session->query, session->query_length,
1703
transactional_tables, false, killed_status) &&
1706
local_error= 1; // Rollback update
1709
if (session->transaction.stmt.modified_non_trans_table)
1710
session->transaction.all.modified_non_trans_table= true;
1712
if (local_error != 0)
1713
error_handled= true; // to force early leave from ::send_error()
1715
if (local_error > 0) // if the above log write did not fail ...
1717
/* Safety: If we haven't got an error before (can happen in do_updates) */
1718
my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update",
1723
id= session->arg_of_last_insert_id_function ?
1724
session->first_successful_insert_id_in_prev_stmt : 0;
1725
sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
1726
(ulong) session->cuted_fields);
1727
session->row_count_func=
1728
(session->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
1729
::my_ok(session, (ulong) session->row_count_func, id, buff);