From e90de4ed57db527e41ae95cc4c539d2766a1333f Mon Sep 17 00:00:00 2001 From: Mike Wang Date: Sun, 10 Nov 2024 13:36:04 +0800 Subject: [PATCH] Bug #116584: Query produces different resultset with force index --- mysql-test/r/ctype_utf8mb4.result | 10 ++++++++++ mysql-test/t/ctype_utf8mb4.test | 10 ++++++++++ strings/ctype-mb.cc | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result index e9f4529e4982..8f253d29a6e8 100644 --- a/mysql-test/r/ctype_utf8mb4.result +++ b/mysql-test/r/ctype_utf8mb4.result @@ -3308,3 +3308,13 @@ SELECT a FROM t1 WHERE a = 'aaa '; a aaa DROP TABLE t1; +# +# Bug #116584: Query produces different resultset with force index +# +CREATE TABLE t1(c1 VARCHAR(16), KEY idx (c1)) COLLATE utf8mb4_bin; +INSERT INTO t1 VALUES ('000'), ('111'), ('abc\n'); +SELECT * FROM t1 FORCE INDEX(idx) WHERE c1 LIKE 'abc%'; +c1 +abc + +DROP TABLE t1; diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 5d18f9370589..344f773d5630 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1675,3 +1675,13 @@ INSERT INTO t1 VALUES('aaa'), ('aaaa'), ('aaaaa'); # One row expected. SELECT a FROM t1 WHERE a = 'aaa '; DROP TABLE t1; + +--echo # +--echo # Bug #116584: Query produces different resultset with force index +--echo # +CREATE TABLE t1(c1 VARCHAR(16), KEY idx (c1)) COLLATE utf8mb4_bin; +INSERT INTO t1 VALUES ('000'), ('111'), ('abc\n'); +# In PAD_SPACE collation, 'abc\n' is less than 'abc' +# But 'abc\n' should be matched in 'abc%' like range query +SELECT * FROM t1 FORCE INDEX(idx) WHERE c1 LIKE 'abc%'; +DROP TABLE t1; diff --git a/strings/ctype-mb.cc b/strings/ctype-mb.cc index 27498aea6af0..969c55d9cbea 100644 --- a/strings/ctype-mb.cc +++ b/strings/ctype-mb.cc @@ -669,7 +669,7 @@ bool my_like_range_mb(const CHARSET_INFO *cs, const char *ptr, "a\0\0..." is the smallest possible string for PAD SPACE. "a\xff\xff..." is the biggest possible string. */ - if ((cs->state & MY_CS_BINSORT) || cs->pad_attribute == NO_PAD) { + if (cs->pad_attribute == NO_PAD) { *min_length = static_cast(min_str - min_org); /*