Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the optimizer should treat predicate 'like' the same way as predicate '=' when it is an exact match #8962

Open
tshqin opened this issue Jan 7, 2019 · 4 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@tshqin
Copy link
Contributor

tshqin commented Jan 7, 2019

there is a multi-column index (a,c,b) on the table, when using 'like' on a condition which is an exact match, the next column in multi-column index could not use index scan.

create table t3 (a int, b decimal(10,2), c varchar(10), d double, e timestamp);
desc select * from t3 where a=5 and b=5.2 and c like 'ok';
desc select * from t3 where a=5 and b=5.2 and c = 'ok';
mysql> desc select * from t3 where a=5 and b=5.2 and c like 'ok';
+-----------------------+-------+------+--------------------------------------------------------------------------------+
| id                    | count | task | operator info                                                                  |
+-----------------------+-------+------+--------------------------------------------------------------------------------+
| IndexLookUp_11        | 0.10  | root |                                                                                |
| ├─Selection_10        | 0.10  | cop  | eq(gin.t3.b, 5.2)                                                              |
| │ └─IndexScan_8       | 0.10  | cop  | table:t3, index:a, c, b, range:[5 "ok",5 "ok"], keep order:false, stats:pseudo |
| └─TableScan_9         | 0.10  | cop  | table:t3, keep order:false                                                     |
+-----------------------+-------+------+--------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> desc select * from t3 where a=5 and b=5.2 and c = 'ok';
+-------------------+-------+------+------------------------------------------------------------------------------------------+
| id                | count | task | operator info                                                                            |
+-------------------+-------+------+------------------------------------------------------------------------------------------+
| IndexLookUp_10    | 0.00  | root |                                                                                          |
| ├─IndexScan_8     | 0.00  | cop  | table:t3, index:a, c, b, range:[5 "ok" 5.20,5 "ok" 5.20], keep order:false, stats:pseudo |
| └─TableScan_9     | 0.00  | cop  | table:t3, keep order:false, stats:pseudo                                                 |
+-------------------+-------+------+------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

tidb version:

Release Version: v2.1.2-1-g8ba8096
Git Commit Hash: 8ba8096
Git Branch: release-2.1
UTC Build Time: 2018-12-21 03:45:55
GoVersion: go version go1.11.2 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Jan 7, 2019
@winoros
Copy link
Member

winoros commented Jan 7, 2019

The best solution is that we rewrite such kind of like function to equal function.

@winoros winoros added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Jan 7, 2019
@morgo morgo changed the title the optimizer better treats predicate 'like' the same way as predicate '=' when it is an exact match the optimizer should treat predicate 'like' the same way as predicate '=' when it is an exact match Jan 7, 2019
@arnkore
Copy link
Contributor

arnkore commented Jan 23, 2019

Can I work on this issue?

@winoros
Copy link
Member

winoros commented Jan 23, 2019

@arnkore
Oh, thanks for your attention. There's already one #9071 about this.

@winoros
Copy link
Member

winoros commented Jan 27, 2021

At this moment in time, we found a new case that LIKE don't behave like EQ when the expression is unicode collation.
Simply rewriting LIKE to EQ would cause correctness problem. We need to handle it in a new way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

5 participants