Skip to content

Unexpected eliminated conditions in the connection with utf8mb4 charset  #53730

@pcqz

Description

@pcqz

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (id int primary key, name varchar(20));
insert into t values(1, 'a'), (2, 'a ');
select * from t where name='a' and length(name)=1;

2. What did you expect to see? (Required)

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql>  select * from t where name='a' and length(name)=1;
+----+------+
| id | name |
+----+------+
|  1 | a    |
+----+------+
1 row in set (0.00 sec)
mysql> explain select * from t where name='a' and length(name)=1;
+-------------------------+---------+-----------+---------------+--------------------------------------------------+
| id                      | estRows | task      | access object | operator info                                    |
+-------------------------+---------+-----------+---------------+--------------------------------------------------+
| TableReader_7           | 0.00    | root      |               | data:Selection_6                                 |
| └─Selection_6           | 0.00    | cop[tikv] |               | eq(length(test.t.name), 1), eq(test.t.name, "a") |
|   └─TableFullScan_5     | 2.00    | cop[tikv] | table:t       | keep order:false, stats:pseudo                   |
+-------------------------+---------+-----------+---------------+--------------------------------------------------+
3 rows in set (0.00 sec)

3. What did you see instead (Required)

mysql> set names utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql>  select * from t where name='a' and length(name)=1;
+----+------+
| id | name |
+----+------+
|  1 | a    |
|  2 | a    |
+----+------+
2 rows in set (0.00 sec)

mysql> explain select * from t where name='a' and length(name)=1;
+-------------------------+---------+-----------+---------------+--------------------------------+
| id                      | estRows | task      | access object | operator info                  |
+-------------------------+---------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00    | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00    | cop[tikv] |               | eq(test.t.name, "a")           |
|   └─TableFullScan_5     | 2.00    | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+---------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

v6.5.6

Metadata

Metadata

Assignees

Labels

affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.impact/wrong-resultseverity/majorsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions