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

Multi-UPDATE does not report truncated fields correctly

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5(EOL), 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11
    • 10.6, 10.11
    • None

    Description

      This script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (1);
      UPDATE t1 SET t1.a='';

      correctly reports 1 warning:

      Rows matched: 1  Changed: 1  Warnings: 1

      Looks correct so far.

      Now I change the script slightly, to use a multi-UPDATE statement:

      DROP TABLE IF EXISTS t1,t2;
      CREATE TABLE t1 (a INT);
      CREATE TABLE t2(a INT);
      INSERT INTO t1 VALUES (1);
      INSERT INTO t2 VALUES (1);
      UPDATE t1,t2 SET t1.a='';

      it reports no warnings:

      Rows matched: 1  Changed: 1  Warnings: 0

      A related problem:

      DROP FUNCTION IF EXISTS f1;
      DELIMITER //
      CREATE FUNCTION f1 (a VARCHAR(20)) RETURNS INT
      BEGIN
        DECLARE d INT;
        SET d= a;
        SET d= a;
        SET d= a; // Assign 3 times, to have multiple truncations on a bad string argument
        RETURN d;
      END;
      //
      DELIMITER ;
      SELECT f1('123x');
       
      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (0);
      UPDATE t1 SET a=f1('123x');
      UPDATE t1, t1 t2 SET t1.a=f1('123x');

      The above script returns:

      MariaDB [test]> UPDATE t1 SET a=f1('123x');
      Query OK, 1 row affected (0.03 sec)
      Rows matched: 1  Changed: 1  Warnings: 0
       
      MariaDB [test]> UPDATE t1, t1 t2 SET t1.a=f1('123x');
      Query OK, 0 rows affected (0.04 sec)
      Rows matched: 1  Changed: 0  Warnings: 3

      The multi-table UPDATE incorrectly says "Warnings: 3" , that is it counted the truncations that happened inside SP. It should only count the number of truncations that happened in fields, which is 0.

      Attachments

        Activity

          People

            bar Alexander Barkov
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.