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: prune cop task for tiflash #13131

Merged
merged 17 commits into from
Nov 7, 2019

Conversation

windtalker
Copy link
Contributor

What problem does this PR solve?

prune unnecessary cop task when TiDB query TiFlash

What is changed and how it works?

when pk is handle and the query has filter on the pk column, TiDB use cop ranges to prune the unnecessary cop task, but for TiFlash, since TiFlash does not support scan range in cop task, so current code always use full range to build the cop task. In this pr, the cop ranges is enabled for TiFlash to prune cop task, and in buildCopTasks, it will use the full region range when generating TiFlash cop task.

Check List

Tests

  • Unit test

Side effects

  • Increased code complexity

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2019

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@windtalker windtalker changed the title Prune region for tiflash Prune cop task for tiflash Nov 5, 2019
@codecov
Copy link

codecov bot commented Nov 5, 2019

Codecov Report

Merging #13131 into master will decrease coverage by 0.1697%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #13131        +/-   ##
================================================
- Coverage   80.2509%   80.0811%   -0.1698%     
================================================
  Files           469        468         -1     
  Lines        111823     110890       -933     
================================================
- Hits          89739      88802       -937     
- Misses        15190      15221        +31     
+ Partials       6894       6867        -27

@zz-jason
Copy link
Member

zz-jason commented Nov 5, 2019

@windtalker please add some proper labels for this pr

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.

In this pr, the cop ranges is enabled for TiFlash to prune cop task

Since it's a full range scan. Which task is pruned now?

@@ -1035,9 +1035,10 @@ func (ds *DataSource) getOriginalPhysicalTableScan(prop *property.PhysicalProper
ts.StoreType = kv.TiKV
}
if ts.StoreType == kv.TiFlash {
// append the AccessCondition to filterCondition because TiFlash only support full range scan for each
// region, do not reset ts.Ranges as it will help prune regions during `buildCopTasks`
Copy link
Member

Choose a reason for hiding this comment

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

Since it's a full range scan. Which task is pruned before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, for a table t with id as its primary key, and the id is the handle column, if user fire a query like select count(*) from t where id >= 100, then obviously, only some of the regions have the useful data. For TiKV, TiDB will only send the cop request to these regions, this "task prune" is done by passing range [100, +inf) to the buildCopTask function. For TiFlash, although it requires full range scan on every region, we can still prune the task which is sending cop request to the regions that do not have data with id >= 100

planner/core/find_best_task.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@windtalker
Copy link
Contributor Author

@winoros , @eurekaka , PTAL

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM, will approve when the following comment addressed.

planner/core/explain.go Outdated Show resolved Hide resolved
windtalker and others added 3 commits November 7, 2019 12:29
Co-Authored-By: Zhuomin(Charming) Liu <lzmhhh123@gmail.com>
@lzmhhh123 lzmhhh123 added 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. labels Nov 7, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

/run-all-tests

@zz-jason
Copy link
Member

zz-jason commented Nov 7, 2019

@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

@windtalker merge failed.

@windtalker windtalker changed the title Prune cop task for tiflash planner: prune cop task for tiflash Nov 7, 2019
@lzmhhh123
Copy link
Contributor

/run-integration-common-test

@lzmhhh123 lzmhhh123 merged commit 80939f2 into pingcap:master Nov 7, 2019
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
lzmhhh123 pushed a commit to lzmhhh123/tidb that referenced this pull request Jan 19, 2020
@windtalker windtalker deleted the prune_region_for_tiflash branch December 28, 2020 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/coprocessor 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.

7 participants