1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-18898 SELECT using wrong index when using operator IN with mixed types

These patches:

  # commit 74891ed257
  #
  #  MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems

  # commit 53499cd1ea
  #
  # MDEV-31303 Key not used when IN clause has both signed and usigned values

earlier fixed MDEV-18898.

Adding only an MTR case.

	modified:   mysql-test/main/func_in.result
	modified:   mysql-test/main/func_in.test
This commit is contained in:
Alexander Barkov
2024-04-09 14:18:29 +04:00
parent 7aa86eb1e1
commit d4936c8b26
2 changed files with 93 additions and 0 deletions

View File

@ -1003,5 +1003,59 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 2 Using where; Using index
DROP TABLE t1;
#
# MDEV-18898 SELECT using wrong index when using operator IN with mixed types
#
CREATE TEMPORARY TABLE t1 (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
);
FOR i IN 1..255
DO
INSERT INTO t1 VALUES (i, MD5(i));
END FOR
$$
#
# Constants alone
#
ANALYZE SELECT id, name FROM t1 WHERE id = 1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL
ANALYZE SELECT id, name FROM t1 WHERE id = '2';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL
#
# Two constants using IN
#
ANALYZE SELECT id, name FROM t1 WHERE id IN (1, 2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', 2) /* Used a wrong index */;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id IN (1, '2') /* Used a wrong index */;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id IN ('1', '2');
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
#
# Two constants using OR
#
ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = 2;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = '2';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id = 1 OR id = '2';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
ANALYZE SELECT id, name FROM t1 WHERE id = '1' OR id = 2;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 2.00 100.00 100.00 Using index condition
DROP TABLE t1;
#
# End of 10.5 tests
#