revision-id: 4a24472601eb9d9f4e14f3ad9c1c1537b6e46bfb (mariadb-10.2.31-895-g4a24472) parent(s): 1288dfffe77a99d6c5906d12010a1677ee149308 author: Igor Babaev committer: Igor Babaev timestamp: 2021-04-26 15:38:07 -0700 message: MDEV-21603 Crashing SHOW TABLES with derived table in WHERE condition --- mysql-test/r/derived.result | 12 ++++++++++++ mysql-test/t/derived.test | 14 ++++++++++++++ sql/sql_base.cc | 1 - sql/sql_lex.cc | 2 -- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 2106ba5..c55c5af 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -1204,5 +1204,17 @@ REPLACE INTO v2 ( SELECT * FROM v4 ) UNION ( SELECT f FROM v2 ); drop view v1,v2,v3,v4; drop table t1,t2,t3; # +# MDEV-21603: materialized derived used in SHOW TABLES +# +create table t1 (nm varchar(32)); +insert into t1 values ('1'),('2'),('3'); +use mysql; +show tables +where tables_in_mysql in (select * +from (select * from test.t1 group by nm) dt); +Tables_in_mysql +use test; +drop table t1; +# # End of 10.2 tests # diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 6d9d5e2..b099ace 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -1036,6 +1036,20 @@ REPLACE INTO v2 ( SELECT * FROM v4 ) UNION ( SELECT f FROM v2 ); drop view v1,v2,v3,v4; drop table t1,t2,t3; + +--echo # +--echo # MDEV-21603: materialized derived used in SHOW TABLES +--echo # + +create table t1 (nm varchar(32)); +insert into t1 values ('1'),('2'),('3'); +use mysql; +show tables + where tables_in_mysql in (select * + from (select * from test.t1 group by nm) dt); +use test; +drop table t1; + --echo # --echo # End of 10.2 tests --echo # diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3403f9e..16689f8 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4939,7 +4939,6 @@ bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags, uint counter; MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint(); DBUG_ENTER("open_normal_and_derived_tables"); - DBUG_ASSERT(!thd->fill_derived_tables()); if (open_tables(thd, &tables, &counter, flags, &prelocking_strategy) || mysql_handle_derived(thd->lex, dt_phases)) goto end; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 57c6dfa..0b78d53 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3105,8 +3105,6 @@ bool LEX::only_view_structure() { switch (sql_command) { case SQLCOM_SHOW_CREATE: - case SQLCOM_SHOW_TABLES: - case SQLCOM_SHOW_FIELDS: case SQLCOM_REVOKE_ALL: case SQLCOM_REVOKE: case SQLCOM_GRANT: