[
https://issues.apache.org/jira/browse/CALCITE-5314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17615687#comment-17615687
]
Stamatis Zampetakis commented on CALCITE-5314:
----------------------------------------------
I left some review comments in the PR but overall looks good.
The rule can be generalized to match any kind of relational expression as
[~julianhyde] mentioned but I agree with [~hanu.ncr] that it is better to
restrict the default instance to match only table scans. If people want to
enlarge the scope it will be easy to do so via the configuration.
> Prune empty parts of a query by exploiting stats/metadata
> ---------------------------------------------------------
>
> Key: CALCITE-5314
> URL: https://issues.apache.org/jira/browse/CALCITE-5314
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Stamatis Zampetakis
> Assignee: Hanumath Rao Maduri
> Priority: Major
> Labels: pull-request-available
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Currently there is a collection of rules (i.e.,
> [PruneEmptyRules|https://github.com/apache/calcite/blob/4ef9ffe0d4afb80fe95e66d4d9c9e6f5939f70a8/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java])
> which remove sections of a query plan when it does not produce any rows.
> At the moment, the removal requires an empty {{Values}} operator to be in the
> plan in order to take effect. However, there are cases where queries involve
> empty relations/tables and in that case we could remove parts of the plan as
> well.
> The information if a relation is empty or not can be derived from metadata.
> For example, we could check if the
> [RelMdMaxRowCount|https://github.com/apache/calcite/blob/4ef9ffe0d4afb80fe95e66d4d9c9e6f5939f70a8/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java]
> returns zero to derive that the relation is empty.
> Implementation wise there are various alternatives to consider:
> * modify the existing PruneEmptyRule to consider metadata;
> * add new pruning rules relying exclusively on metadata;
> * add new rules checking metadata and turning the empty relation to an empty
> {{Values}} which can then be handled by existing rules
--
This message was sent by Atlassian Jira
(v8.20.10#820010)