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: reserve the OFFSET when outer join's inner side is unique #56483

Merged
merged 6 commits into from
Nov 13, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Oct 8, 2024

What problem does this PR solve?

Issue Number: close #56321

Problem Summary:

What changed and how does it work?

When the outer join's inner side has a unique key on the join key.
The relationship between the outer join's output and its outer child's output is one-to-one.
So we can reserve the OFFSET of the LIMIT.

This can reduce the input to the outer join.

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.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2024
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

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

Project coverage is 73.4575%. Comparing base (66cb425) to head (257a2c0).
Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #56483        +/-   ##
================================================
+ Coverage   72.9059%   73.4575%   +0.5515%     
================================================
  Files          1672       1672                
  Lines        461836     461913        +77     
================================================
+ Hits         336706     339310      +2604     
+ Misses       104424     101935      -2489     
+ Partials      20706      20668        -38     
Flag Coverage Δ
integration 43.4237% <53.1914%> (?)
unit 72.2705% <87.2340%> (-0.0165%) ⬇️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 45.1410% <ø> (-0.0062%) ⬇️

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

Rest LGTM

innerChild := p.Children()[1]
innerJoinKey := make([]*expression.Column, 0, len(p.EqualConditions))
for _, eqCond := range p.EqualConditions {
innerJoinKey = append(innerJoinKey, eqCond.GetArgs()[1].(*expression.Column))
Copy link
Contributor

Choose a reason for hiding this comment

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

eq-cond can ensure the arg1 is from inner side?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but the layout of the LogicalJoin or PhysicalJoin should be optimized.
Currently, it's too complex to use.

@fixdb fixdb requested a review from hawkingrei November 5, 2024 05:35
@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. labels Nov 5, 2024
@winoros
Copy link
Member Author

winoros commented Nov 5, 2024

/retest

1 similar comment
@purelind
Copy link
Contributor

purelind commented Nov 5, 2024

/retest

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 6, 2024
@winoros winoros changed the title planner: reverse the OFFSET when outer join's inner side is unique planner: reserve the OFFSET when outer join's inner side is unique Nov 6, 2024
@winoros winoros added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Nov 6, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 13, 2024
Copy link

ti-chi-bot bot commented Nov 13, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-06 02:50:27.549783163 +0000 UTC m=+1009340.388938701: ☑️ agreed by AilinKid.
  • 2024-11-13 13:23:45.458777683 +0000 UTC m=+448987.649646680: ☑️ agreed by hawkingrei.

Copy link
Contributor

@windtalker windtalker 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

// If the join key is nulleq, then we can only push the offset down when the inner side is unique key.
// Only when the join key is normal eq, we can push the offset down when the inner side is unique(could be null).
if innerChild.Schema().IsUnique(true, innerJoinKey...) ||
(innerChild.Schema().IsUnique(false, innerJoinKey...) && !isNullEQ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

check !isNullEQ first?

Copy link

ti-chi-bot bot commented Nov 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, hawkingrei, windtalker

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 added the approved label Nov 13, 2024
@winoros winoros force-pushed the enhance-limit-push-down-outer-join branch from b2514fa to 257a2c0 Compare November 13, 2024 15:18
@ti-chi-bot ti-chi-bot bot merged commit 97e7b5c into pingcap:master Nov 13, 2024
23 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #57361.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. 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 choose full table scan when there is a better execution path
6 participants