[MDEV-32957] Unusable key notes report wrong predicates for > and >= Created: 2023-12-06  Updated: 2023-12-06  Resolved: 2023-12-06

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.6, 11.3
Fix Version/s: 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3, 11.3.2, 11.4.1

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

Issue Links:
Relates
relates to MDEV-32203 Raise notes when an index cannot be u... Closed
relates to MDEV-32958 Unusable key notes do not get reporte... Closed

 Description   

Unusable key notes report wrong predicates for > and >=

SET note_verbosity=unusable_keys;
CREATE OR REPLACE TABLE t1 (a INT, i CHAR(2), KEY(i));
DELIMITER $$
FOR i IN 1..31
DO
  INSERT INTO t1 VALUES (a, 10+i);
END FOR;
$$
DELIMITER ;
EXPLAIN SELECT * FROM t1 WHERE i>30 ORDER BY i LIMIT 5;
SHOW WARNINGS;

+-------+------+---------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                     |
+-------+------+---------------------------------------------------------------------------------------------+
|  Note | 1105 | Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "30" of type `int` |
+-------+------+---------------------------------------------------------------------------------------------+

Notice, when the > operator is used, it says >= in the note.

And the other way around:

EXPLAIN SELECT * FROM t1 WHERE i>=30 ORDER BY i LIMIT 5;
SHOW WARNINGS;

+-------+------+--------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                    |
+-------+------+--------------------------------------------------------------------------------------------+
|  Note | 1105 | Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` > "30" of type `int` |
+-------+------+--------------------------------------------------------------------------------------------+

When the >= operator is used, it says > in the note.


Generated at Thu Feb 08 10:35:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.