Skip to content

[CALCITE-3630] Improve ReduceExpressionsRule - #1686

Merged
chunweilei merged 1 commit into
apache:masterfrom
chunweilei:improve_reduce_expression_rule
Dec 27, 2019
Merged

[CALCITE-3630] Improve ReduceExpressionsRule#1686
chunweilei merged 1 commit into
apache:masterfrom
chunweilei:improve_reduce_expression_rule

Conversation

@chunweilei

Copy link
Copy Markdown
Contributor

call.transformTo(createEmptyRelOrEquivalent(call, filter));
}
// New plan is absolutely better than old plan.
call.getPlanner().setImportance(filter, 0.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

setImportance(filter, 0.0) is not suggested to be used, i kind of remember see https://issues.apache.org/jira/browse/CALCITE-2223

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for sharing, @danny0405 . IMO, if we already do it in this rule[1], it makes sense to do it to be consistent.

[1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L216

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Usages of setImportance indeed require some care. I think, this change for example could lead to a CannotPlanException that could be avoided before.

Assume that we enter the else branch and we create an empty LogicalValues. Then if the rule set does not contain a PhysicalValues we may end-up with a CannotPlanException. Without this change this wouldn't be the case since the old plan could still be matched by other rules and create a PhysicalFilter etc. I admit this is a contrived example but I wanted to highlight that setting importance explicitly might be risky.

@chunweilei chunweilei Dec 27, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Assume that we enter the else branch and we create an empty LogicalValues. Then if the rule set does not contain a PhysicalValues we may end-up with a CannotPlanException.

This is not valid. Because without this change, ReduceExpressionsRule can also create an empty LogicalValues[1]. I agree that we should pay more attention when we use setImportance. But as I mentioned before, what this change does is to be consistent with what the if branch does[2].

[1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L199

[2] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L194-L216

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, I didn't see [1] before.

Other than maybe we could refactor slightly the code to keep the setImportance in one place (in [2]); leaving the decision up to you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO, setImportance should be used as long as the new plan expression is better than old one, means just replace it. Even if there can be exception during planning, it is the fault of VolcanoPlanner, not the fault of setImportance. We should fix the VolcanoPlanner if the exception happens.

@hsyuan hsyuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@chunweilei
chunweilei merged commit 34af9ec into apache:master Dec 27, 2019
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.

4 participants