summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-06-28 12:36:32 +0200
committerSergei Golubchik <serg@mariadb.org>2018-06-28 12:38:53 +0200
commit52a25d7b674464013b7749a366b0879929985a1e (patch)
tree03aee2320340856a879392629041811eb4d0b0ef
parent090febbb2dedad764a4d9fdbc9216921dd27225f (diff)
downloadmariadb-git-52a25d7b674464013b7749a366b0879929985a1e.tar.gz
MDEV-16473 WITH statement throws 'no database selected' error
Different fix, just use NULL, not no_db,
-rw-r--r--mysql-test/r/cte_nonrecursive.result11
-rw-r--r--mysql-test/t/cte_nonrecursive.test7
-rw-r--r--sql/sql_acl.cc2
-rw-r--r--sql/sql_base.cc14
-rw-r--r--sql/sql_class.h9
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_parse.cc10
-rw-r--r--sql/table.h3
8 files changed, 13 insertions, 45 deletions
diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result
index 32104c53af5..f6b80156ee0 100644
--- a/mysql-test/r/cte_nonrecursive.result
+++ b/mysql-test/r/cte_nonrecursive.result
@@ -1511,15 +1511,4 @@ 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 22bb292d8d9..11c864bcac1 100644
--- a/mysql-test/t/cte_nonrecursive.test
+++ b/mysql-test/t/cte_nonrecursive.test
@@ -1056,11 +1056,4 @@ 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_acl.cc b/sql/sql_acl.cc
index 1809e22ffbf..792fe700473 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -7581,7 +7581,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
tl->correspondent_table ? tl->correspondent_table : tl;
sctx= t_ref->security_ctx ? t_ref->security_ctx : thd->security_ctx;
- if (tl->with ||
+ if (tl->with || !tl->db ||
(tl->select_lex &&
(tl->with= tl->select_lex->find_table_def_in_with_clauses(tl))))
continue;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 9905400109e..32e42daf7c4 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1531,6 +1531,12 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
DBUG_RETURN(true);
}
+ if (!table_list->db)
+ {
+ my_error(ER_NO_DB_ERROR, MYF(0));
+ DBUG_RETURN(true);
+ }
+
key_length= get_table_def_key(table_list, &key);
/*
@@ -3330,14 +3336,6 @@ 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->no_default_db && !tables->is_fqtn)
- {
- my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
- error= TRUE;
- goto end;
- }
-
if (tables->table)
{
/*
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 88d3af04376..b377d74445f 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3959,12 +3959,9 @@ public:
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
return TRUE;
}
- /*
- 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);
+ /* This will allow to throw an error later for non-CTE references */
+ *p_db= NULL;
+ *p_db_length= 0;
}
else
{
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index ae010a88e46..a1f6b202ae6 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -156,8 +156,6 @@ struct LEX_TYPE
extern const LEX_STRING null_lex_str;
extern const LEX_STRING empty_lex_str;
-extern const char *no_db;
-
enum enum_sp_suid_behaviour
{
SP_IS_DEFAULT_SUID= 0,
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 6bbc33d000a..df0ee2bd680 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -139,7 +139,6 @@ 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="*"; // Used when no default db is set
const LEX_STRING command_name[257]={
{ C_STRING_WITH_LEN("Sleep") }, //0
@@ -6685,11 +6684,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
THD_STAGE_INFO(thd, stage_checking_permissions);
if ((!db || !db[0]) && !thd->db && !dont_check_global_grants)
{
- DBUG_PRINT("error",("No database"));
- if (!no_errors)
- my_message(ER_NO_DB_ERROR, ER_THD(thd, ER_NO_DB_ERROR),
- MYF(0)); /* purecov: tested */
- DBUG_RETURN(TRUE); /* purecov: tested */
+ DBUG_RETURN(FALSE); // CTE reference or an error later
}
if ((db != NULL) && (db != any_db))
@@ -8188,7 +8183,6 @@ 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;
@@ -8301,7 +8295,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
lex->add_to_query_tables(ptr);
// Pure table aliases do not need to be locked:
- if (!MY_TEST(table_options & TL_OPTION_ALIAS))
+ if (ptr->db && !(table_options & TL_OPTION_ALIAS))
{
ptr->mdl_request.init(MDL_key::TABLE, ptr->db, ptr->table_name, mdl_type,
MDL_TRANSACTION);
diff --git a/sql/table.h b/sql/table.h
index f5d504e39d8..c0cca1026ea 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2095,8 +2095,7 @@ 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. */