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

Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010

    Details

      Description

      This script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT ZEROFILL);
      INSERT INTO t1 VALUES (2010),(2020);
      EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
      SHOW WARNINGS;
      

      returns

      +-------+------+---------------------------------------------------------------------------------------+
      | Level | Code | Message                                                                               |
      +-------+------+---------------------------------------------------------------------------------------+
      | Note  | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and 1) |
      +-------+------+---------------------------------------------------------------------------------------+
      

      Notice, the a>=2010 part was simplified to constant, but the constant was not removed.

      The same problems is repeatable with the YEAR data type:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a YEAR);
      INSERT INTO t1 VALUES (2010),(2020);
      EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
      SHOW WARNINGS;
      

      If I use "INT" instead of "INT ZEROFILL" or "YEAR", it works as expected:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (2010),(2020);
      EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
      SHOW WARNINGS;
      

      returns:

      +-------+------+-------------------------------------------------------------------------------+
      | Level | Code | Message                                                                       |
      +-------+------+-------------------------------------------------------------------------------+
      | Note  | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010) |
      +-------+------+-------------------------------------------------------------------------------+
      

      as expected.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              bar Alexander Barkov added a comment -

              MySQL-5.7.8 does not seem to remove the constant part (the result of propagation) from the WHERE condition:

              DROP TABLE IF EXISTS t1;
              CREATE TABLE t1 (a INT ZEROFILL);
              INSERT INTO t1 VALUES (2010),(2020);
              EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
              SHOW WARNINGS;
              

              returns

              +---------+------+-------------------------------------------------------------------------------------------------------------------+
              | Level   | Code | Message                                                                                                           |
              +---------+------+-------------------------------------------------------------------------------------------------------------------+
              | Warning | 1681 | 'EXTENDED' is deprecated and will be removed in a future release.                                                 |
              | Note    | 1003 | /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and (2010 >= 2010)) |
              +---------+------+-------------------------------------------------------------------------------------------------------------------
              
              Show
              bar Alexander Barkov added a comment - MySQL-5.7.8 does not seem to remove the constant part (the result of propagation) from the WHERE condition: DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a INT ZEROFILL); INSERT INTO t1 VALUES (2010),(2020); EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010; SHOW WARNINGS; returns +---------+------+-------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------------------------------------------------------------+ | Warning | 1681 | 'EXTENDED' is deprecated and will be removed in a future release. | | Note | 1003 | /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and (2010 >= 2010)) | +---------+------+-------------------------------------------------------------------------------------------------------------------

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: