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

push aggregation operators down to projection and union by default #22072

Closed
qw4990 opened this issue Dec 29, 2020 · 2 comments · Fixed by #22090
Closed

push aggregation operators down to projection and union by default #22072

qw4990 opened this issue Dec 29, 2020 · 2 comments · Fixed by #22090
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Dec 29, 2020

Development Task

mysql> explain select sum(col1) from ( select (case when a=1 then 1 else 0 end) as col1 from t ) a;
+-----------------------------+----------+-----------+---------------+------------------------------------------------+
| id                          | estRows  | task      | access object | operator info                                  |
+-----------------------------+----------+-----------+---------------+------------------------------------------------+
| HashAgg_6                   | 1.00     | root      |               | funcs:sum(Column#6)->Column#4                  |
| └─Projection_14             | 10000.00 | root      |               | cast(Column#3, decimal(22,0) BINARY)->Column#6 |
|   └─Projection_8            | 10000.00 | root      |               | case(eq(test.t.a, 1), 1, 0)->Column#3          |
|     └─TableReader_10        | 10000.00 | root      |               | data:TableFullScan_9                           |
|       └─TableFullScan_9     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                 |
+-----------------------------+----------+-----------+---------------+------------------------------------------------+
5 rows in set (0.00 sec)
mysql> set @@tidb_opt_agg_push_down=1;
Query OK, 0 rows affected (0.00 sec)
mysql> explain select sum(col1) from ( select (case when a=1 then 1 else 0 end) as col1 from t ) a;
+----------------------------+----------+-----------+---------------+--------------------------------------------------+
| id                         | estRows  | task      | access object | operator info                                    |
+----------------------------+----------+-----------+---------------+--------------------------------------------------+
| StreamAgg_17               | 1.00     | root      |               | funcs:sum(Column#7)->Column#4                    |
| └─TableReader_18           | 1.00     | root      |               | data:StreamAgg_9                                 |
|   └─StreamAgg_9            | 1.00     | cop[tikv] |               | funcs:sum(case(eq(test.t.a, 1), 1, 0))->Column#7 |
|     └─TableFullScan_16     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                   |
+----------------------------+----------+-----------+---------------+--------------------------------------------------+
4 rows in set (0.00 sec)

Whether aggregation operators are pushed down to projection and union is controlled by a variable tidb_opt_agg_push_down.
This rule always leads to a better plan, so we can enable this rule by default.

@qw4990 qw4990 added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Dec 29, 2020
@TszKitLo40
Copy link
Contributor

I want to try this issue.

@qw4990
Copy link
Contributor Author

qw4990 commented Dec 29, 2020

I want to try this issue.

Thanks, please connect me at Slack if you have any question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants