Commit 658a1e94 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-6683 A parameter and a string literal with the same values are not...

MDEV-6683 A parameter and a string literal with the same values are not recognized as equal by the optimizer
parent c70cacac
......@@ -5977,15 +5977,22 @@ 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;
DROP TABLE t1;
#
# MDEV-6683 A parameter and a string literal with the same values are not recognized as equal by the optimizer
#
SET NAMES utf8, collation_connection=utf8_swedish_ci;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, 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 13 NULL 1 Using index condition
1 SIMPLE t1 ref a a 13 const 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
1 SIMPLE t1 ref a a 13 const 1 Using index condition
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
......
......@@ -1693,8 +1693,16 @@ 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 # MDEV-6683 A parameter and a string literal with the same values are not recognized as equal by the optimizer
-- echo #
ALTER TABLE t1 CONVERT TO CHARACTER SET latin1;
SET NAMES utf8, collation_connection=utf8_swedish_ci;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, 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'¢'";
......
......@@ -1288,6 +1288,7 @@ Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
!cnvitem->check_well_formed_result(&cnvitem->str_value, true))
return NULL;
cnvitem->str_value.mark_as_const();
cnvitem->collation.set(tocs);
cnvitem->max_length= cnvitem->str_value.numchars() * tocs->mbmaxlen;
return cnvitem;
}
......
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