Commit ecbdd729 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-32957 Unusable key notes report wrong predicates for > and >=

The function scalar_comparison_op_to_lex_cstring() returned
wrong operator names for SCALAR_CMP_GE and SCALAR_CMP_GT.
parent f074223a
...@@ -306,6 +306,19 @@ INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), ...@@ -306,6 +306,19 @@ INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
--source include/explain_utils.inc --source include/explain_utils.inc
DROP TABLE t1; DROP TABLE t1;
--echo #30a
--echo #
--echo # MDEV-32957 Unusable key notes report wrong predicates for > and >=
--echo #
CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
(30),(31),(32),(33),(34),(35);
--let $query = DELETE FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5
--let $select = SELECT * FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5
--source include/explain_utils.inc
DROP TABLE t1;
--echo #31 --echo #31
CREATE TABLE t1 (i INT); CREATE TABLE t1 (i INT);
INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
......
...@@ -1506,7 +1506,7 @@ EXPLAIN DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; ...@@ -1506,7 +1506,7 @@ EXPLAIN DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where; Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int`
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
...@@ -1514,7 +1514,7 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; ...@@ -1514,7 +1514,7 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int`
Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5 Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query # Status of EXPLAIN EXTENDED query
...@@ -1526,7 +1526,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; ...@@ -1526,7 +1526,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort 1 SIMPLE t1 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` <= "18" of type `int`
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5 Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
...@@ -1550,6 +1550,69 @@ Handler_read_rnd_next 27 ...@@ -1550,6 +1550,69 @@ Handler_read_rnd_next 27
Sort_rows 8 Sort_rows 8
Sort_scan 1 Sort_scan 1
DROP TABLE t1;
#30a
#
# MDEV-32957 Unusable key notes report wrong predicates for > and >=
#
CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
(30),(31),(32),(33),(34),(35);
#
# query: DELETE FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5
# select: SELECT * FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5
#
Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
EXPLAIN DELETE FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where; Using filesort
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` < "18" of type `int`
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` < "18" of type `int`
Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` >= 10 and `test`.`t1`.`i` < 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE i >= 10 AND i < 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` < "18" of type `int`
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where `test`.`t1`.`i` >= 10 and `test`.`t1`.`i` < 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
Variable_name Value
Handler_read_key 4
Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution:
Variable_name Value
Handler_read_key 4
Handler_read_rnd_next 27
Sort_priority_queue_sorts 1
Sort_rows 5
Sort_scan 1
# Status of testing query execution:
Variable_name Value
Handler_delete 5
Handler_read_key 4
Handler_read_rnd 5
Handler_read_rnd_next 27
Sort_rows 8
Sort_scan 1
DROP TABLE t1; DROP TABLE t1;
#31 #31
CREATE TABLE t1 (i INT); CREATE TABLE t1 (i INT);
...@@ -2057,7 +2120,7 @@ EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; ...@@ -2057,7 +2120,7 @@ EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int`
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
...@@ -2065,7 +2128,7 @@ EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT ...@@ -2065,7 +2128,7 @@ EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int`
Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query # Status of EXPLAIN EXTENDED query
...@@ -2077,7 +2140,7 @@ EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT ...@@ -2077,7 +2140,7 @@ EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort 1 SIMPLE t2 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort
Warnings: Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` >= "10" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` > "10" of type `int`
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int` Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t2`.`i` of type `char` <= "18" of type `int`
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
......
...@@ -952,3 +952,25 @@ Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten c ...@@ -952,3 +952,25 @@ Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten c
DROP TABLE t2; DROP TABLE t2;
DROP TABLE t1; DROP TABLE t1;
SET note_verbosity=DEFAULT; SET note_verbosity=DEFAULT;
#
# MDEV-32957 Unusable key notes report wrong predicates for > and >=
#
SET note_verbosity=unusable_keys;
CREATE TABLE t1 (a INT, i CHAR(32), KEY(i));
FOR i IN 1..31
DO
INSERT INTO t1 VALUES (i, 10+i);
END FOR;
$$
EXPLAIN SELECT * FROM t1 WHERE i>30 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL i NULL NULL NULL 31 Using where; Using filesort
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` > "30" of type `int`
EXPLAIN SELECT * FROM t1 WHERE i>=30 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL i NULL NULL NULL 31 Using where; Using filesort
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` >= "30" of type `int`
DROP TABLE t1;
SET note_verbosity=DEFAULT;
...@@ -415,3 +415,22 @@ DELIMITER ;$$ ...@@ -415,3 +415,22 @@ DELIMITER ;$$
--source unusable_keys_joins.inc --source unusable_keys_joins.inc
DROP TABLE t1; DROP TABLE t1;
SET note_verbosity=DEFAULT; SET note_verbosity=DEFAULT;
--echo #
--echo # MDEV-32957 Unusable key notes report wrong predicates for > and >=
--echo #
SET note_verbosity=unusable_keys;
CREATE TABLE t1 (a INT, i CHAR(32), KEY(i));
DELIMITER $$;
FOR i IN 1..31
DO
INSERT INTO t1 VALUES (i, 10+i);
END FOR;
$$
DELIMITER ;$$
EXPLAIN SELECT * FROM t1 WHERE i>30 ORDER BY i LIMIT 5;
EXPLAIN SELECT * FROM t1 WHERE i>=30 ORDER BY i LIMIT 5;
DROP TABLE t1;
SET note_verbosity=DEFAULT;
...@@ -151,8 +151,8 @@ scalar_comparison_op_to_lex_cstring(scalar_comparison_op op) ...@@ -151,8 +151,8 @@ scalar_comparison_op_to_lex_cstring(scalar_comparison_op op)
case SCALAR_CMP_EQUAL: return LEX_CSTRING{STRING_WITH_LEN("<=>")}; case SCALAR_CMP_EQUAL: return LEX_CSTRING{STRING_WITH_LEN("<=>")};
case SCALAR_CMP_LT: return LEX_CSTRING{STRING_WITH_LEN("<")}; case SCALAR_CMP_LT: return LEX_CSTRING{STRING_WITH_LEN("<")};
case SCALAR_CMP_LE: return LEX_CSTRING{STRING_WITH_LEN("<=")}; case SCALAR_CMP_LE: return LEX_CSTRING{STRING_WITH_LEN("<=")};
case SCALAR_CMP_GE: return LEX_CSTRING{STRING_WITH_LEN(">")}; case SCALAR_CMP_GE: return LEX_CSTRING{STRING_WITH_LEN(">=")};
case SCALAR_CMP_GT: return LEX_CSTRING{STRING_WITH_LEN(">=")}; case SCALAR_CMP_GT: return LEX_CSTRING{STRING_WITH_LEN(">")};
} }
DBUG_ASSERT(0); DBUG_ASSERT(0);
return LEX_CSTRING{STRING_WITH_LEN("<?>")}; return LEX_CSTRING{STRING_WITH_LEN("<?>")};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment