-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: fix a corner case in column pruning rule #10974
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10974 +/- ##
===========================================
Coverage 81.0119% 81.0119%
===========================================
Files 418 418
Lines 89335 89335
===========================================
Hits 72372 72372
Misses 11731 11731
Partials 5232 5232 |
planner/core/rule_column_pruning.go
Outdated
return err | ||
} | ||
la.AggFuncs = []*aggregation.AggFuncDesc{one} | ||
la.schema.Columns = []*expression.Column{{TblName: model.NewCIStr("dummy_cnt"), RetType: types.NewFieldType(mysql.TypeLonglong)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fill ColName
and UniqueID
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks
planner/core/rule_column_pruning.go
Outdated
if len(la.GroupByItems) == 0 && len(la.AggFuncs) == 0 { | ||
// If all the aggregate functions are pruned and there is no group-by item, we should add | ||
// an aggregate function to keep the correctness. | ||
one, err := aggregation.NewAggFuncDesc(la.ctx, ast.AggFuncCount, []expression.Expression{expression.One}, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using first_row(1)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right... first_row
is better
planner/core/rule_column_pruning.go
Outdated
@@ -117,6 +119,17 @@ func (la *LogicalAggregation) PruneColumns(parentUsedCols []*expression.Column) | |||
for _, aggrFunc := range la.AggFuncs { | |||
selfUsedCols = expression.ExtractColumnsFromExpressions(selfUsedCols, aggrFunc.Args, nil) | |||
} | |||
if len(la.GroupByItems) == 0 && len(la.AggFuncs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If len(la.GroupByItems) > 0 && len(la.AggFuncs) == 0
, we'd better add this dummy aggregation function as well. Though the result is correct now, we are depending on the specific implementation of executor, if executor is changed in the future, we may have problem for this case then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation
e9cb460
to
3259bac
Compare
3259bac
to
3fd835b
Compare
addressed, thank you @eurekaka |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
needs to be cherry-picked to release-2.1 and release-3.0 |
OKay |
What problem does this PR solve?
This PR tries to close #9125
What is changed and how it works?
For a
LogicalAggregation
, if all of its functions are pruned and it doesn't have group-by items, a dummy aggregate function is added to keep the correctness.Check List
Tests
Side effects
Related changes