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

[CALCITE-6891] Implement IntersectReorderRule #4244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xiedeyantu
Copy link
Contributor

link: CALCITE-6891

@xiedeyantu xiedeyantu force-pushed the ireorder branch 2 times, most recently from 43da23d to 8024ac1 Compare March 16, 2025 02:09
@xiedeyantu xiedeyantu changed the title [CALCITE-6880] Implement IntersectReorderRule [CALCITE-6891] Implement IntersectReorderRule Mar 18, 2025
final List<Pair<RelNode, Double>> inputsWithRowCounts = new ArrayList<>();

for (RelNode input : inputs) {
Double rowCount = mq.getRowCount(input);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@xiedeyantu xiedeyantu force-pushed the ireorder branch 2 times, most recently from aa60449 to 2e02a7b Compare March 23, 2025 12:21
}

@Override public void onMatch(RelOptRuleCall call) {
final Intersect intersect = call.rel(0);
Copy link
Contributor

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 -> {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants