1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-6679 Different optimizer plan for "a BETWEEN 'string' AND ?" and "a BETWEEN ? AND 'string'"

Item_string::eq() and Item_param::eq() in string context behaved differently.
Introducing a new class Item_basic_value to share the eq() code between
literals (Item_int, Item_double, Item_string, Item_null) and Item_param.
This commit is contained in:
Alexander Barkov
2014-09-02 22:04:48 +04:00
parent e2bf60276c
commit c70cacacfe
5 changed files with 136 additions and 92 deletions

View File

@ -5962,5 +5962,32 @@ NULL
DEALLOCATE PREPARE stmt;
SET NAMES utf8;
#
# MDEV-6679 Different optimizer plan for "a BETWEEN 'string' AND ?" and "a BETWEEN ? AND 'string'"
#
SET NAMES utf8, collation_connection=utf8_swedish_ci;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8, b INT NOT NULL DEFAULT 0, key(a));
INSERT INTO t1 (a) VALUES ('a'),('b'),('c'),('d'),('¢');
SET @arg='¢';
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
EXECUTE stmt USING @arg;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 33 NULL 1 Using index condition
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
EXECUTE stmt USING @arg;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 33 NULL 1 Using index condition
DEALLOCATE PREPARE stmt;
ALTER TABLE t1 CONVERT TO CHARACTER SET latin1;
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
EXECUTE stmt USING @arg;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 13 NULL 1 Using index condition
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
EXECUTE stmt USING @arg;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 13 NULL 1 Using index condition
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
# End of 10.0 tests
#

View File

@ -1681,6 +1681,27 @@ EXECUTE stmt USING @no_such_var;
DEALLOCATE PREPARE stmt;
SET NAMES utf8;
--echo #
--echo # MDEV-6679 Different optimizer plan for "a BETWEEN 'string' AND ?" and "a BETWEEN ? AND 'string'"
--echo #
SET NAMES utf8, collation_connection=utf8_swedish_ci;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8, b INT NOT NULL DEFAULT 0, key(a));
INSERT INTO t1 (a) VALUES ('a'),('b'),('c'),('d'),('¢');
SET @arg='¢';
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
EXECUTE stmt USING @arg;
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
EXECUTE stmt USING @arg;
DEALLOCATE PREPARE stmt;
ALTER TABLE t1 CONVERT TO CHARACTER SET latin1;
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
EXECUTE stmt USING @arg;
PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
EXECUTE stmt USING @arg;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo #
--echo # End of 10.0 tests
--echo #