Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-10447

different execution plan for single- and multi-DELETE

Details

    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);
      

      Attachments

        Issue Links

          Activity

            rhyscampbell Rhys Campbell added a comment -

            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
            

            rhyscampbell Rhys Campbell added a comment - 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

            People

              Unassigned Unassigned
              serg Sergei Golubchik
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.