Skip to content

Commit

Permalink
MDEV-32958 Unusable key notes do not get reported for some operations
Browse files Browse the repository at this point in the history
Enable unusable key notes for non-equality predicates:
   <, <=, =>, >, BETWEEN, IN, LIKE

Note, in some scenarios it displays duplicate notes, e.g.
for queries with ORDER BY:

  SELECT * FROM t1
  WHERE    indexed_string_column >= 10
  ORDER BY indexed_string_column
  LIMIT 5;

This should be tolarable. Getting rid of the diplicate note
completely would need a much more complex patch, which is
not desiable in 10.6.

Details:

- Changing RANGE_OPT_PARAM::note_unusable_keys from bool
  to a new data type Item_func::Bitmap, so the caller can
  choose with a better granuality which predicates
  should raise unusable key notes inside the range optimizer:
    a. all predicates (=, <=>, <, <=, =>, >, BETWEEN, IN, LIKE)
    b. all predicates except equality (=, <=>)
    c. none of the predicates

  "b." is needed because in some scenarios equality predicates (=, <=>)
  send unusable key notes at an earlier stage, before the range optimizer,
  during update_ref_and_keys(). Calling the range optimizer with
  "all predicates" would produce duplicate notes for = and <=> in such cases.

- Fixing get_quick_record_count() to call the range optimizer
  with "all predicates except equality" instead of "none of the predicates".
  Before this change the range optimizer suppressed all notes for
  non-equality predicates: <, <=, =>, >, BETWEEN, IN, LIKE.
  This actually fixes the reported problem.

- Fixing JOIN::make_range_rowid_filters() to call the range optimizer
  with "all predicates except equality" instead of "all predicates".
  Before this change the range optimizer produced duplicate notes
  for = and <=> during a rowid_filter optimization.

- Cleanup:
  Adding the op_collation argument to Field::raise_note_cannot_use_key_part()
  and displaying the operation collation rather than the argument collation
  in the unusable key note. This is important for operations with more than
  two arguments: BETWEEN and IN, e.g.:

    SELECT * FROM t1
    WHERE column_utf8mb3_general_ci
          BETWEEN 'a' AND 'b' COLLATE utf8mb3_unicode_ci;

    SELECT * FROM t1
    WHERE column_utf8mb3_general_ci
          IN ('a', 'b' COLLATE utf8mb3_unicode_ci);

    The note for 'a' now prints utf8mb3_unicode_ci as the collation.
    which is the collation of the entire operation:

      Cannot use key key1 part[0] for lookup:
      "`column_utf8mb3_general_ci`" of collation `utf8mb3_general_ci` >=
      "'a'" of collation `utf8mb3_unicode_ci`

    Before this change it printed the collation of 'a',
    so the note was confusing:

      Cannot use key key1 part[0] for lookup:
      "`column_utf8mb3_general_ci`" of collation `utf8mb3_general_ci` >=
      "'a'" of collation `utf8mb3_general_ci`"
  • Loading branch information
abarkov committed Dec 11, 2023
1 parent bc5e904 commit 4ced489
Show file tree
Hide file tree
Showing 20 changed files with 412 additions and 25 deletions.
6 changes: 6 additions & 0 deletions mysql-test/main/ctype_collate.result
Expand Up @@ -614,18 +614,24 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE s2 BETWEEN 'a' AND 'b' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` >= "'a'" of collation `latin1_german1_ci`
EXPLAIN SELECT * FROM t1 WHERE s1 IN ('a','b' COLLATE latin1_german1_ci);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range s1 s1 11 NULL 2 Using index condition
EXPLAIN SELECT * FROM t1 WHERE s2 IN ('a','b' COLLATE latin1_german1_ci);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` = "'a'" of collation `latin1_german1_ci`
EXPLAIN SELECT * FROM t1 WHERE s1 LIKE 'a' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range s1 s1 11 NULL 1 Using index condition
EXPLAIN SELECT * FROM t1 WHERE s2 LIKE 'a' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` like "'a' collate latin1_german1_ci" of collation `latin1_german1_ci`
DROP TABLE t1;
create table t1(f1 varchar(10) character set latin2 collate latin2_hungarian_ci, key(f1));
insert into t1 set f1=0x3F3F9DC73F;
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/main/func_in.result
Expand Up @@ -531,6 +531,8 @@ Warning 1292 Truncated incorrect DECIMAL value: 'b'
explain select f1 from t1 where f1 in (2,1);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index t1f1_idx t1f1_idx 2 NULL 3 Using where; Using index
Warnings:
Note 1105 Cannot use key `t1f1_idx` part[0] for lookup: `test`.`t1`.`f1` of type `char` = "2" of type `int`
create table t2(f2 int, index t2f2(f2));
insert into t2 values(0),(1),(2);
select f2 from t2 where f2 in ('a',2);
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/main/group_min_max.result
Expand Up @@ -3298,6 +3298,8 @@ explain
SELECT b, min(a) FROM t1 WHERE a > ('0' = b) AND b = 'z' GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 4 const 1 Using where; Using index
Warnings:
Note 1105 Cannot use key `b` part[1] for lookup: `test`.`t1`.`a` of type `varchar` > "'0' = 'z'" of type `boolean`
SELECT b, min(a) FROM t1 WHERE a > ('0' = b) AND b = 'z' GROUP BY b;
b min(a)
explain
Expand Down Expand Up @@ -3984,12 +3986,18 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN DATE'2001-01-04' AND DATE'2001-01-05' GROUP BY id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 27 NULL 64 Using where; Using index
Warnings:
Note 1105 Cannot use key `id` part[1] for lookup: `test`.`t1`.`a` of type `varchar` >= "DATE'2001-01-04'" of type `date`
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN DATE'2001-01-04' AND '2001-01-05' GROUP BY id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 27 NULL 64 Using where; Using index
Warnings:
Note 1105 Cannot use key `id` part[1] for lookup: `test`.`t1`.`a` of type `varchar` >= "DATE'2001-01-04'" of type `date`
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN '2001-01-04' AND DATE'2001-01-05' GROUP BY id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 27 NULL 64 Using where; Using index
Warnings:
Note 1105 Cannot use key `id` part[1] for lookup: `test`.`t1`.`a` of type `varchar` >= "<cache>('2001-01-04')" of type `date`
DROP TABLE t1;
#
# MIN() optimization didn't work correctly with BETWEEN when using too
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/main/mrr_icp_extra.result
Expand Up @@ -38,18 +38,24 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE s2 BETWEEN 'a' AND 'b' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` >= "'a'" of collation `latin1_german1_ci`
EXPLAIN SELECT * FROM t1 WHERE s1 IN ('a','b' COLLATE latin1_german1_ci);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range s1 s1 11 NULL 2 Using index condition; Rowid-ordered scan
EXPLAIN SELECT * FROM t1 WHERE s2 IN ('a','b' COLLATE latin1_german1_ci);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` = "'a'" of collation `latin1_german1_ci`
EXPLAIN SELECT * FROM t1 WHERE s1 LIKE 'a' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range s1 s1 11 NULL 1 Using index condition; Rowid-ordered scan
EXPLAIN SELECT * FROM t1 WHERE s2 LIKE 'a' COLLATE latin1_german1_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL s2 NULL NULL NULL 10 Using where
Warnings:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` like "'a' collate latin1_german1_ci" of collation `latin1_german1_ci`
DROP TABLE t1;
#
#
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/main/myisam_explain_non_select_all.result
Expand Up @@ -1528,6 +1528,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
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 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
Expand Down Expand Up @@ -1591,6 +1593,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
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 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
Expand Down Expand Up @@ -2142,6 +2146,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
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` <= "18" 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 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
Variable_name Value
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/main/subselect4.result
Expand Up @@ -1892,6 +1892,8 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY SUBQUERY2_t1 index NULL col_int_key 5 NULL 2 Using index
2 SUBQUERY SUBQUERY2_t2 ALL col_varchar_key NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
Warnings:
Note 1105 Cannot use key `col_varchar_key` part[0] for lookup: `test`.`t1`.`col_varchar_key` of type `varchar` < "0" of type `bigint`
SELECT col_int_key
FROM t2
WHERE (SELECT SUBQUERY2_t1.col_int_key
Expand All @@ -1917,6 +1919,8 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY SUBQUERY2_t1 index NULL col_int_key 5 NULL 2 Using index
2 SUBQUERY SUBQUERY2_t2 ALL col_varchar_key NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
Warnings:
Note 1105 Cannot use key `col_varchar_key` part[0] for lookup: `test`.`t1`.`col_varchar_key` of type `varchar` < "0" of type `bigint`
SELECT col_int_key
FROM t2
WHERE (SELECT SUBQUERY2_t1.col_int_key
Expand Down
207 changes: 207 additions & 0 deletions mysql-test/main/type_varchar.result
Expand Up @@ -967,10 +967,217 @@ 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`
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`
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;
#
# MDEV-32958 Unusable key notes do not get reported for some operations
#
SET note_verbosity=unusable_keys;
CREATE TABLE t1 (c1 varchar(10), KEY(c1)) CHARACTER SET latin1;
INSERT INTO t1 VALUES ('a');
INSERT INTO t1 VALUES ('b');
INSERT INTO t1 VALUES ('c');
INSERT INTO t1 VALUES ('d');
INSERT INTO t1 VALUES ('e');
INSERT INTO t1 VALUES ('f');
INSERT INTO t1 VALUES ('g');
INSERT INTO t1 VALUES ('h');
INSERT INTO t1 VALUES ('i');
INSERT INTO t1 VALUES ('j');
EXPLAIN SELECT * FROM t1 WHERE c1=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` = "10" of type `int`
SELECT * FROM t1 WHERE c1=10;
c1
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` = "10" of type `int`
Warning 1292 Truncated incorrect DECIMAL value: 'a'
Warning 1292 Truncated incorrect DECIMAL value: 'b'
Warning 1292 Truncated incorrect DECIMAL value: 'c'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
Warning 1292 Truncated incorrect DECIMAL value: 'e'
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'g'
Warning 1292 Truncated incorrect DECIMAL value: 'h'
Warning 1292 Truncated incorrect DECIMAL value: 'i'
Warning 1292 Truncated incorrect DECIMAL value: 'j'
EXPLAIN SELECT * FROM t1 WHERE c1<10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` < "10" of type `int`
SELECT * FROM t1 WHERE c1<10;
c1
a
b
c
d
e
f
g
h
i
j
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` < "10" of type `int`
Warning 1292 Truncated incorrect DECIMAL value: 'a'
Warning 1292 Truncated incorrect DECIMAL value: 'b'
Warning 1292 Truncated incorrect DECIMAL value: 'c'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
Warning 1292 Truncated incorrect DECIMAL value: 'e'
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'g'
Warning 1292 Truncated incorrect DECIMAL value: 'h'
Warning 1292 Truncated incorrect DECIMAL value: 'i'
Warning 1292 Truncated incorrect DECIMAL value: 'j'
EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 10 AND 11;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` >= "10" of type `int`
SELECT * FROM t1 WHERE c1 BETWEEN 10 AND 11;
c1
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` >= "10" of type `int`
Warning 1292 Truncated incorrect DECIMAL value: 'a'
Warning 1292 Truncated incorrect DECIMAL value: 'b'
Warning 1292 Truncated incorrect DECIMAL value: 'c'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
Warning 1292 Truncated incorrect DECIMAL value: 'e'
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'g'
Warning 1292 Truncated incorrect DECIMAL value: 'h'
Warning 1292 Truncated incorrect DECIMAL value: 'i'
Warning 1292 Truncated incorrect DECIMAL value: 'j'
EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 10 AND '11';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` >= "10" of type `int`
SELECT * FROM t1 WHERE c1 BETWEEN 10 AND '11';
c1
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` >= "10" of type `int`
Warning 1292 Truncated incorrect DOUBLE value: 'a'
Warning 1292 Truncated incorrect DOUBLE value: 'b'
Warning 1292 Truncated incorrect DOUBLE value: 'c'
Warning 1292 Truncated incorrect DOUBLE value: 'd'
Warning 1292 Truncated incorrect DOUBLE value: 'e'
Warning 1292 Truncated incorrect DOUBLE value: 'f'
Warning 1292 Truncated incorrect DOUBLE value: 'g'
Warning 1292 Truncated incorrect DOUBLE value: 'h'
Warning 1292 Truncated incorrect DOUBLE value: 'i'
Warning 1292 Truncated incorrect DOUBLE value: 'j'
EXPLAIN SELECT * FROM t1 WHERE c1 IN (10,20);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` = "10" of type `int`
SELECT * FROM t1 WHERE c1 IN (10,20);
c1
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of type `varchar` = "10" of type `int`
Warning 1292 Truncated incorrect DECIMAL value: 'a'
Warning 1292 Truncated incorrect DECIMAL value: 'b'
Warning 1292 Truncated incorrect DECIMAL value: 'c'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
Warning 1292 Truncated incorrect DECIMAL value: 'e'
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'g'
Warning 1292 Truncated incorrect DECIMAL value: 'h'
Warning 1292 Truncated incorrect DECIMAL value: 'i'
Warning 1292 Truncated incorrect DECIMAL value: 'j'
EXPLAIN SELECT * FROM t1 WHERE c1 IN (_latin1'a' COLLATE latin1_german2_ci,'b');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of collation `latin1_swedish_ci` = "_latin1'a' collate latin1_german2_ci" of collation `latin1_german2_ci`
SELECT * FROM t1 WHERE c1 IN (_latin1'a' COLLATE latin1_german2_ci,'b');
c1
a
b
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of collation `latin1_swedish_ci` = "_latin1'a' collate latin1_german2_ci" of collation `latin1_german2_ci`
EXPLAIN SELECT * FROM t1 WHERE c1 IN ('a',_latin1'b' COLLATE latin1_german2_ci);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index c1 c1 13 NULL 10 Using where; Using index
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of collation `latin1_swedish_ci` = "'a'" of collation `latin1_german2_ci`
SELECT * FROM t1 WHERE c1 IN ('a',_latin1'b' COLLATE latin1_german2_ci);
c1
a
b
Warnings:
Note 1105 Cannot use key `c1` part[0] for lookup: `test`.`t1`.`c1` of collation `latin1_swedish_ci` = "'a'" of collation `latin1_german2_ci`
DROP TABLE t1;
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);
EXPLAIN SELECT * FROM t1 WHERE i >= 10 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 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` >= "10" of type `int`
SELECT * FROM t1 WHERE i >= 10 ORDER BY i LIMIT 5;
a i
NULL 10
NULL 11
NULL 12
NULL 13
NULL 14
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`
EXPLAIN UPDATE t1 SET a = 1 WHERE i = 10 ORDER BY a, 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`
EXPLAIN UPDATE t1 SET a = 1 WHERE i < 10 ORDER BY a, 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`
EXPLAIN DELETE FROM t1 WHERE i = 10 ORDER BY a, 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`
EXPLAIN DELETE FROM t1 WHERE i < 10 ORDER BY a, 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`
EXPLAIN UPDATE t1 SET a = 1 WHERE i = 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` = "10" of type `int`
EXPLAIN UPDATE t1 SET a = 1 WHERE i < 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` < "10" of type `int`
EXPLAIN DELETE FROM t1 WHERE i = 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` = "10" of type `int`
EXPLAIN DELETE FROM t1 WHERE i < 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where
Warnings:
Note 1105 Cannot use key `i` part[0] for lookup: `test`.`t1`.`i` of type `char` < "10" of type `int`
DROP TABLE t1;
SET note_verbosity=DEFAULT;

0 comments on commit 4ced489

Please sign in to comment.