-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.2affects-6.3affects-6.4affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-6.6affects-7.0affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.2affects-7.3affects-7.4affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.severity/criticalsig/plannerSIG: PlannerSIG: Plannertype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.
Description
Bug Report
This bug is related to the same mechanism as #48821, which is the behavior that trailing space will be trimmed in the stored index key on PAD SPACE column, but this bug is caused by another place in the code.
1. Minimal reproduce step (Required)
create table t(a varchar(25) collate utf8mb4_bin, index ia(a));
insert into t value('xxx ');
select * from t use index (ia) where a like 'xxx_';
explain select * from t use index (ia) where a like 'xxx_';
select * from t use index () where a like 'xxx_';
explain select * from t use index () where a like 'xxx_';
2. What did you expect to see? (Required)
From MySQL:
> select * from t use index (ia) where a like 'xxx_';
+------+
| a |
+------+
| xxx |
+------+
1 row in set (0.000 sec)
> explain select * from t use index (ia) where a like 'xxx_';
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------+
| 1 | SIMPLE | t | NULL | index | ia | ia | 103 | NULL | 1 | 100.00 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------+
1 row in set, 1 warning (0.000 sec)
> select * from t use index () where a like 'xxx_';
+------+
| a |
+------+
| xxx |
+------+
1 row in set (0.000 sec)
> explain select * from t use index () where a like 'xxx_';
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | t | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.001 sec)
3. What did you see instead (Required)
127.0.0.1:4000[test]> select * from t use index (ia) where a like 'xxx_';
Empty set (0.001 sec)
127.0.0.1:4000[test]> explain select * from t use index (ia) where a like 'xxx_';
+--------------------------+---------+-----------+----------------------+-----------------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------+---------+-----------+----------------------+-----------------------------------------------------+
| IndexReader_7 | 250.00 | root | | index:Selection_6 |
| └─Selection_6 | 250.00 | cop[tikv] | | like(test.t.a, "xxx_", 92) |
| └─IndexRangeScan_5 | 250.00 | cop[tikv] | table:t, index:ia(a) | range:("xxx","xxy"), keep order:false, stats:pseudo |
+--------------------------+---------+-----------+----------------------+-----------------------------------------------------+
3 rows in set (0.001 sec)
127.0.0.1:4000[test]> select * from t use index () where a like 'xxx_';
+------+
| a |
+------+
| xxx |
+------+
1 row in set (0.001 sec)
127.0.0.1:4000[test]> explain select * from t use index () where a like 'xxx_';
+-------------------------+----------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7 | 250.00 | root | | data:Selection_6 |
| └─Selection_6 | 250.00 | cop[tikv] | | like(test.t.a, "xxx_", 92) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.000 sec)
4. What is your TiDB version? (Required)
From v6.0.0 to latest master
Metadata
Metadata
Assignees
Labels
affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.2affects-6.3affects-6.4affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-6.6affects-7.0affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.2affects-7.3affects-7.4affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.severity/criticalsig/plannerSIG: PlannerSIG: Plannertype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.