summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-06-28 00:33:44 -0700
committerIgor Babaev <igor@askmonty.org>2018-06-28 00:36:50 -0700
commit090febbb2dedad764a4d9fdbc9216921dd27225f (patch)
treeed47de000eb321849727cc04530993cf73f8d762
parent377cd520643eba3dccc21336af582b170137d407 (diff)
downloadmariadb-git-090febbb2dedad764a4d9fdbc9216921dd27225f.tar.gz
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 "*".
-rw-r--r--mysql-test/r/cte_nonrecursive.result11
-rw-r--r--mysql-test/t/cte_nonrecursive.test7
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_class.h5
-rw-r--r--sql/sql_parse.cc3
-rw-r--r--sql/table.h3
6 files changed, 27 insertions, 4 deletions
diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result
index f6b80156ee0..32104c53af5 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 `*` ;
+create table `*`.t1 (a int);
+insert into `*`.t1 values (2), (7), (3), (1);
+use `*`;
+select * from t1;
+a
+2
+7
+3
+1
+drop database `*`;
use test;
diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test
index 11c864bcac1..22bb292d8d9 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 `*` ;
+create table `*`.t1 (a int);
+insert into `*`.t1 values (2), (7), (3), (1);
+use `*`;
+select * from t1;
+drop database `*`;
+
use test;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 093f7cf3427..9905400109e 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 e79fde055c2..88d3af04376 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3959,7 +3959,10 @@ public:
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 3631c8edd13..6bbc33d000a 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 c0cca1026ea..f5d504e39d8 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. */