[MDEV-12432] Range optimizer for ENUM and SET does not return "Impossible WHERE" in some case Created: 2017-04-03  Updated: 2017-04-25  Resolved: 2017-04-25

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.1, 10.2, 10.3
Fix Version/s: 10.3.1

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-8787 Return Impossible WHERE instead of Fu... Open

 Description   

This script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a ENUM('a','b','c','1'),KEY(a));
INSERT INTO t1 VALUES ('a'),('b'),('c'),('1');
EXPLAIN SELECT * FROM t1 WHERE a=100.1e0;

returns

+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                                               |
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|    1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE noticed after reading const tables |
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+

Looks correct. The constant 100.1e0 will never return any rows from the column t1.a.

However, if I test more impossible constants of various data types:

EXPLAIN SELECT * FROM t1 WHERE a=100;
EXPLAIN SELECT * FROM t1 WHERE a=100.1;
EXPLAIN SELECT * FROM t1 WHERE a='xx';
EXPLAIN SELECT * FROM t1 WHERE a='99999999';
EXPLAIN SELECT * FROM t1 WHERE a='100';
EXPLAIN SELECT * FROM t1 WHERE a='1x';
EXPLAIN SELECT * FROM t1 WHERE a='1.0';
EXPLAIN SELECT * FROM t1 WHERE a='1.1';

it does not detect Impossible WHERE and is going to do range search:

+------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+
| 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 |
+------+-------------+-------+------+---------------+------+---------+-------+------+--------------------------+



 Comments   
Comment by Alexander Barkov [ 2017-04-25 ]

Pushed to bb-10.2-ext

Generated at Thu Feb 08 07:57:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.