You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Hanumath Rao Maduri (Jira)" <ji...@apache.org> on 2022/10/07 15:47:00 UTC

[jira] [Commented] (CALCITE-5314) Prune empty parts of a query by exploiting stats/metadata

    [ https://issues.apache.org/jira/browse/CALCITE-5314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17614130#comment-17614130 ] 

Hanumath Rao Maduri commented on CALCITE-5314:
----------------------------------------------

[~zabetak] Thanks for creating this JIRA. I am working on exactly same optimization to exploit the stats and prune out the empty subgraphs using existing PruneEmptyRules. The only catch here is that Stats are expected to be Stale, but in our case we guarantee atleast cardinality of the table not to be Stale. 

I chose the approach three listed out in the description.
 * add new rules checking metadata and turning the empty relation to an empty {{Values}} which can then be handled by existing rules

The reasoning was this enables to switch on / off the empty table optimization by just turning on/off this single rule (which is simple and easy).

I would love to contribute to this JIRA.
h4.

> 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)