-
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/core: separate aggPrune
from aggPushDown
#7676
Conversation
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.
rest LGTM
Struct renaming changes will be pushed after merged #7680 if there's no need to change the code logic. |
plan/rule_aggregation_elimination.go
Outdated
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
type aggregationRecursiveEliminater struct { |
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.
Eliminator
@winoros PTAL |
/run-all-tests |
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-common-test |
Seems there's precision error. I'm looking into it. |
Emmm... It seems that i need to reuse |
…nto extract-agg-prune
/run-all-tests tidb-test=pr/631 |
fb9b08d
to
3842d88
Compare
aggPrune
from aggPushDown
aggPrune
from aggPushDown
planner/core/optimizer.go
Outdated
@@ -32,23 +32,25 @@ const ( | |||
flagPrunColumns uint64 = 1 << iota | |||
flagEliminateProjection | |||
flagBuildKeyInfo | |||
flagEliminateAgg |
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.
how about moving it after flagDecorrelate
?
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.
Seems reasonable.
@@ -851,7 +851,7 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) { | |||
}, | |||
{ | |||
sql: "select (select count(1) k from t s where s.a = t.a having k != 0) from t", | |||
best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t)->StreamAgg)->StreamAgg->Sel([ne(k, 0)])}(test.t.a,s.a)->Projection->Projection", | |||
best: "MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))->Projection}(test.t.a,s.a)->Projection->Projection", |
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.
First decorrelate
, it becomes select k from t left join (select count(1) k from t s group by a) on s.a=t.a and k != 0
.
Then aggregate eliminate
, it becomes select k from t left join (select if(isnull(1), 0, 1) k from t s) on s.a=t.a and k != 0
. Since if(isnull(1), 0, 1) is always 1. So it simplified as select k from t left join (select 1 k from t s) on s.a=t.a and k != 0
.
Finally predicate push down
, k != 0
pushed down and converted to 1 != 0
which is always true.
So Sel([ne(k, 0)])
is removed after that aggregate eliminate
is operated after decorrelate
.
/run-all-tests |
/run-common-test tidb-test=pr/631 |
/run-common-test tidb-test=pr/631 |
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
What problem does this PR solve?
AggregationPushDown
is closed by default since it's not always better. ButAggregationElimination
is always a good choice.What is changed and how it works?
So separate it from
aggPushDown
Check List
Tests
Related changes
It's one part from #7531.
Release Note
reopen aggregation pruning optimization
.