[Commits] 6be6ecf: MDEV-21603 Crashing SHOW TABLES with derived table in WHERE condition
revision-id: 6be6ecf2f0dd1822b3573a4cd3d28d5173a7d6c7 (mariadb-10.3.26-139-g6be6ecf) parent(s): 2c9bf0ae8758b2c46ea5e02d1ea3d3ab5cab63b2 author: Igor Babaev committer: Igor Babaev timestamp: 2021-04-28 23:24:48 -0700 message: MDEV-21603 Crashing SHOW TABLES with derived table in WHERE condition --- mysql-test/main/derived.result | 31 +++++++++++++++++++++++++++++++ mysql-test/main/derived.test | 29 +++++++++++++++++++++++++++++ sql/sql_base.cc | 1 - sql/sql_lex.cc | 2 -- sql/sql_show.cc | 4 +++- 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result index 0f91750..975c18c 100644 --- a/mysql-test/main/derived.result +++ b/mysql-test/main/derived.result @@ -1260,3 +1260,34 @@ a a 4 4 6 6 drop table t1,t2,t3; +# +# MDEV-21603: materialized derived used in SHOW TABLES +# +create table t1 (nm varchar(32), a int); +insert into t1 values ('1',1),('2',2),('3',3); +use mysql; +show tables +where tables_in_mysql in (select * +from (select nm from test.t1 group by nm) dt); +Tables_in_mysql +show fields from test.t1 +where Field in (select * from (select nm from test.t1 group by nm) dt); +Field Type Null Key Default Extra +insert into test.t1 values ('nm',0); +show fields from test.t1 +where Field in (select * from (select nm from test.t1 group by nm) dt); +Field Type Null Key Default Extra +nm varchar(32) YES NULL +show fields from test.t1 +where Field in +(select * from (select column_name from information_schema.columns +where table_name='t1' + group by column_name) dt); +Field Type Null Key Default Extra +nm varchar(32) YES NULL +a int(11) YES NULL +use test; +drop table t1; +# +# End of 10.2 tests +# diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test index f4477ce..cad22aa 100644 --- a/mysql-test/main/derived.test +++ b/mysql-test/main/derived.test @@ -1069,3 +1069,32 @@ analyze select * from t1 , ( (select t2.a from t2 order by c) union all (select select * from t1 , ( (select t2.a from t2 order by c) union all (select t2.a from t2 order by c) except(select t3.a from t3 order by b))q where t1.a=q.a; drop table t1,t2,t3; + +--echo # +--echo # MDEV-21603: materialized derived used in SHOW TABLES +--echo # + +create table t1 (nm varchar(32), a int); +insert into t1 values ('1',1),('2',2),('3',3); +use mysql; +show tables + where tables_in_mysql in (select * + from (select nm from test.t1 group by nm) dt); +show fields from test.t1 + where Field in (select * from (select nm from test.t1 group by nm) dt); +insert into test.t1 values ('nm',0); +show fields from test.t1 + where Field in (select * from (select nm from test.t1 group by nm) dt); + +show fields from test.t1 + where Field in + (select * from (select column_name from information_schema.columns + where table_name='t1' + group by column_name) 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 74ac1a3..031baee 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5187,7 +5187,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 5604658..3866d82 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3358,8 +3358,6 @@ bool LEX::only_view_structure() switch (sql_command) { case SQLCOM_SHOW_CREATE: case SQLCOM_CHECKSUM: - case SQLCOM_SHOW_TABLES: - case SQLCOM_SHOW_FIELDS: case SQLCOM_REVOKE_ALL: case SQLCOM_REVOKE: case SQLCOM_GRANT: diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6b020f6..bf72c59 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -8140,7 +8140,9 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list) CHARSET_INFO *cs= system_charset_info; MEM_ROOT *mem_root= thd->mem_root; bool need_all_fieds= table_list->schema_table_reformed || // SHOW command - thd->lex->only_view_structure(); // need table structure + thd->lex->only_view_structure() || // need table structure + thd->lex->sql_command == SQLCOM_SHOW_FIELDS || + thd->lex->sql_command == SQLCOM_SHOW_TABLES; DBUG_ENTER("create_schema_table"); for (; fields_info->field_name; fields_info++)
participants (1)
-
IgorBabaev