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 authored and vuvova committed Jun 3, 2023
1 parent 54324e5 commit aa713f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
19 changes: 19 additions & 0 deletions mysql-test/main/explain_non_select.result
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,22 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
drop table t1,t2;
#
# 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
20 changes: 20 additions & 0 deletions mysql-test/main/explain_non_select.test
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,23 @@ PREPARE stmt FROM 'EXPLAIN INSERT INTO t1 SELECT * FROM t2';
EXECUTE stmt;
drop table t1,t2;

--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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -28138,7 +28138,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 aa713f5

Please sign in to comment.