Bug #21392: multi-table delete with alias table name fails with

            1003: Incorrect table name
in multi-table DELETE the set of tables to delete from actually 
references then tables in the other list, e.g:
DELETE alias_of_t1 FROM t1 alias_of_t1 WHERE ....
is a valid statement.
So we must turn off table name syntactical validity check for alias_of_t1 
because it's not a table name (even if it looks like one).
In order to do that we add a special flag (TL_OPTION_ALIAS) to 
disable the name checking for the aliases in multi-table DELETE.
parent 13f50fdb
...@@ -172,3 +172,7 @@ a ...@@ -172,3 +172,7 @@ a
0 0
2 2
DROP TABLE t1; DROP TABLE t1;
create table t1 (a int);
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
drop table t1;
...@@ -153,4 +153,14 @@ DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1; ...@@ -153,4 +153,14 @@ DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
#
# Bug #21392: multi-table delete with alias table name fails with
# 1003: Incorrect table name
#
create table t1 (a int);
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
drop table t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -305,6 +305,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout); ...@@ -305,6 +305,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout);
#define TL_OPTION_UPDATING 1 #define TL_OPTION_UPDATING 1
#define TL_OPTION_FORCE_INDEX 2 #define TL_OPTION_FORCE_INDEX 2
#define TL_OPTION_IGNORE_LEAVES 4 #define TL_OPTION_IGNORE_LEAVES 4
#define TL_OPTION_ALIAS 8
/* Some portable defines */ /* Some portable defines */
......
...@@ -4863,6 +4863,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc) ...@@ -4863,6 +4863,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
table_options A set of the following bits: table_options A set of the following bits:
TL_OPTION_UPDATING Table will be updated TL_OPTION_UPDATING Table will be updated
TL_OPTION_FORCE_INDEX Force usage of index TL_OPTION_FORCE_INDEX Force usage of index
TL_OPTION_ALIAS an alias in multi table DELETE
lock_type How table should be locked lock_type How table should be locked
use_index List of indexed used in USE INDEX use_index List of indexed used in USE INDEX
ignore_index List of indexed used in IGNORE INDEX ignore_index List of indexed used in IGNORE INDEX
...@@ -4888,7 +4889,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ...@@ -4888,7 +4889,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
if (!table) if (!table)
DBUG_RETURN(0); // End of memory DBUG_RETURN(0); // End of memory
alias_str= alias ? alias->str : table->table.str; alias_str= alias ? alias->str : table->table.str;
if (check_table_name(table->table.str,table->table.length) || if (!test(table_options & TL_OPTION_ALIAS) &&
check_table_name(table->table.str,table->table.length) ||
table->db.str && check_db_name(table->db.str)) table->db.str && check_db_name(table->db.str))
{ {
net_printf(thd, ER_WRONG_TABLE_NAME, table->table.str); net_printf(thd, ER_WRONG_TABLE_NAME, table->table.str);
......
...@@ -4345,14 +4345,17 @@ table_wild_one: ...@@ -4345,14 +4345,17 @@ table_wild_one:
ident opt_wild opt_table_alias ident opt_wild opt_table_alias
{ {
if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3, if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
TL_OPTION_UPDATING, Lex->lock_option)) TL_OPTION_UPDATING |
TL_OPTION_ALIAS, Lex->lock_option))
YYABORT; YYABORT;
} }
| ident '.' ident opt_wild opt_table_alias | ident '.' ident opt_wild opt_table_alias
{ {
if (!Select->add_table_to_list(YYTHD, if (!Select->add_table_to_list(YYTHD,
new Table_ident(YYTHD, $1, $3, 0), new Table_ident(YYTHD, $1, $3, 0),
$5, TL_OPTION_UPDATING, $5,
TL_OPTION_UPDATING |
TL_OPTION_ALIAS,
Lex->lock_option)) Lex->lock_option))
YYABORT; YYABORT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment