-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[CALCITE-6891] Implement IntersectReorderRule #4244
base: main
Are you sure you want to change the base?
Conversation
43da23d
to
8024ac1
Compare
|
final List<Pair<RelNode, Double>> inputsWithRowCounts = new ArrayList<>(); | ||
|
||
for (RelNode input : inputs) { | ||
Double rowCount = mq.getRowCount(input); |
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.
Do we only need to assess whether RowCount can be replaced by Cumulative Cost? Or just consider RowCount only.
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.
Do we only need to assess whether RowCount can be replaced by Cumulative Cost? Or just consider RowCount only.
Thanks, I thought about your question. In intersect, the number of output columns of the children is equal. In my opinion, RowCount may represent cost.
core/src/main/java/org/apache/calcite/rel/rules/IntersectReorderRule.java
Outdated
Show resolved
Hide resolved
aa60449
to
2e02a7b
Compare
} | ||
|
||
@Override public void onMatch(RelOptRuleCall call) { | ||
final Intersect intersect = call.rel(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.
I suggest it could be simpler here, For example:
final Intersect intersect = call.rel(0);
final RelMetadataQuery mq = call.getMetadataQuery();
final List<RelNode> inputs = intersect.getInputs();
List<RelNode> sortedInputs = inputs.stream()
.sorted(Comparator.comparingDouble(input -> mq.getRowCount(input)))
.collect(Collectors.toList());
if (inputs.equals(sortedInputs)) {
return;
}
final RelBuilder relBuilder = call.builder();
relBuilder.pushAll(sortedInputs);
relBuilder.intersect(intersect.all, sortedInputs.size());
call.transformTo(relBuilder.build());
+ "intersect\n" | ||
+ "select deptno from dept\n"; | ||
|
||
sql(sql).withVolcanoPlanner(true, p -> { |
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.
Maybe it would be clearer to apply the rules by adding different filters for the same scan in the test case.
link: CALCITE-6891