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

Condition propagation does not work for temporal types

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.5.40, 10.0.14, 10.1.1
    • Fix Version/s: 10.1
    • Component/s: Optimizer
    • Labels:
      None

      Description

      Condition propagation works for string and numeric data types:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (c1 VARCHAR(10));
      INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02');
      EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='2001-01-01' AND CONCAT(c1)>'2002-01-01';
      

      The above script correctly detects impossible condition:

      +------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra            |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
      |    1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | Impossible WHERE |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
      

      But in case of temporal data types, it does not work:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (c1 DATE);
      INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02');
      EXPLAIN EXTENDED SELECT * FROM t1 WHERE TIMESTAMP(c1)=TIMESTAMP'2001-01-01 00:00:00' AND TIMESTAMP(c1)>TIMESTAMP'2002-01-01 00:00:00';
      SHOW WARNINGS;
      

      It does not detect that the condition is not possible:

      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    2 |   100.00 | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Level | Code | Message                                                                                                                                                                                                  |
      +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Note  | 1003 | select `test`.`t1`.`c1` AS `c1` from `test`.`t1` where ((cast(`test`.`t1`.`c1` as datetime) = TIMESTAMP'2001-01-01 00:00:00') and (cast(`test`.`t1`.`c1` as datetime) > TIMESTAMP'2002-01-01 00:00:00')) |
      +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      

      It's going to scan the entire table.

      The problem happens because clone_item() returns NULL for temporal literals. It should be rewritten to do true cloning.

        Gliffy Diagrams

          Attachments

            Activity

            There are no comments yet on this issue.

              People

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

                Dates

                • Created:
                  Updated: