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

plan: rewrite exact `like` expression to equal condition #9071

Merged
merged 9 commits into from Jan 28, 2019

Conversation

Projects
None yet
4 participants
@hhxcc
Copy link
Contributor

hhxcc commented Jan 15, 2019

What problem does this PR solve?

Fix #8962

What is changed and how it works?

rewrite such kind of like function to equal function.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Jan 15, 2019

Codecov Report

Merging #9071 into master will increase coverage by 0.01%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9071      +/-   ##
==========================================
+ Coverage   67.19%   67.21%   +0.01%     
==========================================
  Files         371      371              
  Lines       76958    76982      +24     
==========================================
+ Hits        51711    51742      +31     
+ Misses      20624    20618       -6     
+ Partials     4623     4622       -1
Impacted Files Coverage Δ
util/stringutil/string_util.go 98.51% <100%> (+0.05%) ⬆️
planner/core/expression_rewriter.go 73.78% <88%> (+0.2%) ⬆️
util/ranger/points.go 77.35% <0%> (-1.48%) ⬇️
util/ranger/checker.go 63.15% <0%> (-1.32%) ⬇️
executor/executor.go 67.03% <0%> (+0.13%) ⬆️
executor/index_lookup_join.go 77.91% <0%> (+0.63%) ⬆️
expression/schema.go 94.95% <0%> (+0.84%) ⬆️
ddl/delete_range.go 77.77% <0%> (+2.64%) ⬆️
store/tikv/scan.go 77.31% <0%> (+3.36%) ⬆️
util/systimemon/systime_mon.go 100% <0%> (+20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dcba1f...f3e6d56. Read the comment docs.

@eurekaka eurekaka changed the title rewrite predicate 'like' the same way as predicate '=' when it is an … plan: rewrite exact `like` expression to equal condition Jan 15, 2019

@winoros

This comment has been minimized.

Copy link
Member

winoros commented Jan 15, 2019

Thanks for your contribution!

@winoros
Copy link
Member

winoros left a comment

Actually, you just need to check whether er.ctxStack[l-1] is a string without regex pattern.

Show resolved Hide resolved planner/core/expression_rewriter.go Outdated
Show resolved Hide resolved planner/core/expression_rewriter.go Outdated
Show resolved Hide resolved planner/core/expression_rewriter.go Outdated

hhxcc added some commits Jan 16, 2019

@hhxcc

This comment has been minimized.

Copy link
Contributor Author

hhxcc commented Jan 16, 2019

@winoros when pattern string contains escape character , we should use the compiled result of the pattern string in the equal condition, eg: a LIKE 'ab\_c' should rewrite to a = 'ab_c' .
So, we can not just check whether er.ctxStack[l-1] is a string without regex pattern.

Show resolved Hide resolved planner/core/expression_rewriter.go Outdated
Show resolved Hide resolved planner/core/expression_rewriter.go Outdated
Show resolved Hide resolved planner/core/expression_rewriter.go Outdated
Show resolved Hide resolved planner/core/expression_rewriter.go Outdated

hhxcc added some commits Jan 17, 2019

hhxcc added some commits Jan 17, 2019

@winoros

This comment has been minimized.

Copy link
Member

winoros commented Jan 18, 2019

We need to add ast.Like to expression.UnCacheableFunctions?

@eurekaka
Copy link
Contributor

eurekaka left a comment

LGTM

@eurekaka

This comment has been minimized.

Copy link
Contributor

eurekaka commented Jan 18, 2019

We need to add ast.Like to expression.UnCacheableFunctions?

Any specific reason?

@winoros

This comment has been minimized.

Copy link
Member

winoros commented Jan 24, 2019

@hhxcc @eurekaka
This rewriting changes the expression structure. So when prepare cache enabled, it will produce wrong result.

create table t(a varchar(10));
insert into t values('bbb');
prepare stmt from 'select * from t where concat(a, "b") like ?';
set @a='bbb';
execute stmt using @a;
set @a='b%';
execute stmt using @a;

The second time it use the physical plan cached by the first time then return wrong result.

hhxcc added some commits Jan 28, 2019

@winoros
Copy link
Member

winoros left a comment

lgtm
Thanks for your contribution!

@winoros

This comment has been minimized.

Copy link
Member

winoros commented Jan 28, 2019

/run-all-tests

@winoros winoros merged commit 6a06977 into pingcap:master Jan 28, 2019

13 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/common-test job succeeded
Details
idc-jenkins-ci-tidb/integration-common-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-compatibility-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-ddl-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/mybatis-test job succeeded
Details
idc-jenkins-ci-tidb/sqllogic-test-1 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/sqllogic-test-2 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/unit-test Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment