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

NEW.col IS NULL disagrees with NEW.col's actual value in multi-event triggers

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 12.3, 13.0, 13.1
    • 12.3, 13.0
    • Triggers
    • None
    • Can result in unexpected behaviour

    Description

      NEW.col IS NULL disagrees with NEW.col's actual value in multi-event triggers

      CREATE TABLE t1 (a INT PRIMARY KEY);
      CREATE TABLE log2 (is_null_flag VARCHAR(5), new_val INT, old_val INT);
       
      --delimiter $$
      CREATE TRIGGER trg BEFORE UPDATE OR DELETE ON t1 FOR EACH ROW
      BEGIN
        IF DELETING THEN
          INSERT INTO log2 VALUES (IF(NEW.a IS NULL, 'YES', 'NO'), NEW.a, OLD.a);
        END IF;
      END
      $$
      --delimiter ;
       
      INSERT INTO t1 VALUES (1);
      DELETE FROM t1 WHERE a = 1;
       
      # Expected: ('YES', NULL) -- NEW has no meaning for DELETE.
      # Actual: ('NO', NULL) -- is_null_flag disagrees with val in the same row.
      SELECT * FROM log2;
       
      #clean up
      DROP TABLE t1, log2;
      

      CLI output

      13.1.0-opt>CREATE TABLE t1 (a INT PRIMARY KEY);
      Query OK, 0 rows affected (0.009 sec)
       
      13.1.0-opt>CREATE TABLE log2 (is_null_flag VARCHAR(5), new_val INT, old_val INT);
      Query OK, 0 rows affected (0.007 sec)
       
      13.1.0-opt>
      13.1.0-opt>delimiter $$
      13.1.0-opt>CREATE TRIGGER trg BEFORE UPDATE OR DELETE ON t1 FOR EACH ROW
          -> BEGIN
          ->   IF DELETING THEN
          ->     INSERT INTO log2 VALUES (IF(NEW.a IS NULL, 'YES', 'NO'), NEW.a, OLD.a);
          ->   END IF;
          -> END
          -> $$
      Query OK, 0 rows affected (0.005 sec)
       
      13.1.0-opt>delimiter ;
      13.1.0-opt>
      13.1.0-opt>INSERT INTO t1 VALUES (1);
      Query OK, 1 row affected (0.002 sec)
       
      13.1.0-opt>DELETE FROM t1 WHERE a = 1;
      Query OK, 1 row affected (0.001 sec)
       
      13.1.0-opt>
      13.1.0-opt>SELECT * FROM log2;
      +--------------+---------+---------+
      | is_null_flag | new_val | old_val |
      +--------------+---------+---------+
      | NO           |    NULL |       1 |
      +--------------+---------+---------+
      1 row in set (0.000 sec)
       
      13.1.0-opt>
      13.1.0-opt>DROP TABLE t1, log2;
      Query OK, 0 rows affected (0.009 sec)
       
      13.1.0-opt>
      

      Attachments

        Issue Links

          Activity

            People

              shulga Dmitry Shulga
              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.