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

INSERT ... ON DUPLICATE KEY UPDATE report the wrong INSERTING/UPDATING/DELETING flag 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

      MTR Test

      CREATE TABLE t1 (a INT PRIMARY KEY);
      CREATE TABLE log1 (msg VARCHAR(20));
       
      --delimiter $
      CREATE TRIGGER trg BEFORE INSERT OR UPDATE OR DELETE ON t1 FOR EACH ROW
      BEGIN
        IF INSERTING THEN
          INSERT INTO log1 VALUES ('INSERTING');
        ELSEIF UPDATING THEN
          INSERT INTO log1 VALUES ('UPDATING');
        ELSEIF DELETING THEN
          INSERT INTO log1 VALUES ('DELETING');
        END IF;
      END
      $
      --delimiter ;
       
      INSERT INTO t1 VALUES (1);
      # Expected: second log1 row is 'UPDATING'. Actual: 'INSERTING'.
      INSERT INTO t1 VALUES (1) ON DUPLICATE KEY UPDATE a = 1;
       
      SELECT * FROM log1;
       
      DROP TABLE t1, log1;
      

      CLI Out

      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 log1 (msg VARCHAR(20));
      Query OK, 0 rows affected (0.008 sec)
       
      13.1.0-opt>
      13.1.0-opt>delimiter $$
      13.1.0-opt>CREATE TRIGGER trg BEFORE INSERT OR UPDATE OR DELETE ON t1 FOR EACH ROW
          -> BEGIN
          ->   IF INSERTING THEN
          ->     INSERT INTO log1 VALUES ('INSERTING');
          ->   ELSEIF UPDATING THEN
          ->     INSERT INTO log1 VALUES ('UPDATING');
          ->   ELSEIF DELETING THEN
          ->     INSERT INTO log1 VALUES ('DELETING');
          ->   END IF;
          -> END
          -> $$
      Query OK, 0 rows affected (0.006 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.001 sec)
       
      13.1.0-opt>INSERT INTO t1 VALUES (1) ON DUPLICATE KEY UPDATE a = 1;
      Query OK, 0 rows affected (0.002 sec)
       
      13.1.0-opt>SELECT * FROM log1;
      +-----------+
      | msg       |
      +-----------+
      | INSERTING |
      | INSERTING |
      | INSERTING |
      +-----------+
      3 rows in set (0.000 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.