[
https://issues.apache.org/jira/browse/CALCITE-5314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17614141#comment-17614141
]
Stamatis Zampetakis commented on CALCITE-5314:
----------------------------------------------
[~hanu.ncr] feel free to pick it up and I will try to review the changes once I
find some time. If you need to break the task into smaller pieces feel free to
create additional JIRAs and link them to this case.
If the stats are stale the metadata providers should return appropriate values
to indicate that. For instance, RelMdMaxRowCount should return null or
something that won't create problems to rules that may use it.
> 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
> Priority: Major
>
> 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)