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, executor: push limit down into IndexLookUpReader executor #12262

Merged
merged 5 commits into from
Sep 24, 2019

Conversation

eurekaka
Copy link
Contributor

What problem does this PR solve?

Fix #10668

What is changed and how it works?

Sink PhysicalLimit on top of IndexLookUpReader into IndexLookUpReader, and in executor, skip the preceding and tailing handles returned by IndexPlan. This optimization can avoid unnecessary TableScan for handles not satisfying Limit / Offset constraint, and improve execution performance especially for queries with large Offset.

Check List

Tests

  • Unit test

Code changes

  • Has exported variable/fields change

Side effects

  • Increased code complexity

Related changes

  • Need to update cost of IndexLookUpReader's TablePlan / IndexPlan since some unnecessary I/O and network cost is avoided. This can be done in the next PR.

@eurekaka eurekaka added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner sig/execution SIG execution labels Sep 18, 2019
@codecov
Copy link

codecov bot commented Sep 18, 2019

Codecov Report

Merging #12262 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #12262   +/-   ##
===========================================
  Coverage   81.1502%   81.1502%           
===========================================
  Files           454        454           
  Lines         99662      99662           
===========================================
  Hits          80876      80876           
  Misses        12972      12972           
  Partials       5814       5814

@eurekaka
Copy link
Contributor Author

/run-all-tests

@jingyugao
Copy link
Contributor

This pr seems to do some query-rewrite in cbo pahse?

@eurekaka
Copy link
Contributor Author

@jingyugao Yes, it is query-rewrite to some extent, like the operator pushdown (to storage layer) here.

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@eurekaka eurekaka added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 23, 2019
@@ -484,9 +487,9 @@ func (e *IndexLookUpExecutor) startIndexWorker(ctx context.Context, kvRanges []k
}
if e.runtimeStats != nil {
copStats := e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.GetRootStats(e.idxPlans[len(e.idxPlans)-1].ExplainID().String())
copStats.SetRowNum(count)
copStats.SetRowNum(int64(count))
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR, but it seems really strange to use int64 instead of uint64 for a count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qw4990 Is there any specific reason why we are using int/int64 for SetRequiredRows/SetRowNum respectively?

Copy link
Contributor

Choose a reason for hiding this comment

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

For RowNum, we use methods like atomic.XXXInt64 to maintain it so its type is int64.
And for RequiredRows we maintain it using Golang statement and for convenience, we set its type to int.

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added needs-cherry-pick-2.1 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 24, 2019
@zz-jason zz-jason changed the title planner/executor: push limit down into IndexLookUpReader executor planner, executor: push limit down into IndexLookUpReader executor Sep 24, 2019
@zz-jason zz-jason added the status/can-merge Indicates a PR has been approved by a committer. label Sep 24, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

Your auto merge job has been accepted, waiting for 12331, 12332, 12325

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

/run-all-tests

@sre-bot sre-bot merged commit 8179558 into pingcap:master Sep 24, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-3.1 failed

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-2.1 failed

@eurekaka eurekaka deleted the limit branch September 24, 2019 07:47
eurekaka added a commit to eurekaka/tidb that referenced this pull request Sep 25, 2019
…ingcap#12262)

Conflicts:
	cmd/explaintest/r/explain_easy.result
	cmd/explaintest/r/explain_easy_stats.result
	planner/core/integration_test.go
	planner/core/physical_plans.go
	planner/core/testdata/plan_suite_out.json
eurekaka added a commit to eurekaka/tidb that referenced this pull request Sep 25, 2019
…ingcap#12262)

Conflicts:
	cmd/explaintest/r/explain_easy.result
	cmd/explaintest/r/explain_easy_stats.result
	planner/core/integration_test.go
	planner/core/physical_plans.go
	planner/core/testdata/plan_suite_out.json
eurekaka added a commit to eurekaka/tidb that referenced this pull request Sep 25, 2019
…ingcap#12262)

Conflicts:
	cmd/explaintest/r/explain_easy.result
	cmd/explaintest/r/explain_easy_stats.result
	planner/core/integration_test.go
	planner/core/physical_plans.go
	planner/core/testdata/plan_suite_out.json
	executor/distsql.go
	executor/distsql_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Push down limit on IndexLookUp operator may improve performance in some scene
8 participants