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

Redundant truncation errors/warnings with optimizer_trace enabled

Details

    Description

      The problem is repeatable with at least MyISAM and InnoDB.

      SET @@optimizer_trace='enabled=on';
       
      CREATE OR REPLACE TABLE t1 (
        a CHAR(2) NOT NULL PRIMARY KEY,
        b VARCHAR(20) NOT NULL,
        KEY (b)
      ) ENGINE=InnoDB CHARSET=utf8mb4;
       
      CREATE  OR REPLACE TABLE t2 (
        a CHAR(2) NOT NULL PRIMARY KEY,
        b VARCHAR(20) NOT NULL,
        KEY (b)
      ) ENGINE=InnoDB CHARSET=utf8mb4;
       
      INSERT INTO t1 VALUES
      ('AB','MySQLAB'),
      ('JA','Sun Microsystems'),
      ('MS','Microsoft'),
      ('IB','IBM- Inc.'),
      ('GO','Google Inc.');
       
      INSERT IGNORE INTO t2 VALUES
      ('AB','Sweden'),
      ('JA','USA'),
      ('MS','United States of America'),
      ('IB','North America'),
      ('GO','South America');
       
      UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
      

      ERROR 1406 (22001): Data too long for column 'b' at row 1
      

      The above error is not expected.

      Additionally, in some versions (at least 11.3 and higher), warnings are produced in a simpler script:

      SET @@optimizer_trace='enabled=on';
       
      CREATE OR REPLACE TABLE t1 (
        a CHAR(2) NOT NULL PRIMARY KEY,
        b VARCHAR(20) NOT NULL,
        KEY (b)
      ) ENGINE=InnoDB CHARSET=utf8mb4;
       
      INSERT INTO t1 VALUES
      ('AB','MySQLAB'),
      ('JA','Sun Microsystems'),
      ('MS','Microsoft'),
      ('IB','IBM- Inc.'),
      ('GO','Google Inc.');
       
      UPDATE t1 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
      

      +---------+------+----------------------------------------+
      | Level   | Code | Message                                |
      +---------+------+----------------------------------------+
      | Warning | 1265 | Data truncated for column 'b' at row 1 |
      | Warning | 1265 | Data truncated for column 'b' at row 1 |
      | Warning | 1265 | Data truncated for column 'b' at row 1 |
      | Warning | 1265 | Data truncated for column 'b' at row 1 |
      +---------+------+----------------------------------------+
      

      These warnings are not expected.

      The problem seems to be in the fact that the call for like_range() in Item_func_like::get_mm_leaf() produces more characters than the size of the index.

      The patch below fixes the problem, but the real patch should probably fix like_range() not to return more characters than the size of the index.

      index 5793b19f695..108b4ac78ae 100644
      --- a/sql/opt_range.cc
      +++ b/sql/opt_range.cc
      @@ -9174,6 +9174,19 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param,
                                          &min_length, &max_length))
           DBUG_RETURN(0);              // Can't optimize with LIKE
       
      +  min_length= Well_formed_prefix(field->charset(),
      +                                 (const char *) min_str + offset, min_length,
      +                                 field->char_length()).length();
      +  max_length= Well_formed_prefix(field->charset(),
      +                                 (const char *) max_str + offset, max_length,
      +                                 field->char_length()).length();
         if (offset != maybe_null)                    // BLOB or VARCHAR
         {
           int2store(min_str + maybe_null, min_length);
      
      

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            Description {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            CREATE OR REPLACE TABLE t2 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            INSERT IGNORE INTO t2 VALUES
            ('AB','Sweden'),
            ('JA','USA'),
            ('MS','United States of America'),
            ('IB','North America'),
            ('GO','South America');

            UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            ERROR 1406 (22001): Data too long for column 'b' at row 1
            {noformat}

            The above error is not expected.



            Additionally, in some versions (at least 11.3 and higher), warnings are produced in a simpler script:

            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            UPDATE t1 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            +---------+------+----------------------------------------+
            | Level | Code | Message |
            +---------+------+----------------------------------------+
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            +---------+------+----------------------------------------+
            {noformat}
            These warnings are not expected.

            The problem seems to be in the fact that the call for *{{like_range()}}* in *{{Item_func_like::get_mm_leaf}}* produces more characters than the size of the index.

            The patch below fixes the problem, but the real patch should probably fix *{{like_range()}}* not to return more characters than the size of the index.

            {code:cpp}
            index 5793b19f695..108b4ac78ae 100644
            --- a/sql/opt_range.cc
            +++ b/sql/opt_range.cc
            @@ -9174,6 +9174,19 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param,
                                                &min_length, &max_length))
                 DBUG_RETURN(0); // Can't optimize with LIKE
             
            + min_length= Well_formed_prefix(field->charset(),
            + (const char *) min_str + offset, min_length,
            + field->char_length()).length();
            + max_length= Well_formed_prefix(field->charset(),
            + (const char *) max_str + offset, max_length,
            + field->char_length()).length();
               if (offset != maybe_null) // BLOB or VARCHAR
               {
                 int2store(min_str + maybe_null, min_length);

            {code}
            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            CREATE OR REPLACE TABLE t2 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            INSERT IGNORE INTO t2 VALUES
            ('AB','Sweden'),
            ('JA','USA'),
            ('MS','United States of America'),
            ('IB','North America'),
            ('GO','South America');

            UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            ERROR 1406 (22001): Data too long for column 'b' at row 1
            {noformat}

            The above error is not expected.



            Additionally, in some versions (at least 11.3 and higher), warnings are produced in a simpler script:

            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            UPDATE t1 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            +---------+------+----------------------------------------+
            | Level | Code | Message |
            +---------+------+----------------------------------------+
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            +---------+------+----------------------------------------+
            {noformat}
            These warnings are not expected.

            The problem seems to be in the fact that the call for *{{like_range()}}* in *{{Item_func_like::get_mm_leaf()}}* produces more characters than the size of the index.

            The patch below fixes the problem, but the real patch should probably fix *{{like_range()}}* not to return more characters than the size of the index.

            {code:cpp}
            index 5793b19f695..108b4ac78ae 100644
            --- a/sql/opt_range.cc
            +++ b/sql/opt_range.cc
            @@ -9174,6 +9174,19 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param,
                                                &min_length, &max_length))
                 DBUG_RETURN(0); // Can't optimize with LIKE
             
            + min_length= Well_formed_prefix(field->charset(),
            + (const char *) min_str + offset, min_length,
            + field->char_length()).length();
            + max_length= Well_formed_prefix(field->charset(),
            + (const char *) max_str + offset, max_length,
            + field->char_length()).length();
               if (offset != maybe_null) // BLOB or VARCHAR
               {
                 int2store(min_str + maybe_null, min_length);

            {code}
            bar Alexander Barkov made changes -
            bar Alexander Barkov made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            bar Alexander Barkov made changes -
            bar Alexander Barkov made changes -
            bar Alexander Barkov made changes -
            Description {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            CREATE OR REPLACE TABLE t2 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            INSERT IGNORE INTO t2 VALUES
            ('AB','Sweden'),
            ('JA','USA'),
            ('MS','United States of America'),
            ('IB','North America'),
            ('GO','South America');

            UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            ERROR 1406 (22001): Data too long for column 'b' at row 1
            {noformat}

            The above error is not expected.



            Additionally, in some versions (at least 11.3 and higher), warnings are produced in a simpler script:

            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            UPDATE t1 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            +---------+------+----------------------------------------+
            | Level | Code | Message |
            +---------+------+----------------------------------------+
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            +---------+------+----------------------------------------+
            {noformat}
            These warnings are not expected.

            The problem seems to be in the fact that the call for *{{like_range()}}* in *{{Item_func_like::get_mm_leaf()}}* produces more characters than the size of the index.

            The patch below fixes the problem, but the real patch should probably fix *{{like_range()}}* not to return more characters than the size of the index.

            {code:cpp}
            index 5793b19f695..108b4ac78ae 100644
            --- a/sql/opt_range.cc
            +++ b/sql/opt_range.cc
            @@ -9174,6 +9174,19 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param,
                                                &min_length, &max_length))
                 DBUG_RETURN(0); // Can't optimize with LIKE
             
            + min_length= Well_formed_prefix(field->charset(),
            + (const char *) min_str + offset, min_length,
            + field->char_length()).length();
            + max_length= Well_formed_prefix(field->charset(),
            + (const char *) max_str + offset, max_length,
            + field->char_length()).length();
               if (offset != maybe_null) // BLOB or VARCHAR
               {
                 int2store(min_str + maybe_null, min_length);

            {code}
            The problem is repeatable with at least MyISAM and InnoDB.

            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            CREATE OR REPLACE TABLE t2 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            INSERT IGNORE INTO t2 VALUES
            ('AB','Sweden'),
            ('JA','USA'),
            ('MS','United States of America'),
            ('IB','North America'),
            ('GO','South America');

            UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            ERROR 1406 (22001): Data too long for column 'b' at row 1
            {noformat}

            The above error is not expected.



            Additionally, in some versions (at least 11.3 and higher), warnings are produced in a simpler script:

            {code:sql}
            SET @@optimizer_trace='enabled=on';

            CREATE OR REPLACE TABLE t1 (
              a CHAR(2) NOT NULL PRIMARY KEY,
              b VARCHAR(20) NOT NULL,
              KEY (b)
            ) ENGINE=InnoDB CHARSET=utf8mb4;

            INSERT INTO t1 VALUES
            ('AB','MySQLAB'),
            ('JA','Sun Microsystems'),
            ('MS','Microsoft'),
            ('IB','IBM- Inc.'),
            ('GO','Google Inc.');

            UPDATE t1 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'Unknown%';
            {code}
            {noformat}
            +---------+------+----------------------------------------+
            | Level | Code | Message |
            +---------+------+----------------------------------------+
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            | Warning | 1265 | Data truncated for column 'b' at row 1 |
            +---------+------+----------------------------------------+
            {noformat}
            These warnings are not expected.

            The problem seems to be in the fact that the call for *{{like_range()}}* in *{{Item_func_like::get_mm_leaf()}}* produces more characters than the size of the index.

            The patch below fixes the problem, but the real patch should probably fix *{{like_range()}}* not to return more characters than the size of the index.

            {code:cpp}
            index 5793b19f695..108b4ac78ae 100644
            --- a/sql/opt_range.cc
            +++ b/sql/opt_range.cc
            @@ -9174,6 +9174,19 @@ Item_func_like::get_mm_leaf(RANGE_OPT_PARAM *param,
                                                &min_length, &max_length))
                 DBUG_RETURN(0); // Can't optimize with LIKE
             
            + min_length= Well_formed_prefix(field->charset(),
            + (const char *) min_str + offset, min_length,
            + field->char_length()).length();
            + max_length= Well_formed_prefix(field->charset(),
            + (const char *) max_str + offset, max_length,
            + field->char_length()).length();
               if (offset != maybe_null) // BLOB or VARCHAR
               {
                 int2store(min_str + maybe_null, min_length);

            {code}
            bar Alexander Barkov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            bar Alexander Barkov made changes -
            Assignee Alexander Barkov [ bar ] Sergei Golubchik [ serg ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            bar Alexander Barkov made changes -
            Assignee Sergei Golubchik [ serg ] Alexander Barkov [ bar ]
            bar Alexander Barkov made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            bar Alexander Barkov made changes -
            Fix Version/s 10.5.26 [ 29832 ]
            Fix Version/s 10.5 [ 23123 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            bar Alexander Barkov made changes -
            Comment [ [~serg], Please review a patch for 10.5:

            https://github.com/MariaDB/server/commit/0104c7639c98fa2db9ca13a3ce47079917759ad3 ]
            bar Alexander Barkov made changes -
            Fix Version/s 10.6.19 [ 29833 ]
            Fix Version/s 10.11.9 [ 29834 ]
            Fix Version/s 11.1.6 [ 29835 ]
            Fix Version/s 11.2.5 [ 29836 ]
            Fix Version/s 11.4.3 [ 29837 ]
            Fix Version/s 11.5.2 [ 29838 ]
            Fix Version/s 11.6.0 [ 29839 ]

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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