Stamatis Zampetakis created CALCITE-7803:
--------------------------------------------
Summary: Extract rewritable materialized view fragments from
queries
Key: CALCITE-7803
URL: https://issues.apache.org/jira/browse/CALCITE-7803
Project: Calcite
Issue Type: Improvement
Components: core
Reporter: Stamatis Zampetakis
Assignee: Stamatis Zampetakis
The MaterializedViewRules impose limitations on the shape of a query/plan that
can be used for query rewriting. There is a [validity
check|https://github.com/apache/calcite/blob/34db6c8cd895998f38175efc3e3306311fc7d061/core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewRule.java#L503]
that must be satisfied both by the operator matching the rule and the
materialized view candidate. In a nutshell only SPJA query/plans are allowed
with a few additional restrictions.
The goal of this ticket is to add a new API/utility able to extract rewritable
materialized view fragments form an input query/plan. A fragment is rewritable
if it passes the validity check present in the materialized view rules. The
visitor should only extract maximal fragments; no containment relationships
among fragments.
Consider the following query having a union with two branches. Observe that
both of the branches are rewritable but the whole query is not due to the union.
+Input+
{code:sql}
SELECT ename FROM emp WHERE empno = 1
UNION
SELECT ename FROM emp WHERE empno = 2
{code}
+Fragment 1+
{code:sql}
SELECT ename FROM emp WHERE empno = 1
{code}
+Fragment 2+
{code:sql}
SELECT ename FROM emp WHERE empno = 2
{code}
The {{SELECT ename FROM emp}} is also a rewritable fragment but its not maximal
thus its not part of the result. The examples above appear in SQL but the
algorithm applies at the algebra (RelNode) level.
The API is meant to support optimizations around common table expressions and
materialized views. For instance, it can be used for workload analysis to
generate view based recommendations.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)