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

*: simplify LIKE patterns with multiple consecutive wildcards (#17490) #22572

Closed

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Jan 27, 2021

cherry-pick #17490 to release-4.0
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/22572

After apply modifications, you can push your change to this PR via:

git push [email protected]:ti-srebot/tidb.git pr/22572:release-4.0-c84aa7997095

What problem does this PR solve?

Problem Summary: %% => % and %_ => _% are valid rewrite rules that improve pattern matching performance.

This is a follow up to #17418 (comment) (cc @wjhuang2016).

What is changed and how it works?

What's Changed:

  • LIKE pattern compile now applies the rules %% => % and %_ => _%.

Related changes

Preceding: #17418

Check List

Tests

  • Unit test

Moderate performance improvement for the affected cases:

name                                 old time/op  new time/op  delta
DoMatch/a%_%_%_%_b-8                 31.0ns ± 0%  20.2ns ± 0%   ~     (p=1.000 n=1+1)
DoMatch/%_%_a%_%_b-8                 37.1ns ± 0%  26.2ns ± 0%   ~     (p=1.000 n=1+1)
DoMatch/a%_%_a%_%_b-8                 142ns ± 0%    94ns ± 0%   ~     (p=1.000 n=1+1)
DoMatchNegative/a%a%a%a%a%a%a%a%b-8   193ns ± 0%   171ns ± 0%   ~     (p=1.000 n=1+1)

Release note

  • Simplify LIKE patterns with multiple consecutive wildcards.

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@zz-jason please accept the invitation then you can push to the cherry-pick pull requests.
https://github.com/ti-srebot/tidb/invitations

@xiongjiwei
Copy link
Contributor

this PR not only improve performance, but also fix a bug

mysql> select 'aa' collate utf8mb4_general_ci like 'a_%a';
+---------------------------------------------+
| 'aa' collate utf8mb4_general_ci like 'a_%a' |
+---------------------------------------------+
|                                           0 |
+---------------------------------------------+
1 row in set (0.06 sec)

this test case is added in PR #22558

@xiongjiwei
Copy link
Contributor

/run-all-tests

@xiongjiwei
Copy link
Contributor

Sorry, make a mistake. This PR not fix the bug.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2021
@ti-chi-bot
Copy link
Member

@ti-srebot: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@xiongjiwei
Copy link
Contributor

/close

@ti-chi-bot
Copy link
Member

@xiongjiwei: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot closed this Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants