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/core: thoroughly push down count-distinct agg in the MPP mode. (#25662) #25861

Merged
merged 5 commits into from
Jul 20, 2021

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Jul 1, 2021

cherry-pick #25662 to release-5.0
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/25861

After apply modifications, you can push your change to this PR via:

git push git@github.com:ti-srebot/tidb.git pr/25861:release-5.0-3ad894da97d9

…up by columns

What problem does this PR solve?

Problem Summary:
Right now for count-distinct agg we can only execute the dedup part on TiFlash and gather all the intermediate data to get final result on TiDB. However the execution in TiDB will be the performance bottleneck so we hope to push down this part in MPP mode.

What is changed and how it works?

What's Changed:
We check the group by columns and distinct functions during exhaustPhysicalPlans and set the physical hint to MppScalar indicating this is a scalar function then we will push down all the calculation. This tune only takes effect in the MPP mode.

How it Works:
for a simple statement: select count(distinct a) from t;. The performace advance is great:
before tune:

mysql> explain analyze select count(distinct a) from t;
+------------------------------+-------------+----------+-------------------+---------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------+----------+------+
| id                           | estRows     | actRows  | task              | access object | execution info                                                                                                  | operator info                            | memory   | disk |
+------------------------------+-------------+----------+-------------------+---------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------+----------+------+
| HashAgg_13                   | 1.00        | 1        | root              |               | time:18.2s, loops:2                                                                                             | funcs:count(distinct test.t.a)->Column#4 | 932.1 MB | N/A  |
| └─TableReader_15             | 1.00        | 30950159 | root              |               | time:461.5ms, loops:30593, cop_task: {num: 640, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00} | data:ExchangeSender_14                   | N/A      | N/A  |
|   └─ExchangeSender_14        | 1.00        | 30950159 | batchCop[tiflash] |               | tiflash_task:{proc max:1.11s, min:0s, p80:1ms, p95:8ms, iters:768, tasks:640, threads:48}                       | ExchangeType: PassThrough                | N/A      | N/A  |
|     └─HashAgg_6              | 1.00        | 30950159 | batchCop[tiflash] |               | tiflash_task:{proc max:1.11s, min:0s, p80:1ms, p95:8ms, iters:768, tasks:640, threads:3}                        | group by:test.t.a,                       | N/A      | N/A  |
|       └─TableFullScan_12     | 64349746.00 | 64238857 | batchCop[tiflash] | table:t       | tiflash_task:{proc max:274.6ms, min:0s, p80:0s, p95:0s, iters:1044, tasks:640, threads:48}                      | keep order:false                         | N/A      | N/A  |
+------------------------------+-------------+----------+-------------------+---------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------+----------+------+
5 rows in set (18.22 sec)

after tune

mysql> explain analyze select count(distinct a) from t;
+----------------------------------+----------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------+------------------------------------------+--------+------+
| id                               | estRows  | actRows  | task              | access object | execution info                                                                             | operator info                            | memory | disk |
+----------------------------------+----------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------+------------------------------------------+--------+------+
| TableReader_18                   | 1.00     | 1        | root              |               | time:3.29s, loops:2, cop_task: {num: 1, max: 0s, proc_keys: 0, copr_cache_hit_ratio: 0.00} | data:ExchangeSender_17                   | N/A    | N/A  |
| └─ExchangeSender_17              | 1.00     | 1        | batchCop[tiflash] |               | tiflash_task:{time:3.19s, loops:1, threads:20}                                             | ExchangeType: PassThrough                | N/A    | N/A  |
|   └─HashAgg_14                   | 1.00     | 1        | batchCop[tiflash] |               | tiflash_task:{time:3.19s, loops:1, threads:1}                                              | funcs:count(distinct test.t.a)->Column#4 | N/A    | N/A  |
|     └─ExchangeReceiver_16        | 1.00     | 30950159 | batchCop[tiflash] |               | tiflash_task:{time:1.09s, loops:640, threads:20}                                           |                                          | N/A    | N/A  |
|       └─ExchangeSender_15        | 1.00     | 30950159 | batchCop[tiflash] |               | tiflash_task:{time:1.23s, loops:768, threads:48}                                           | ExchangeType: PassThrough                | N/A    | N/A  |
|         └─HashAgg_6              | 1.00     | 30950159 | batchCop[tiflash] |               | tiflash_task:{time:1.23s, loops:768, threads:3}                                            | group by:test.t.a,                       | N/A    | N/A  |
|           └─TableFullScan_12     | 10000.00 | 64238857 | batchCop[tiflash] | table:t       | tiflash_task:{time:256.9ms, loops:1044, threads:48}                                        | keep order:false, stats:pseudo           | N/A    | N/A  |
+----------------------------------+----------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------+------------------------------------------+--------+------+
7 rows in set (6.24 sec)

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Release note

  • planner/core: thoroughly push down count-distinct agg in the MPP mode.

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot ti-srebot requested a review from a team as a code owner July 1, 2021 07:03
@ti-srebot ti-srebot requested review from hanfei1991 and removed request for a team July 1, 2021 07:03
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/5.0-cherry-pick labels Jul 1, 2021
@ti-srebot ti-srebot added this to the v5.0.3 milestone Jul 1, 2021
@ti-srebot
Copy link
Contributor Author

@hanfei1991 you're already a collaborator in bot's repo.

@ti-chi-bot ti-chi-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 Jul 19, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 20, 2021
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • qw4990
  • rebelice

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 20, 2021
@zhouqiang-cl zhouqiang-cl added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 20, 2021
@zhouqiang-cl
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 3f09286

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@hanfei1991
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

@ti-srebot: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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 merged commit 0b6c3c9 into pingcap:release-5.0 Jul 20, 2021
@hanfei1991 hanfei1991 deleted the release-5.0-3ad894da97d9 branch July 20, 2021 08:32
@zhouqiang-cl zhouqiang-cl modified the milestones: v5.0.3, v5.0.4 Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/5.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants