Bug #81770 Manual description for derived_merge & delete isn't apply for 5.7.11 or later.
Submitted: 8 Jun 2016 6:00 Modified: 24 Aug 2016 17:04
Reporter: Meiji Kimura Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.7.11 or later OS:Any
Assigned to: CPU Architecture:Any

[8 Jun 2016 6:00] Meiji Kimura
Description:
http://dev.mysql.com/doc/refman/5.7/en/subquery-optimization.html#derived-table-optimizati...

In this manual, it says,"

For statements such as DELETE or UPDATE that modify tables, using the merge strategy for a derived table that prior to MySQL 5.7.6 was materialized can result in an ER_UPDATE_TABLE_USED error:

mysql> DELETE FROM t1
    -> WHERE id IN (SELECT id
    ->              FROM (SELECT t1.id
    ->                    FROM t1 INNER JOIN t2 USING (id)
    ->                    WHERE t2.status = 0) AS t);
ERROR 1093 (HY000): You can't specify target table 't1'
for update in FROM clause

"

But the modification based on Bug#79333, the result is not true for MySQL 5.7.11 or later. It's not affected setting of derived_merge.

MySQL5.7.6-5.7.10
mysql> DELETE FROM t1 WHERE id IN (SELECT id FROM (SELECT t1.id FROM t1 INNER JOIN t2 USING (id) WHERE t2.status = 0) AS t);
ERROR 1093 (HY000): You can't specify target table 't1' for update in FROM clause

MySQL 5.6 or earlier, MySQL5.7.11-5.7.13
mysql> DELETE FROM t1 WHERE id IN (SELECT id FROM (SELECT t1.id FROM t1 INNER JOIN t2 USING (id) WHERE t2.status = 0) AS t);
Query OK, 3 rows affected (0.00 sec)

So we need to update about manual desciption about this query.

How to repeat:
run these queries on MySQL 5.7.11 or later.

drop table if exists t1;
CREATE TABLE t1 (id INT);
INSERT INTO t1 VALUES(1),(2),(3),(4),(5);
drop table if exists t2;
CREATE TABLE t2 (id INT,status INT);
INSERT INTO t2 VALUES(1,1),(2,1),(3,0),(4,0),(5,0);
commit;

DELETE FROM t1 WHERE id IN (SELECT id FROM (SELECT t1.id FROM t1 INNER JOIN t2 USING (id) WHERE t2.status = 0) AS t);

Suggested fix:
Ask the developper for good example to explain derived_merge & update/delete.
[8 Jun 2016 7:00] MySQL Verification Team
Hello Meiji-San,

Thank you for the report and feedback!

Thanks,
Umesh
[24 Aug 2016 17:04] Paul DuBois
Posted by developer:
 
Recommendation from the optimizer team was that, since the issue has been fixed, to simply remove the text in question.