Skip to content

Commit

Permalink
MDEV-31224 Crash with EXPLAIN EXTENDED for multi-table update of syst…
Browse files Browse the repository at this point in the history
…em 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>
  • Loading branch information
igorbabaev committed May 10, 2023
1 parent a09f661 commit 6544d88
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
18 changes: 18 additions & 0 deletions mysql-test/main/explain_non_select.result
Expand Up @@ -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
19 changes: 19 additions & 0 deletions mysql-test/main/explain_non_select.test
Expand Up @@ -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
4 changes: 2 additions & 2 deletions mysql-test/main/myisam_explain_non_select_all.result
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_select.cc
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6544d88

Please sign in to comment.