Skip to content

Commit 090febb

Browse files
committed
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 "*".
1 parent 377cd52 commit 090febb

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

mysql-test/r/cte_nonrecursive.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,4 +1511,15 @@ a a
15111511
3 3
15121512
1 1
15131513
drop database db_mdev_16473;
1514+
create database `*` ;
1515+
create table `*`.t1 (a int);
1516+
insert into `*`.t1 values (2), (7), (3), (1);
1517+
use `*`;
1518+
select * from t1;
1519+
a
1520+
2
1521+
7
1522+
3
1523+
1
1524+
drop database `*`;
15141525
use test;

mysql-test/t/cte_nonrecursive.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,4 +1056,11 @@ select * from cte, db_mdev_16473.t1 as t where cte.a=t.a;
10561056

10571057
drop database db_mdev_16473;
10581058

1059+
create database `*` ;
1060+
create table `*`.t1 (a int);
1061+
insert into `*`.t1 values (2), (7), (3), (1);
1062+
use `*`;
1063+
select * from t1;
1064+
drop database `*`;
1065+
10591066
use test;

sql/sql_base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
33313331
Not a placeholder: must be a base/temporary table or a view. Let us open it.
33323332
*/
33333333

3334-
if (tables->db[0] == no_db[0])
3334+
if (tables->no_default_db && !tables->is_fqtn)
33353335
{
33363336
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
33373337
error= TRUE;

sql/sql_class.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3959,7 +3959,10 @@ class THD :public Statement,
39593959
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
39603960
return TRUE;
39613961
}
3962-
/* This will allow to throw an error later for non-CTE references */
3962+
/*
3963+
It does not matter what database name is set in this case
3964+
because it will never be used after parser stage
3965+
*/
39633966
*p_db_length= strlen(no_db);
39643967
*p_db= strmake(no_db, *p_db_length);
39653968
}

sql/sql_parse.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static bool execute_show_status(THD *, TABLE_LIST *);
139139
static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
140140

141141
const char *any_db="*any*"; // Special symbol for check_access
142-
const char *no_db="*none*"; // Used when no default db is set
142+
const char *no_db="*"; // Used when no default db is set
143143

144144
const LEX_STRING command_name[257]={
145145
{ C_STRING_WITH_LEN("Sleep") }, //0
@@ -8188,6 +8188,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
81888188
DBUG_RETURN(0);
81898189
else
81908190
ptr->is_fqtn= FALSE;
8191+
ptr->no_default_db= !thd->db && !(lex->sphead && lex->sphead->m_name.str);
81918192

81928193
ptr->alias= alias_str;
81938194
ptr->is_alias= alias ? TRUE : FALSE;

sql/table.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,8 @@ struct TABLE_LIST
20952095
qualified name (<db_name>.<table_name>).
20962096
*/
20972097
bool is_fqtn;
2098-
2098+
/** TRUE if no default database is defined for the table name */
2099+
bool no_default_db;
20992100
/* TRUE <=> derived table should be filled right after optimization. */
21002101
bool fill_me;
21012102
/* TRUE <=> view/DT is merged. */

0 commit comments

Comments
 (0)