[MDEV-10447] different execution plan for single- and multi-DELETE Created: 2016-07-26  Updated: 2018-02-23

Status: Open
Project: MariaDB Server
Component/s: Data Manipulation - Delete, Optimizer
Affects Version/s: 10.1
Fix Version/s: 10.1

Type: Bug Priority: Major
Reporter: Sergei Golubchik Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-7487 Semi-join optimization for single-tab... Closed

 Description   

create table t1 (id int);
insert t1 values (1),(2),(3);
create table t2 (id int, acc_id int);
insert t2 values (1,1),(2,2),(3,3);
explain delete from t1 where id in (select id from t2 where acc_id = 9999);
explain delete uc from t1 as uc where uc. id in (select p. id from t2 p where p.acc_id = 9999);



 Comments   
Comment by Rhys Campbell [ 2016-07-27 ]

Just an example a little closer to what I saw. Version 10.0.24..

CREATE TABLE t1 (id INT PRIMARY KEY);
INSERT t1 VALUES (1),(2),(3);
CREATE TABLE t2 (id INT PRIMARY KEY, acc_id INT, KEY(acc_id));
INSERT t2 VALUES (1,1),(2,2),(3,3);
EXPLAIN DELETE FROM t1 WHERE id IN (SELECT id FROM t2 WHERE acc_id = 9999); # Table scan first!
EXPLAIN DELETE uc FROM t1 AS uc WHERE uc.id IN (SELECT p.id FROM t2 p WHERE p.acc_id = 9999); # the plan we want
 
EXPLAIN DELETE FROM t1 WHERE t1.id IN (SELECT t2.id FROM t2 WHERE t2.acc_id = 9999) RETURNING t1.id; # Even aliasing like this produceds the poor plan

Generated at Thu Feb 08 07:42:17 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.