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

Multi-table UPDATE stores NULL into a NOT NULL column as 0 without an error when the target table has a BEFORE UPDATE trigger

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      CLI Testcase

      SET sql_mode='STRICT_ALL_TABLES';
      CREATE TABLE t (f INT NOT NULL);
      CREATE TABLE t2 (g INT);
      INSERT INTO t VALUES (5);
      INSERT INTO t2 VALUES (5);
      UPDATE t2, t SET t.f=NULL;
      CREATE TRIGGER tr BEFORE UPDATE ON t FOR EACH ROW SET @x=1;
      UPDATE t2, t SET t.f=NULL;
      SELECT * FROM t;
      

      MTR Testcase

      SET sql_mode='STRICT_ALL_TABLES';
      CREATE TABLE t (f INT NOT NULL);
      CREATE TABLE t2 (g INT);
      INSERT INTO t VALUES (5);
      INSERT INTO t2 VALUES (5);
      --error ER_BAD_NULL_ERROR
      UPDATE t2, t SET t.f=NULL;
      CREATE TRIGGER tr BEFORE UPDATE ON t FOR EACH ROW SET @x=1;
      --error ER_BAD_NULL_ERROR
      UPDATE t2, t SET t.f=NULL;
       
      #Cleanup
      DROP TABLE t, t2;
      SET sql_mode=DEFAULT;
      

      CLI Output

      13.2.0-opt>SET sql_mode='STRICT_ALL_TABLES';
      Query OK, 0 rows affected (0.000 sec)
       
      13.2.0-opt>CREATE TABLE t (f INT NOT NULL);
      Query OK, 0 rows affected (0.008 sec)
       
      13.2.0-opt>CREATE TABLE t2 (g INT);
      Query OK, 0 rows affected (0.006 sec)
       
      13.2.0-opt>INSERT INTO t VALUES (5);
      Query OK, 1 row affected (0.001 sec)
       
      13.2.0-opt>INSERT INTO t2 VALUES (5);
      Query OK, 1 row affected (0.001 sec)
       
      13.2.0-opt>UPDATE t2, t SET t.f=NULL;
      ERROR 1048 (23000): Column 'f' cannot be null
      13.2.0-opt>CREATE TRIGGER tr BEFORE UPDATE ON t FOR EACH ROW SET @x=1;
      Query OK, 0 rows affected (0.005 sec)
       
      13.2.0-opt>UPDATE t2, t SET t.f=NULL;
      Query OK, 1 row affected (0.001 sec)
      Rows matched: 1  Changed: 1  Warnings: 0
       
      13.2.0-opt>SELECT * FROM t;
      +---+
      | f |
      +---+
      | 0 |
      +---+
      1 row in set (0.000 sec)
       
      13.2.0-opt>
      

      Attachments

        Activity

          People

            shulga Dmitry Shulga
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.