summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2023-05-09 21:20:10 -0700
committerIgor Babaev <igor@askmonty.org>2023-05-09 21:20:10 -0700
commit6544d88ff5a7b2ec66153933a3a0531b9091c357 (patch)
tree13fec3186c83ebdc3c9c6497f20d919b831dfb3e
parenta09f661f4392fc9574a5239972243eebc65fe7f2 (diff)
downloadmariadb-git-6544d88ff5a7b2ec66153933a3a0531b9091c357.tar.gz
MDEV-31224 Crash with EXPLAIN EXTENDED for multi-table update of system table
EXPLAIN EXTENDED should always print the field item used in the left part of an equality expression from the SET clause of an update statement as a reference to table column. Approved by Oleksandr Byelkin <sanja@mariadb.com>
-rw-r--r--mysql-test/main/explain_non_select.result18
-rw-r--r--mysql-test/main/explain_non_select.test19
-rw-r--r--mysql-test/main/myisam_explain_non_select_all.result4
-rw-r--r--sql/sql_select.cc2
4 files changed, 40 insertions, 3 deletions
diff --git a/mysql-test/main/explain_non_select.result b/mysql-test/main/explain_non_select.result
index d7ed3992572..009a568e2c2 100644
--- a/mysql-test/main/explain_non_select.result
+++ b/mysql-test/main/explain_non_select.result
@@ -308,4 +308,22 @@ select * from t1;
a
4
drop table t1,t2,t3;
+#
+# MDEV-31224: EXPLAIN EXTENDED for multi-table update of system table
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3);
+EXPLAIN EXTENDED UPDATE t1, t2 SET b = 4 WHERE a IN (6,2);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t2`.`b` = 4 where `test`.`t1`.`a` in (6,2)
+UPDATE t1, t2 SET b = 4 WHERE a IN (6,2);
+SELECT * from t2;
+b
+4
+DROP TABLE t1, t2;
# End of 10.4 tests
diff --git a/mysql-test/main/explain_non_select.test b/mysql-test/main/explain_non_select.test
index c0c543ad273..e861955b3f1 100644
--- a/mysql-test/main/explain_non_select.test
+++ b/mysql-test/main/explain_non_select.test
@@ -277,4 +277,23 @@ select * from t1;
drop table t1,t2,t3;
+--echo #
+--echo # MDEV-31224: EXPLAIN EXTENDED for multi-table update of system table
+--echo #
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3);
+
+let $q=
+UPDATE t1, t2 SET b = 4 WHERE a IN (6,2);
+
+eval EXPLAIN EXTENDED $q;
+eval $q;
+SELECT * from t2;
+
+DROP TABLE t1, t2;
+
--echo # End of 10.4 tests
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 3ca9629d027..b515cb4fd83 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -2689,7 +2689,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
Warnings:
-Note 1003 update `test`.`t1` set NULL = 10
+Note 1003 update `test`.`t1` set `test`.`t2`.`c2` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2734,7 +2734,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
-Note 1003 update `test`.`t1` set NULL = 10 where `test`.`t1`.`c3` = 10
+Note 1003 update `test`.`t1` set `test`.`t2`.`c2` = 10 where `test`.`t1`.`c3` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2be1fea9b03..a5d6ca05a1e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -28169,7 +28169,7 @@ void st_select_lex::print_set_clause(THD *thd, String *str,
else
str->append(',');
- item->print(str, query_type);
+ item->print(str, (enum_query_type) (query_type | QT_NO_DATA_EXPANSION));
str->append(STRING_WITH_LEN(" = "));
val->print(str, query_type);
}