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

UPDATE/DELETE IGNORE ... FOR PORTION OF silently drops the part of the row outside the portion

    XMLWordPrintable

Details

    • Can result in data loss

    Description

      Test case

      CREATE TABLE bookings (room INT PRIMARY KEY, guest VARCHAR(10),
                             checkin DATE, checkout DATE,
                             PERIOD FOR stay(checkin, checkout)) ENGINE=InnoDB;
      INSERT INTO bookings VALUES (7, 'alice', '2000-01-01', '2010-01-01');
      SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
       
      # without IGNORE correctly refused
      UPDATE bookings FOR PORTION OF stay FROM '2002-01-01' TO '2003-01-01'
        SET guest='bob';
      SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
       
      # Bug: the same statement with IGNORE silently drops the part of the row outside the portion
      UPDATE IGNORE bookings FOR PORTION OF stay FROM '2002-01-01' TO '2003-01-01'
        SET guest='bob';
      SELECT ROW_COUNT();
      SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
      

      CLI Output

      10.6.28-opt>CREATE TABLE bookings (room INT PRIMARY KEY, guest VARCHAR(10),
          ->                        checkin DATE, checkout DATE,
          ->                        PERIOD FOR stay(checkin, checkout)) ENGINE=InnoDB;
      out AS period_end FROM bookings;
       
      DROP TABLE bookings;Query OK, 0 rows affected (0.017 sec)
       
      10.6.28-opt>INSERT INTO bookings VALUES (7, 'alice', '2000-01-01', '2010-01-01');
      Query OK, 1 row affected (0.003 sec)
       
      10.6.28-opt>SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
      +------+-------+--------------+------------+
      | room | guest | period_start | period_end |
      +------+-------+--------------+------------+
      |    7 | alice | 2000-01-01   | 2010-01-01 |
      +------+-------+--------------+------------+
      1 row in set (0.000 sec)
       
      10.6.28-opt>
       
      # without IGNORE correctly refused
      10.6.28-opt>UPDATE bookings FOR PORTION OF stay FROM '2002-01-01' TO '2003-01-01'
          ->   SET guest='bob';
      ERROR 1062 (23000): Duplicate entry '7' for key 'PRIMARY'
      10.6.28-opt>SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
      +------+-------+--------------+------------+
      | room | guest | period_start | period_end |
      +------+-------+--------------+------------+
      |    7 | alice | 2000-01-01   | 2010-01-01 |
      +------+-------+--------------+------------+
      1 row in set (0.000 sec)
       
      10.6.28-opt>
      # Bug: the same statement with IGNORE silently drops the part of the row outside the portion
      10.6.28-opt>UPDATE IGNORE bookings FOR PORTION OF stay FROM '2002-01-01' TO '2003-01-01'
          ->   SET guest='bob';
      Query OK, 1 row affected (0.001 sec)
      Rows matched: 1  Changed: 1  Inserted: 0  Warnings: 0
       
      10.6.28-opt>SELECT room, guest, checkin AS period_start, checkout AS period_end FROM bookings;
      +------+-------+--------------+------------+
      | room | guest | period_start | period_end |
      +------+-------+--------------+------------+
      |    7 | bob   | 2002-01-01   | 2003-01-01 |
      +------+-------+--------------+------------+
      1 row in set (0.000 sec)
       
      10.6.28-opt>
      

      Attachments

        Issue Links

          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 - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 0.5h
                  0.5h

                  Git Integration

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