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

Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
    • Fix Version/s: 10.4.0
    • Component/s: Data types, Optimizer
    • Labels:
      None

      Description

      The range optimizer decides to use "ref" search when testing an equality between an indexed integer column and an out-of-range integer constant:

      CREATE OR REPLACE TABLE t1 (a TINYINT, KEY(a));
      INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
      EXPLAIN SELECT * FROM t1 WHERE a=200;
      

      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra                    |
      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      |    1 | SIMPLE      | t1    | ref  | a             | a    | 2       | const |    1 | Using where; Using index |
      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      

      The same happens with the BIT data type:

      CREATE OR REPLACE TABLE t1 (a BIT(7), KEY(a));
      INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
      EXPLAIN SELECT * FROM t1 WHERE a=200;
      

      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra                    |
      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      |    1 | SIMPLE      | t1    | ref  | a             | a    | 2       | const |    1 | Using where; Using index |
      +------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
      

      This is wrong. It should return with "Impossible WHERE".

        Attachments

          Issue Links

            Activity

              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: