revision-id: 3615a604f60d19390c5dd22712c77386bc7743dc (mariadb-10.2.23-75-g3615a604f60)
parent(s): 1f1a61cfc41a01ffa65d568eebdc037a54b5c463
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-04-24 16:17:00 +0200
message:
MDEV-16240: Assertion `0' failed in row_sel_convert_mysql_key_to_innobase
Set table in row ID position mode before using this function.
---
mysql-test/r/multi_update_innodb.result | 40 ++++++++++++++++++++++
mysql-test/t/multi_update_innodb.test | 49 +++++++++++++++++++++++++++
sql/handler.cc | 11 ++++--
sql/item_subselect.cc | 9 +++--
sql/item_subselect.h | 2 +-
sql/log_event.cc | 9 +++++
sql/sql_insert.cc | 60 +++++++++++++++++++++++++++------
sql/sql_load.cc | 9 +++++
sql/sql_select.cc | 16 +++++++++
sql/sql_update.cc | 8 +++++
10 files changed, 197 insertions(+), 16 deletions(-)
diff --git a/mysql-test/r/multi_update_innodb.result b/mysql-test/r/multi_update_innodb.result
index 5890fd24f5f..294ebfcebdf 100644
--- a/mysql-test/r/multi_update_innodb.result
+++ b/mysql-test/r/multi_update_innodb.result
@@ -151,3 +151,43 @@ create table t2 like t1;
insert into t2 select * from t1;
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
drop table t1,t2;
+#
+# MDEV-16240: Assertion `0' failed in
+# row_sel_convert_mysql_key_to_innobase
+#
+SET @save_sql_mode=@@sql_mode;
+set sql_mode='';
+CREATE TABLE `t3` (
+`f1` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
+`f2` datetime DEFAULT '2000-01-01 00:00:00' ON UPDATE current_timestamp(),
+`f3` TIMESTAMP NULL DEFAULT '2000-01-01 00:00:00',
+`pk` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+`f4` datetime DEFAULT current_timestamp(),
+PRIMARY KEY (`pk`),
+UNIQUE KEY `f2k` (`f2`),
+KEY `f4k` (`f4`)
+) ENGINE=InnoDB;
+INSERT INTO `t3` VALUES ('2018-05-18 15:08:07','2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00'),('0000-00-00 00:00:00','0000-00-00 00:00:00','1999-12-31 23:00:00','2002-07-03 23:04:40','0000-00-00 00:00:00');
+CREATE VIEW `v1` AS
+SELECT `t3`.`pk` AS `pk`,
+`t3`.`f3` AS `f3`,
+`t3`.`f4` AS `f4`,
+`t3`.`f2` AS `f2`,
+`t3`.`f1` AS `f1`
+FROM `t3`;
+CREATE TABLE `t4` (
+`f1` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+`f3` timestamp NULL DEFAULT NULL,
+`f2` timestamp NULL DEFAULT '1999-12-31 23:00:00' ON UPDATE current_timestamp(),
+`pk` int(11) NOT NULL,
+`f4` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+PRIMARY KEY (`pk`)
+) ENGINE=InnoDB;
+INSERT INTO `t4` VALUES ('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,1,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,3,'2018-05-18 15:08:06'),('0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,1976,'0000-00-00 00:00:00'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2000,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2001,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2002,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2003,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2004,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2005,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2018,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2019,'2018-05-1
8 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2024,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','1999-12-31 23:00:00',2025,'2018-05-18 15:08:06'),('0000-00-00 00:00:00',NULL,'2018-05-18 15:08:06',2026,'2018-05-18 15:08:06'),('2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00',2027,'0000-00-00 00:00:00');
+UPDATE `v1` t1, `t4` t2
+SET t1.`f2` = 6452736 WHERE t1.`f4` = 6272000;
+ERROR 23000: Duplicate entry '0000-00-00 00:00:00' for key 'f2k'
+DROP VIEW v1;
+DROP TABLE t3,t4;
+SET @@sql_mode=@save_sql_mode;
+# End of 10.2 tests
diff --git a/mysql-test/t/multi_update_innodb.test b/mysql-test/t/multi_update_innodb.test
index f5f8f91edb8..2e46ee06d4d 100644
--- a/mysql-test/t/multi_update_innodb.test
+++ b/mysql-test/t/multi_update_innodb.test
@@ -173,3 +173,52 @@ delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
drop table t1,t2;
+--echo #
+--echo # MDEV-16240: Assertion `0' failed in
+--echo # row_sel_convert_mysql_key_to_innobase
+--echo #
+
+SET @save_sql_mode=@@sql_mode;
+set sql_mode='';
+
+CREATE TABLE `t3` (
+ `f1` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
+ `f2` datetime DEFAULT '2000-01-01 00:00:00' ON UPDATE current_timestamp(),
+ `f3` TIMESTAMP NULL DEFAULT '2000-01-01 00:00:00',
+ `pk` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `f4` datetime DEFAULT current_timestamp(),
+ PRIMARY KEY (`pk`),
+ UNIQUE KEY `f2k` (`f2`),
+ KEY `f4k` (`f4`)
+ ) ENGINE=InnoDB;
+
+INSERT INTO `t3` VALUES ('2018-05-18 15:08:07','2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00'),('0000-00-00 00:00:00','0000-00-00 00:00:00','1999-12-31 23:00:00','2002-07-03 23:04:40','0000-00-00 00:00:00');
+
+CREATE VIEW `v1` AS
+SELECT `t3`.`pk` AS `pk`,
+ `t3`.`f3` AS `f3`,
+ `t3`.`f4` AS `f4`,
+ `t3`.`f2` AS `f2`,
+ `t3`.`f1` AS `f1`
+FROM `t3`;
+
+CREATE TABLE `t4` (
+ `f1` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+ `f3` timestamp NULL DEFAULT NULL,
+ `f2` timestamp NULL DEFAULT '1999-12-31 23:00:00' ON UPDATE current_timestamp(),
+ `pk` int(11) NOT NULL,
+ `f4` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+ PRIMARY KEY (`pk`)
+) ENGINE=InnoDB;
+
+INSERT INTO `t4` VALUES ('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,1,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,3,'2018-05-18 15:08:06'),('0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,1976,'0000-00-00 00:00:00'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2000,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2001,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2002,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2003,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2004,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2005,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2018,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2019,'2018-05-1
8 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2024,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','1999-12-31 23:00:00',2025,'2018-05-18 15:08:06'),('0000-00-00 00:00:00',NULL,'2018-05-18 15:08:06',2026,'2018-05-18 15:08:06'),('2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00',2027,'0000-00-00 00:00:00');
+
+--error ER_DUP_ENTRY
+UPDATE `v1` t1, `t4` t2
+SET t1.`f2` = 6452736 WHERE t1.`f4` = 6272000;
+
+DROP VIEW v1;
+DROP TABLE t3,t4;
+SET @@sql_mode=@save_sql_mode;
+
+--echo # End of 10.2 tests
diff --git a/sql/handler.cc b/sql/handler.cc
index ae63640ae5c..ec966389d5d 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2648,8 +2648,7 @@ int handler::ha_rnd_pos(uchar *buf, uchar *pos)
DBUG_ENTER("handler::ha_rnd_pos");
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
- /* TODO: Find out how to solve ha_rnd_pos when finding duplicate update. */
- /* DBUG_ASSERT(inited == RND); */
+ DBUG_ASSERT(inited == RND);
TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
{ result= rnd_pos(buf, pos); })
@@ -3307,6 +3306,10 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
ulonglong nr;
int error;
MY_BITMAP *old_read_set;
+ bool rnd_inited= (inited == RND);
+
+ if (rnd_inited && ha_rnd_end())
+ return;
old_read_set= table->prepare_for_keyread(table->s->next_number_index);
@@ -3316,6 +3319,8 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
DBUG_ASSERT(0);
(void) extra(HA_EXTRA_NO_KEYREAD);
*first_value= ULONGLONG_MAX;
+ if (rnd_inited && ha_rnd_init_with_error(0))
+ DBUG_ASSERT(0);
return;
}
@@ -3362,6 +3367,8 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
ha_index_end();
table->restore_column_maps_after_keyread(old_read_set);
*first_value= nr;
+ if (rnd_inited && ha_rnd_init_with_error(0))
+ DBUG_ASSERT(0);
return;
}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 8a9dd083911..8cff8f3a5c4 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -5855,12 +5855,16 @@ Ordered_key::cmp_keys_by_row_data_and_rownum(Ordered_key *key,
}
-void Ordered_key::sort_keys()
+bool Ordered_key::sort_keys()
{
+ if (tbl->file->ha_rnd_init_with_error(0))
+ return TRUE;
my_qsort2(key_buff, (size_t) key_buff_elements, sizeof(rownum_t),
(qsort2_cmp) &cmp_keys_by_row_data_and_rownum, (void*) this);
/* Invalidate the current row position. */
cur_key_idx= HA_POS_ERROR;
+ tbl->file->ha_rnd_end();
+ return FALSE;
}
@@ -6313,7 +6317,8 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
/* Sort the keys in each of the indexes. */
for (uint i= 0; i < merge_keys_count; i++)
- merge_keys[i]->sort_keys();
+ if (merge_keys[i]->sort_keys())
+ return TRUE;
if (init_queue(&pq, merge_keys_count, 0, FALSE,
subselect_rowid_merge_engine::cmp_keys_by_cur_rownum, NULL,
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index bd6a1bdc498..5366c759795 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -1287,7 +1287,7 @@ class Ordered_key : public Sql_alloc
++cur_key_idx;
}
- void sort_keys();
+ bool sort_keys();
double null_selectivity();
/*
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 8990e1953b6..c17c7ef6e06 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -12845,6 +12845,14 @@ Rows_log_event::write_row(rpl_group_info *rgi,
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
{
DBUG_PRINT("info",("Locating offending record using rnd_pos()"));
+ error= table->file->ha_rnd_init(0);
+ if (error)
+ {
+ DBUG_PRINT("info",("rnd_init() returns error %d",error));
+ table->file->print_error(error, MYF(0));
+ DBUG_RETURN(error);
+ }
+
error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
if (error)
{
@@ -12854,6 +12862,7 @@ Rows_log_event::write_row(rpl_group_info *rgi,
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
+ table->file->ha_rnd_end();
}
else
{
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index c623336fdba..4005153cb64 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -881,7 +881,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
#endif /* EMBEDDED_LIBRARY */
{
if (duplic != DUP_ERROR || ignore)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ goto abort;
+ }
/**
This is a simple check for the case when the table has a trigger
that reads from it, or when the statement invokes a stored function
@@ -942,7 +947,10 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
{
DBUG_PRINT("info", ("iteration %llu", iteration));
if (iteration && bulk_parameters_set(thd))
- goto abort;
+ {
+ error= 1;
+ goto values_loop_end;
+ }
while ((values= its++))
{
@@ -1094,7 +1102,11 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
error=1;
}
if (duplic != DUP_ERROR || ignore)
+ {
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table->file->ha_rnd_end();
+ }
transactional_table= table->file->has_transactions();
@@ -1705,6 +1717,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
goto err;
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
{
+ DBUG_ASSERT(table->file->inited == handler::RND);
if (table->file->ha_rnd_pos(table->record[1],table->file->dup_ref))
goto err;
}
@@ -3177,6 +3190,9 @@ bool Delayed_insert::handle_inserts(void)
max_rows= ULONG_MAX; // Do as much as possible
}
+ if (table->file->ha_rnd_init_with_error(0))
+ goto err;
+
/*
We can't use row caching when using the binary log because if
we get a crash, then binary log will contain rows that are not yet
@@ -3352,6 +3368,8 @@ bool Delayed_insert::handle_inserts(void)
}
}
+ table->file->ha_rnd_end();
+
if (WSREP((&thd)))
thd_proc_info(&thd, "insert done");
else
@@ -3649,7 +3667,12 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ DBUG_RETURN(1);
+ }
if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
@@ -3818,6 +3841,9 @@ bool select_insert::prepare_eof()
if (!error && thd->is_error())
error= thd->get_stmt_da()->sql_errno();
+ if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table->file->ha_rnd_end();
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
@@ -3929,6 +3955,11 @@ void select_insert::abort_result_set() {
if (thd->locked_tables_mode <= LTM_LOCK_TABLES)
table->file->ha_end_bulk_insert();
+ if (table->file->inited)
+ table->file->ha_rnd_end();
+ table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
+
/*
If at least one row has been inserted/modified and will stay in
the table (the table doesn't have transactions) we must write to
@@ -4341,7 +4372,12 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
restore_record(table,s->default_values); // Get empty record
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ DBUG_RETURN(1);
+ }
if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
@@ -4522,9 +4558,6 @@ bool select_create::send_eof()
*/
exit_done= 1; // Avoid double calls
- table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
- table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
-
send_ok_packet();
if (m_plock)
@@ -4600,13 +4633,6 @@ void select_create::abort_result_set()
thd->locked_tables_list.unlock_locked_table(thd,
create_info->mdl_ticket);
}
- if (m_plock)
- {
- mysql_unlock_tables(thd, *m_plock);
- *m_plock= NULL;
- m_plock= NULL;
- }
-
if (table)
{
bool tmp_table= table->s->tmp_table;
@@ -4617,9 +4643,21 @@ void select_create::abort_result_set()
thd->restore_tmp_table_share(saved_tmp_table_share);
}
+ if (table->file->inited &&
+ (info.ignore || info.handle_duplicates != DUP_ERROR) &&
+ (table->file->ha_table_flags() & HA_DUPLICATE_POS))
+ table->file->ha_rnd_end();
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
table->auto_increment_field_not_null= FALSE;
+
+ if (m_plock)
+ {
+ mysql_unlock_tables(thd, *m_plock);
+ *m_plock= NULL;
+ m_plock= NULL;
+ }
+
drop_open_table(thd, table, create_table->db, create_table->table_name);
table=0; // Safety
if (thd->log_current_statement && mysql_bin_log.is_open())
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 49558f8b694..8994b436cab 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -660,6 +660,12 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
thd->abort_on_warning= !ignore && thd->is_strict_mode();
+ if ((table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS) &&
+ (error= table_list->table->file->ha_rnd_init(0)))
+ {
+ table->file->print_error(error, MYF(0));
+ goto err;
+ }
thd_progress_init(thd, 2);
if (table_list->table->validate_default_values_of_unset_fields(thd))
{
@@ -679,6 +685,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
set_fields, set_values, read_info,
*ex->enclosed, skip_lines, ignore);
+ if (table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table_list->table->file->ha_rnd_end();
+
thd_proc_info(thd, "End bulk insert");
if (!error)
thd_progress_next_stage(thd);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 3c1cea6be51..291560dc098 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -20318,6 +20318,15 @@ end_unique_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
table->file->print_error(error,MYF(0)); /* purecov: inspected */
DBUG_RETURN(NESTED_LOOP_ERROR); /* purecov: inspected */
}
+ /* Prepare table for random positioning */
+ bool rnd_inited= (table->file->inited == handler::RND);
+ if (!rnd_inited &&
+ ((error= table->file->ha_index_end()) ||
+ (error= table->file->ha_rnd_init(0))))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_RETURN(NESTED_LOOP_ERROR);
+ }
if (table->file->ha_rnd_pos(table->record[1],table->file->dup_ref))
{
table->file->print_error(error,MYF(0)); /* purecov: inspected */
@@ -20331,6 +20340,13 @@ end_unique_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
table->file->print_error(error,MYF(0)); /* purecov: inspected */
DBUG_RETURN(NESTED_LOOP_ERROR); /* purecov: inspected */
}
+ if (!rnd_inited &&
+ ((error= table->file->ha_rnd_end()) ||
+ (error= table->file->ha_index_init(0, 0))))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_RETURN(NESTED_LOOP_ERROR);
+ }
}
if (join->thd->check_killed())
{
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 11ffa684216..f5284350094 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -211,6 +211,14 @@ static void prepare_record_for_error_message(int error, TABLE *table)
bitmap_union(table->read_set, &unique_map);
/* Tell the engine about the new set. */
table->file->column_bitmaps_signal();
+
+ if ((error= table->file->ha_index_or_rnd_end()) ||
+ (error= table->file->ha_rnd_init(0)))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_VOID_RETURN;
+ }
+
/* Read record that is identified by table->file->ref. */
(void) table->file->ha_rnd_pos(table->record[1], table->file->ref);
/* Copy the newly read columns into the new record. */