| Bug #27525 | table not found when using multi-table-deletes with aliases over several databas | ||
|---|---|---|---|
| Submitted: | 29 Mar 2007 16:53 | Modified: | 18 Apr 21:11 |
| Reporter: | Thomas Mayer | ||
| Status: | Closed | ||
| Category: | Server: DML | Severity: | S3 (Non-critical) |
| Version: | 5.0.33/5.1 | OS: | Linux (OpenSuse 10.2) |
| Assigned to: | Davi Arnaut | Target Version: | 6.0 |
| Tags: | 42S02, 1109, USING, alias, multi-table delete | ||
| Triage: | D3 (Medium) | ||
[29 Mar 2007 16:53]
Thomas Mayer
[29 Mar 2007 18:23]
Thomas Mayer
delete from test2.table1 using test2.table1, table2 where test2.table1.f=table2.f; This works, but I do not consider this as a solution. It's just a work-around.
[30 Mar 2007 22:25]
Thomas Mayer
With mysql 5.0.33, the problem persists
[18 May 2007 0:35]
Federico Petronio
Same problem found in Debian Linux 4.0 running MySQL 5.0.32-7etch1. CPU info: vendor_id : AuthenticAMD cpu family : 6 model : 10 model name : AMD Athlon(tm) XP 2600+
[26 Jun 2007 16:43]
Miguel Solorzano
Thank you for the bug report.
[27 Jul 2007 15:35]
Konstantin Osipov
See also Bug #23413 "ERROR 1046 (3D000): No database selected" occurs when executing DELETE FROM
[6 Sep 2007 18:47]
Konstantin Osipov
Please ensure that the patch resolves table names unambiguously, cover with tests, do not forget to alert the docs team to remove the documented limitation from the manual. Fix in 5.2 only.
[31 Oct 2007 0:19]
Alexander Rubin
Bug exists with MySQL 5.0.46
[4 Dec 2007 20:50]
Davi Arnaut
This feature request is also dependent on a much needed fixup of the ambiguities due to a improper extension in the DELETE clause. It shouldn't be possible to specify aliases in the tbl_name part of a DELETE clause: DELETE [..] FROM tbl_name .. DELETE [..] tbl_name[.*] [, tbl_name[.*]] FROM table_references DELETE [..] FROM tbl_name[.*] [, tbl_name[.*]] USING table_references Yet statements like: DELETE a1 AS a1 FROM db1.t1 AS a1, db2.t2 AS a1; are accepted. This deletes from db1.t1 if the selected database is db1 or from db2.t2 if db2 is the selected database. It gets even crazier: USE db2; DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1; # accepted, should not. DELETE a1 FROM db1.t1 AS a1; # fail, should accept. DELETE a1 FROM db2.t2 AS a1; # accepted, ok DELETE a1 AS a1 FROM db1.t1 AS a1, db2.t2 AS a1; # accepted, should not.
[27 Feb 18:56]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/43096 ChangeSet@1.2575, 2008-02-27 14:56:00-03:00, davi@mysql.com +9 -0 Bug#27525 table not found when using multi-table-deletes with aliases over several databas Bug#30234 Unexpected behavior using DELETE with AS and USING The multi-delete statement has a documented limitation that cross-database multiple-table deletes using aliases are not supported because it fails to find the tables by alias if it belongs to a different database. The problem is that when building the list of tables to delete from, if a database name is not specified (maybe an alias) it defaults to the name of the current selected database, making impossible to to properly resolve tables by alias later. Another problem is a inconsistency of the multiple table delete syntax that permits ambiguities in a delete statement (aliases that refer to multiple different tables or vice-versa). The first step for a solution and proper implementation of the cross-databse multiple table delete is to get rid of any ambiguities in a multiple table statement. Currently, the parser is accepting multiple table delete statements that have no obvious meaning, such as: DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1; DELETE a1 AS a1 FROM db1.t1 AS a1, db2.t2 AS a1; The solution is to resolve the left part of a delete statement using the right part, if the a table on right has an alias, it must be referenced in the left using the given alias. Also, each table on the left side must match unambiguously only one table in the right side.
[28 Feb 0:00]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/43122 ChangeSet@1.2575, 2008-02-27 19:59:48-03:00, davi@mysql.com +9 -0 Bug#27525 table not found when using multi-table-deletes with aliases over several databas Bug#30234 Unexpected behavior using DELETE with AS and USING The multi-delete statement has a documented limitation that cross-database multiple-table deletes using aliases are not supported because it fails to find the tables by alias if it belongs to a different database. The problem is that when building the list of tables to delete from, if a database name is not specified (maybe an alias) it defaults to the name of the current selected database, making impossible to to properly resolve tables by alias later. Another problem is a inconsistency of the multiple table delete syntax that permits ambiguities in a delete statement (aliases that refer to multiple different tables or vice-versa). The first step for a solution and proper implementation of the cross-databse multiple table delete is to get rid of any ambiguities in a multiple table statement. Currently, the parser is accepting multiple table delete statements that have no obvious meaning, such as: DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1; DELETE a1 AS a1 FROM db1.t1 AS a1, db2.t2 AS a1; The solution is to resolve the left part of a delete statement using the right part, if the a table on right has an alias, it must be referenced in the left using the given alias. Also, each table on the left side must match unambiguously only one table in the right side.
[28 Feb 0:06]
Davi Arnaut
Queued in 6.0-runtime
[3 Mar 19:19]
Bugs System
Pushed into 6.0.5-alpha
[18 Apr 21:11]
Paul DuBois
Noted in 6.0.5 changelog.
Several changes were made to the processing of multiple-table DELETE
statements:
- Statements could not perform cross-database deletes unless the tables
were referred to without using aliases. This limitation has been
lifted and table aliases now are allowed.
- Previously, alias declarations could be given for tables elsewhere
than in the table_references part of the syntax. This could lead to
ambiguous statements that have unexpected results such as deleting
rows from the wrong table. Example:
DELETE FROM t1 AS a2 USING t1 AS a1 INNER JOIN t2 AS a2;
Now alias declarations can be declared only in the table_references
part. Elsewhere in the statement, alias references are allowed but
not alias declarations.
- Alias resolution was improved so that it is no longer possible to
have inconsistent or ambiguous aliases for tables.
Statements containing alias constructs that are no longer allowed
must be rewritten.
[4 Jun 6:42]
Robert Chapin
New information on version 5.0.45 This bug can be reproduced without using a multi-database query. I was able to do this while testing XMB. I created a second copy of the database to use for testing DELETE statements. While testing only the second copy... DELETE xmb_attachments, xmb_posts FROM xmb_posts AS p LEFT JOIN xmb_attachments USING(pid) WHERE p.author='kuba1' ...MySQL Threw... #1109 - Unknown table 'xmb_posts' in MULTI DELETE I repeated the statement several times in PHP and phpMyAdmin with the same result. The error disappeared when I separated the statement as: DELETE xmb_attachments FROM xmb_posts AS p LEFT JOIN xmb_attachments USING(pid) WHERE p.author='kuba1' DELETE FROM xmb_posts WHERE author='kuba1' I hope I'm not just repeating what was said earlier. My scenario seemed much simpler than the multi-database ambiguous alias case. Robert Chapin Chapin Information Services, Inc.
[4 Jun 6:57]
Robert Chapin
My comment might duplicate http://bugs.mysql.com/bug.php?id=4630
