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: do not eliminate group_concat in aggregate elimination #9967

Merged
merged 5 commits into from
Apr 1, 2019

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Apr 1, 2019

What problem does this PR solve?

fix #9922

What is changed and how it works?

Do not eliminate group_concat considering system variable group_concat_max_len.

Actually, we can rewrite GROUP_CONCAT when all the arguments it
accepts are promised to be NOT-NULL. (Recorded as a task in #9968)
When it accepts only 1 argument, we can extract this argument into a
projection.
When it accepts multiple arguments, we can wrap the arguments with a
function CONCAT_WS and extract this function into a projection.
BUT, GROUP_CONCAT should truncate the final result according to the
system variable group_concat_max_len. To ensure the correctness of
the result, we close the elimination of GROUP_CONCAT here.

Check List

Tests

  • Integration test

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression
    Performance may regress when group_concat accepts only 1 argument.

Related changes

  • Need to cherry-pick to the release branch

@zz-jason zz-jason changed the title planner, executor: do not eliminate group_concat considering group_concat_max_len planner: do not eliminate group_concat in aggregate elimination Apr 1, 2019
@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 1, 2019

PTAL @zz-jason
Issue created as #9968

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 1, 2019

/run-all-tests

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 the status/LGT1 Indicates that a PR has LGTM 1. label Apr 1, 2019
@@ -36,6 +36,19 @@ type aggregationEliminateChecker struct {
// For count(expr), sum(expr), avg(expr), count(distinct expr, [expr...]) we may need to rewrite the expr. Details are shown below.
// If we can eliminate agg successful, we return a projection. Else we return a nil pointer.
func (a *aggregationEliminateChecker) tryToEliminateAggregation(agg *LogicalAggregation) *LogicalProjection {
for _, af := range agg.AggFuncs {
// TODO: Actually, we can rewrite GROUP_CONCAT.
// When it accepts only 1 argument, we can extract this argument into a
Copy link
Member

Choose a reason for hiding this comment

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

This case is easy to be added in this pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noop, since group_concat_max_len is configurable.
We can not ensure whether the length of the final result exceeds max_len even if there is only 1 argument.

And, maybe it'll be easier to implement if we wrap the argument(s) into a concat_ws despite the count of the arguments.

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Apr 1, 2019

/run-all-tests

@codecov
Copy link

codecov bot commented Apr 1, 2019

Codecov Report

Merging #9967 into master will increase coverage by 0.0067%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master      #9967        +/-   ##
================================================
+ Coverage   77.4704%   77.4772%   +0.0067%     
================================================
  Files           403        404         +1     
  Lines         81777      81775         -2     
================================================
+ Hits          63353      63357         +4     
+ Misses        13707      13704         -3     
+ Partials       4717       4714         -3

@XuHuaiyu XuHuaiyu requested a review from winoros April 1, 2019 03:43
Copy link
Contributor

@eurekaka eurekaka 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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 1, 2019
@zz-jason
Copy link
Member

zz-jason commented Apr 1, 2019

/run-unit-test

@XuHuaiyu XuHuaiyu merged commit 4c91f53 into pingcap:master Apr 1, 2019
@XuHuaiyu XuHuaiyu deleted the agg_eliminate branch April 1, 2019 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong aggEliminateCheck for select group_concat() group by unique
4 participants