revision-id: e7d3aa6662289cc41f495ba565ea8331e9c33bc1 (mariadb-10.2.16-10-ge7d3aa6) parent(s): 6d377a523c78b1e442d69ae6be548bccddd54416 author: Igor Babaev committer: Igor Babaev timestamp: 2018-06-28 00:13:55 -0700 message: This is another attempt to fix mdev-16473. The previous correction of the patch for mdev-16473 did not work correctly for the databases whose names started with '*'. Added a test case with a database named "*none*". --- mysql-test/r/cte_nonrecursive.result | 11 +++++++++++ mysql-test/t/cte_nonrecursive.test | 7 +++++++ sql/sql_base.cc | 2 +- sql/sql_class.h | 5 ++++- sql/sql_parse.cc | 3 ++- sql/table.h | 3 ++- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result index f6b8015..b1bf786 100644 --- a/mysql-test/r/cte_nonrecursive.result +++ b/mysql-test/r/cte_nonrecursive.result @@ -1511,4 +1511,15 @@ a a 3 3 1 1 drop database db_mdev_16473; +create database `*none*` ; +create table `*none*`.t1 (a int); +insert into `*none*`.t1 values (2), (7), (3), (1); +use `*none*`; +select * from t1; +a +2 +7 +3 +1 +drop database `*none*`; use test; diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index 11c864b..d800903 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -1056,4 +1056,11 @@ select * from cte, db_mdev_16473.t1 as t where cte.a=t.a; drop database db_mdev_16473; +create database `*none*` ; +create table `*none*`.t1 (a int); +insert into `*none*`.t1 values (2), (7), (3), (1); +use `*none*`; +select * from t1; +drop database `*none*`; + use test; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 093f7cf..9905400 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3331,7 +3331,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, Not a placeholder: must be a base/temporary table or a view. Let us open it. */ - if (tables->db[0] == no_db[0]) + if (tables->no_default_db && !tables->is_fqtn) { my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); error= TRUE; diff --git a/sql/sql_class.h b/sql/sql_class.h index e79fde0..88d3af0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3959,7 +3959,10 @@ class THD :public Statement, my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); return TRUE; } - /* This will allow to throw an error later for non-CTE references */ + /* + It does not matter what database name is set in this case + because it will never be used after parser stage + */ *p_db_length= strlen(no_db); *p_db= strmake(no_db, *p_db_length); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3631c8e..6bbc33d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -139,7 +139,7 @@ static bool execute_show_status(THD *, TABLE_LIST *); static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *); const char *any_db="*any*"; // Special symbol for check_access -const char *no_db="*none*"; // Used when no default db is set +const char *no_db="*"; // Used when no default db is set const LEX_STRING command_name[257]={ { C_STRING_WITH_LEN("Sleep") }, //0 @@ -8188,6 +8188,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, DBUG_RETURN(0); else ptr->is_fqtn= FALSE; + ptr->no_default_db= !thd->db && !(lex->sphead && lex->sphead->m_name.str); ptr->alias= alias_str; ptr->is_alias= alias ? TRUE : FALSE; diff --git a/sql/table.h b/sql/table.h index c0cca10..f5d504e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -2095,7 +2095,8 @@ struct TABLE_LIST qualified name (<db_name>.<table_name>). */ bool is_fqtn; - + /** TRUE if no default database is defined for the table name */ + bool no_default_db; /* TRUE <=> derived table should be filled right after optimization. */ bool fill_me; /* TRUE <=> view/DT is merged. */