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: column pruning must reserve at least one column #54778

Merged
merged 7 commits into from
Jul 29, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Jul 19, 2024

What problem does this PR solve?

Issue Number: close #54777

Problem Summary:

What changed and how does it work?

Column pruning must reserve at least one column for correctness.

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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 19, 2024
Comment on lines 119 to 134
allPruned := true
for i, b := range used {
if b || expression.ExprHasSetVarOrSleep(p.Exprs[i]) {
// Set to true to avoid the ExprHasSetVarOrSleep be called multiple times.
used[i] = true
allPruned = false
break
}
}
if allPruned {
_, ok := p.Children()[0].(*LogicalTableDual)
if ok {
// If the child is dual. The proj should not be eliminated.
return p, nil
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For the Proj->Dual.

@@ -155,7 +177,7 @@ func (ds *DataSource) PruneColumns(parentUsedCols []*expression.Column, opt *opt
// Current DataSource operator contains all the filters on this table, and the columns used by these filters are always included
// in the output schema. Even if they are not needed by DataSource's parent operator. Thus add a projection here to prune useless columns
// Limit to MPP tasks, because TiKV can't benefit from this now(projection can't be pushed down to TiKV now).
if !addOneHandle && ds.Schema().Len() > len(parentUsedCols) && ds.SCtx().GetSessionVars().IsMPPEnforced() && ds.TableInfo.TiFlashReplica != nil {
if !addOneHandle && ds.Schema().Len() > len(parentUsedCols) && len(parentUsedCols) > 0 && ds.SCtx().GetSessionVars().IsMPPEnforced() && ds.TableInfo.TiFlashReplica != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

We should not do the project if no column is required from its parent.

@@ -98,7 +101,7 @@ func (rs *resultReorder) injectSort(lp base.LogicalPlan) base.LogicalPlan {

func (*resultReorder) isInputOrderKeeper(lp base.LogicalPlan) bool {
switch lp.(type) {
case *LogicalSelection, *LogicalProjection, *LogicalLimit:
case *LogicalSelection, *LogicalProjection, *LogicalLimit, *LogicalTableDual:
Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't add this, we'll get Proj->Sort->Dual for Proj->Dual.

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

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

Project coverage is 73.2215%. Comparing base (c517ffb) to head (99e44b7).
Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #54778        +/-   ##
================================================
+ Coverage   72.5717%   73.2215%   +0.6497%     
================================================
  Files          1565       1573         +8     
  Lines        440170     447658      +7488     
================================================
+ Hits         319439     327782      +8343     
+ Misses       100937      99175      -1762     
- Partials      19794      20701       +907     
Flag Coverage Δ
integration 25.1736% <29.7872%> (?)
unit 71.6175% <87.2340%> (+0.0034%) ⬆️

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

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 46.1229% <ø> (+0.3007%) ⬆️

Copy link
Contributor

@elsa0520 elsa0520 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. labels Jul 22, 2024
Copy link

ti-chi-bot bot commented Jul 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elsa0520, 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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 22, 2024
Copy link

ti-chi-bot bot commented Jul 22, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-22 02:06:59.410089111 +0000 UTC m=+838041.401030576: ☑️ agreed by elsa0520.
  • 2024-07-22 19:44:18.061853783 +0000 UTC m=+901480.052795254: ☑️ agreed by time-and-fate.

@hawkingrei
Copy link
Member

/retest

1 similar comment
@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 24, 2024
@ti-chi-bot ti-chi-bot bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 24, 2024
Copy link

ti-chi-bot bot commented Jul 25, 2024

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.

@winoros winoros removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 29, 2024
@winoros
Copy link
Member Author

winoros commented Jul 29, 2024

/merge

Copy link

ti-chi-bot bot commented Jul 29, 2024

@winoros: We have migrated to builtin LGTM and approve plugins for reviewing.

👉 Please use /approve when you want approve this pull request.

The changes announcement: LGTM plugin changes

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 ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot merged commit 60c7e61 into pingcap:master Jul 29, 2024
23 checks passed
@winoros winoros deleted the strict-no-col branch July 29, 2024 18:07
hawkingrei pushed a commit to hawkingrei/tidb that referenced this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm 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.

Strictly checking column pruning would not cause empty column output for each operator
4 participants