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

plan: rewrite exact like expression to equal condition #9071

Merged
merged 9 commits into from
Jan 28, 2019
Merged

plan: rewrite exact like expression to equal condition #9071

merged 9 commits into from
Jan 28, 2019

Conversation

hhu-cc
Copy link
Contributor

@hhu-cc hhu-cc 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
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
@eurekaka eurekaka added type/enhancement The issue or PR belongs to an enhancement. contribution This PR is from a community contributor. sig/planner SIG: Planner labels Jan 15, 2019
@winoros
Copy link
Member

winoros commented Jan 15, 2019

Thanks for your contribution!

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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
@hhu-cc
Copy link
Contributor Author

hhu-cc 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.

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 Show resolved Hide resolved
@winoros
Copy link
Member

winoros commented Jan 18, 2019

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

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eurekaka eurekaka added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 18, 2019
@eurekaka
Copy link
Contributor

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

Any specific reason?

@winoros
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.

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
Thanks for your contribution!

@winoros
Copy link
Member

winoros commented Jan 28, 2019

/run-all-tests

@winoros winoros merged commit 6a06977 into pingcap:master Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. sig/planner SIG: Planner status/LGT1 Indicates that a PR has LGTM 1. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants