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

DELETE ... FOR PORTION OF with a subquery bound deletes the whole row instead of the portion

    XMLWordPrintable

Details

    • Can result in data loss

    Description

      Testcase

      CREATE TABLE src (d DATE) ENGINE=MyISAM;
      INSERT INTO src VALUES ('2002-01-01'), ('2003-01-01');
      CREATE TABLE t1 (id INT, s DATE, e DATE, PERIOD FOR p(s,e)) ENGINE= MyISAM;
      INSERT INTO t1 VALUES (1, '2000-01-01', '2010-01-01');
      SELECT id, s AS period_start, e AS period_end FROM t1;
      DELETE FROM t1 FOR PORTION OF p FROM (SELECT MIN(d) FROM src)
                                        TO (SELECT MAX(d) FROM src);
      SELECT id, s AS period_start, e AS period_end FROM t1 ORDER BY s;
      

      CLI output

      10.6.28-opt>CREATE TABLE src (d DATE) ENGINE=MyISAM;
      Query OK, 0 rows affected (0.136 sec)
       
      10.6.28-opt>INSERT INTO src VALUES ('2002-01-01'), ('2003-01-01');
      Query OK, 2 rows affected (0.037 sec)
      Records: 2  Duplicates: 0  Warnings: 0
       
      10.6.28-opt>
      10.6.28-opt>CREATE TABLE t1 (id INT, s DATE, e DATE, PERIOD FOR p(s,e)) ENGINE=MyISAM;
      Query OK, 0 rows affected (0.022 sec)
       
      10.6.28-opt>INSERT INTO t1 VALUES (1, '2000-01-01', '2010-01-01');
      Query OK, 1 row affected (0.000 sec)
       
      10.6.28-opt>
      10.6.28-opt>SELECT id, s AS period_start, e AS period_end FROM t1;
      +------+--------------+------------+
      | id   | period_start | period_end |
      +------+--------------+------------+
      |    1 | 2000-01-01   | 2010-01-01 |
      +------+--------------+------------+
      1 row in set (0.012 sec)
       
      10.6.28-opt>
      10.6.28-opt>DELETE FROM t1 FOR PORTION OF p FROM (SELECT MIN(d) FROM src)
          ->                                   TO (SELECT MAX(d) FROM src);
      Query OK, 1 row affected (0.005 sec)
       
      10.6.28-opt>SELECT id, s AS period_start, e AS period_end FROM t1 ORDER BY s;
      Empty set (0.000 sec)
       
      10.6.28-opt>
      

      Without subquery DELETE statement works fine

      10.6.28-opt>INSERT INTO t1 VALUES (1, '2000-01-01', '2010-01-01');
      Query OK, 1 row affected (0.000 sec)
       
      10.6.28-opt>DELETE FROM t1 FOR PORTION OF p FROM '2002-01-01' TO '2003-01-01';
      Query OK, 1 row affected (0.000 sec)
       
      10.6.28-opt>SELECT id, s AS period_start, e AS period_end FROM t1 ORDER BY s;
      +------+--------------+------------+
      | id   | period_start | period_end |
      +------+--------------+------------+
      |    1 | 2000-01-01   | 2002-01-01 |
      |    1 | 2003-01-01   | 2010-01-01 |
      +------+--------------+------------+
      2 rows in set (0.000 sec)
       
      10.6.28-opt>
      

      Attachments

        Activity

          People

            midenok Aleksey Midenkov
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Time Spent - 0.5h Remaining Estimate - 2.5d
                2.5d
                Logged:
                Time Spent - 0.5h Remaining Estimate - 2.5d
                0.5h

                Git Integration

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