Bug #17014 | table can not be used after "using ... as " | ||
---|---|---|---|
Submitted: | 1 Feb 2006 16:15 | Modified: | 9 Feb 2006 13:47 |
Reporter: | [ name withheld ] | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 5.0.18 | OS: | Linux (LINUX 2.4.32) |
Assigned to: | CPU Architecture: | Any |
[1 Feb 2006 16:15]
[ name withheld ]
[9 Feb 2006 13:47]
Valeriy Kravchuk
MUPLTI DELETE should mean "multiple-table DELETE" - the operation you are trying to perform. Read the manual (http://dev.mysql.com/doc/refman/4.1/en/delete.html) about it: "From MySQL 4.0, you can specify multiple tables in the DELETE statement to delete rows from one or more tables depending on a particular condition in multiple tables. However, you cannot use ORDER BY or LIMIT in a multiple-table DELETE. You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the particular condition in the WHERE clause. However, you cannot use ORDER BY or LIMIT in a multiple-table DELETE. The table_references clause lists the tables involved in the join. Its syntax is described in Section 13.2.7.1, “JOIN Syntax”. The first multiple-table DELETE syntax is supported starting from MySQL 4.0.0. The second is supported starting from MySQL 4.0.2. For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted. For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted. The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching: DELETE t1, t2 FROM t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id; Or: DELETE FROM t1, t2 USING t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id; These statements use all three tables when searching for rows to delete, but delete matching rows only from tables t1 and t2. The preceding examples show inner joins that use the comma operator, but multiple-table DELETE statements can use any type of join allowed in SELECT statements, such as LEFT JOIN. The syntax allows .* after the table names for compatibility with Access. If you use a multiple-table DELETE statement involving InnoDB tables for which there are foreign key constraints, the MySQL optimizer might process tables in an order that differs from that of their parent/child relationship. In this case, the statement fails and rolls back. Instead, you should delete from a single table and rely on the ON DELETE capabilities that InnoDB provides to cause the other tables to be modified accordingly. Note: In MySQL 4.0, you should refer to the table names to be deleted with the true table name. In MySQL 4.1, you must use the alias (if one was given) when referring to a table name: In MySQL 4.0: DELETE test FROM test AS t1, test2 WHERE ... In MySQL 4.1: DELETE t1 FROM test AS t1, test2 WHERE ... The reason we did not make this change in 4.0 was to avoid breaking any old 4.0 applications that were using the old syntax." The Note in this long quote from the manual also explains, why the behaviour you described is not a bug in MySQL >=4.1. It is intended and documented behaviour in newer versions.