[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Query rewriting materialized view rules


I have some confusion regarding the query rewriting rules in Calcite and I was hoping someone could help me with that.
Looking at the documentation of materialized views http://calcite.apache.org/docs/materialized_views#materialized-views-maintained-by-calcite
and in the source code, I found there are 2 systems in place for rewriting queries to use materialized views. There is the unify rules found in https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java with an extension to materialized views found in https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/plan/MaterializedViewSubstitutionVisitor.java
And there is the materialized view rules found in https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/AbstractMaterializedViewRule.java

Since I am not that experienced working with Calcite, I was wondering if someone could shed some light about these 2 query rewriting systems. Are they supposed to be used independently or in conjunction? Do they try to solve the same thing or is one rewriting system better for some queries than others? (for instance, if I want a query to be rewritten to use materialized views, would that better fit the MaterializedViewSubstitutionVisitor or the AbstractMaterializedViewRule).

If someone could help me out to better understand how calcite does its rewritings, that would be great.