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

planner: change the rewrite rule of row expression #53928

Merged
merged 5 commits into from
Jun 20, 2024

Conversation

elsa0520
Copy link
Contributor

@elsa0520 elsa0520 commented Jun 11, 2024

What problem does this PR solve?

(x,y,z) op (a,b,c)
rewritten
(x op a) or (x = a and y op b) or (x = a and y = b and z op c)

The new rewriting method allows buildrange to handle range construction problems more conveniently.

Issue Number: close #41598

Problem Summary:

What changed and how does it work?

The old expression rewrite is rewritten row expression to if(x!=a, x> a, if(xxxx)). The range builder could not easy build and merge this kind of expr range.

The new expression rewritten to (x op a) or (x = a and y op b) or (x = a and y = b and z op c) . It will be rewritten as a DNF which is more conveniently for Range builder.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

The row expression will be rewritten into DNF. This form is more conducive to more precise range builder of the index, thereby reducing key reading.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/planner SIG: Planner labels Jun 11, 2024
Copy link

tiprow bot commented Jun 11, 2024

Hi @elsa0520. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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-sigs/prow repository.

@elsa0520
Copy link
Contributor Author

Testing, not ready to merge

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 83.78378% with 6 lines in your changes missing coverage. Please review.

Project coverage is 56.6515%. Comparing base (b96a775) to head (2db6374).
Report is 41 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #53928         +/-   ##
=================================================
- Coverage   72.5347%   56.6515%   -15.8833%     
=================================================
  Files          1508       1640        +132     
  Lines        432015     618280     +186265     
=================================================
+ Hits         313361     350265      +36904     
- Misses        99268     244593     +145325     
- Partials      19386      23422       +4036     
Flag Coverage Δ
integration 37.2764% <83.7837%> (?)
unit 71.7730% <83.7837%> (+0.2454%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9656% <ø> (+0.0188%) ⬆️
parser ∅ <ø> (∅)
br 52.3531% <ø> (+10.0903%) ⬆️

Copy link
Contributor

@fixdb fixdb left a comment

Choose a reason for hiding this comment

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

Are you going to add test cases?

@elsa0520
Copy link
Contributor Author

Are you going to add test cases?

Yes, I haven't finish the test.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-tests-checked labels Jun 14, 2024
(x,y,z) op (a,b,c)
rewritten
(x op a) or (x = a and y op b) or (x = a and y = b and z op c)

The new rewriting method allows buildrange to handle range construction problems more conveniently.
Copy link

ti-chi-bot bot commented Jun 14, 2024

@ghazalfamilyusa: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

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.

Copy link
Member

@time-and-fate time-and-fate left a comment

Choose a reason for hiding this comment

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

Others LGTM.

pkg/planner/core/expression_rewriter.go Outdated Show resolved Hide resolved
Comment on lines 418 to 420
// build prefix equal conditions
// (l[0], ... , l[i-1], ...) op (r[0], ... , r[i-1], ...) should be convert to
// l[0] = r[0] and l[1] = r[1] and ... and l[i-1] = r[i-1]
Copy link
Member

Choose a reason for hiding this comment

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

I think the comments here are a little confusing, especially the "should be converted to".
Actually, we are not "convert"ing it to the AND list. We are just preparing the prefix columns part of the final result.
And also at this stage, we haven't connected them using AND yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link

ti-chi-bot bot commented Jun 17, 2024

@ghazalfamilyusa: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

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.

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Jun 18, 2024
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 18, 2024
@elsa0520
Copy link
Contributor Author

/test unit-test

Copy link

tiprow bot commented Jun 18, 2024

@elsa0520: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test unit-test

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-sigs/prow repository.

@elsa0520
Copy link
Contributor Author

/test unit-test

Copy link

tiprow bot commented Jun 20, 2024

@elsa0520: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test unit-test

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 20, 2024
Copy link

ti-chi-bot bot commented Jun 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-18 04:22:01.870776656 +0000 UTC m=+88648.356265487: ☑️ agreed by time-and-fate.
  • 2024-06-20 10:02:02.900302194 +0000 UTC m=+281849.385791028: ☑️ agreed by AilinKid.

@AilinKid AilinKid changed the title planner: Change the rewrite rule of row expression planner: change the rewrite rule of row expression Jun 20, 2024
Copy link

ti-chi-bot bot commented Jun 20, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, ghazalfamilyusa, hawkingrei, time-and-fate

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit 805ea36 into pingcap:master Jun 20, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimizer cannot handle cases like ((a = 1 and b = 2 and c > 3) or (a = 4 and b = 5 and c > 6)) and d > 3
6 participants