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: fix ExtractCorrelatedCols method in PhysicalTableScan #51205

Merged
merged 5 commits into from
Feb 21, 2024

Conversation

Lloyd-Pottiger
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger commented Feb 20, 2024

What problem does this PR solve?

Issue Number: close #51204

Problem Summary:

What changed and how does it work?

Before, we do not try to extract correlated column in LateMaterializationFilterCondition. So when the correlated columns only in LateMaterializationFilterCondition, exprs failed to fill in correlated column with constant value during Plan2Pb, and it leads to wrong query result.

Now, in ExtractCorrelatedCols method, we will also try to extract correlated column in LateMaterializationFilterCondition.

Also fix other methods.

Check List

Currently, integration test do not support TiFlash, so I will add tests in https://github.com/pingcap/tiflash

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.

Fix wrong query result of Apply operator when there are correlated column in push down conditions

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 20, 2024
Copy link

tiprow bot commented Feb 20, 2024

Hi @Lloyd-Pottiger. 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/test-infra repository.

@JaySon-Huang
Copy link
Contributor

please update the "Problem Summary" and "Release note"

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Feb 20, 2024
@Lloyd-Pottiger
Copy link
Contributor Author

please update the "Problem Summary" and "Release note"

done

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Merging #51205 (a83fd24) into master (a465300) will decrease coverage by 16.4706%.
Report is 23 commits behind head on master.
The diff coverage is 50.0000%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #51205         +/-   ##
=================================================
- Coverage   70.6268%   54.1562%   -16.4706%     
=================================================
  Files          1467       1576        +109     
  Lines        434809     605291     +170482     
=================================================
+ Hits         307092     327803      +20711     
- Misses       108517     254591     +146074     
- Partials      19200      22897       +3697     
Flag Coverage Δ
integration 20.9225% <0.0000%> (?)
unit 70.3229% <50.0000%> (-0.1090%) ⬇️

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

Components Coverage Δ
dumpling 53.9957% <ø> (-0.0313%) ⬇️
parser ∅ <ø> (∅)
br 50.4113% <ø> (+4.5428%) ⬆️

@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Feb 21, 2024
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.

LGTM

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. and removed do-not-merge/needs-triage-completed labels Feb 21, 2024
@@ -935,13 +936,16 @@ func (ts *PhysicalTableScan) Clone() (PhysicalPlan, error) {

// ExtractCorrelatedCols implements PhysicalPlan interface.
func (ts *PhysicalTableScan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
corCols := make([]*expression.CorrelatedColumn, 0, len(ts.AccessCondition)+len(ts.filterCondition))
corCols := make([]*expression.CorrelatedColumn, 0, len(ts.AccessCondition)+len(ts.filterCondition)+len(ts.LateMaterializationFilterCondition))
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the tests for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@SeaRise SeaRise left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -935,13 +936,16 @@ func (ts *PhysicalTableScan) Clone() (PhysicalPlan, error) {

// ExtractCorrelatedCols implements PhysicalPlan interface.
func (ts *PhysicalTableScan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
corCols := make([]*expression.CorrelatedColumn, 0, len(ts.AccessCondition)+len(ts.filterCondition))
corCols := make([]*expression.CorrelatedColumn, 0, len(ts.AccessCondition)+len(ts.filterCondition)+len(ts.LateMaterializationFilterCondition))
Copy link
Contributor

Choose a reason for hiding this comment

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

Will CorrelatedCols be explicit in explan plan?
If so maybe a ut can be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@SeaRise
Copy link
Contributor

SeaRise commented Feb 21, 2024

/hold

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

ti-chi-bot bot commented Feb 21, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-02-21 01:16:37.928351322 +0000 UTC m=+406286.675974432: ☑️ agreed by windtalker.
  • 2024-02-21 03:13:31.381374051 +0000 UTC m=+413300.128997162: ☑️ agreed by SeaRise.

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Feb 21, 2024
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 21, 2024
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@Lloyd-Pottiger
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Feb 21, 2024

@Lloyd-Pottiger: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@@ -437,3 +437,57 @@ func TestPhysicalPlanMemoryTrace(t *testing.T) {
pp.MPPPartitionCols = append(pp.MPPPartitionCols, &property.MPPPartitionColumn{})
require.Greater(t, pp.MemoryUsage(), size)
}

func TestPhysicalTableScanExtractCorrelatedCols(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just use json output file to compare the whole physical plan? It is hard to see what is the purpose of this test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add some comments.

It is only used to test ExtractCorrelatedCols, compare the whole plan do not meet our needs.

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@Lloyd-Pottiger
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2024
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.

+1

Copy link

ti-chi-bot bot commented Feb 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fixdb, SeaRise, 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 merged commit a0e0969 into pingcap:master Feb 21, 2024
21 checks passed
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Feb 21, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Feb 21, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@Lloyd-Pottiger Lloyd-Pottiger deleted the fix-lm-cor branch February 22, 2024 12:49
rleungx pushed a commit to rleungx/tidb that referenced this pull request Mar 1, 2024
…d in PhysicalTableScan (pingcap#887)

* planner: fix ExtractCorrelatedCols method in PhysicalTableScan  (pingcap#51205) (pingcap#51227)

close pingcap#51204

* make check

Signed-off-by: zzm <zhouzemin@pingcap.com>

* gctuner: make TestIssue48741 more stable (pingcap#49430)

---------

Signed-off-by: zzm <zhouzemin@pingcap.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: Hangjie Mo <mohangjie1995@gmail.com>
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-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong query result of Apply operator when late materialization is enable
7 participants