You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "asdfgh19 (via GitHub)" <gi...@apache.org> on 2023/04/25 07:26:40 UTC

[GitHub] [calcite] asdfgh19 commented on a diff in pull request #3169: [CALCITE-5665] Reducing ineffective matches for MaterializedViewRules

asdfgh19 commented on code in PR #3169:
URL: https://github.com/apache/calcite/pull/3169#discussion_r1176113352


##########
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewRule.java:
##########
@@ -92,6 +96,16 @@
 public abstract class MaterializedViewRule<C extends MaterializedViewRule.Config>
     extends RelRule<C> {
 
+  /**
+   * Cache of RelMetadataQuery to MaterializationMetadata.
+   */
+  private final LoadingCache<RelMetadataQuery, MaterializationMetadata>
+      materializationMetadataCache =
+      CacheBuilder.newBuilder()
+          .expireAfterAccess(5, TimeUnit.MINUTES)
+          .maximumSize(1_024)
+          .build(CacheLoader.from(MaterializationMetadata::new));

Review Comment:
   > Is `1_024` a typo?
   
   Not a typo, this is a reference to QuerySqlStatisticProvider#SILENT_CACHING_INSTANCE, in order to be consistent with the existing code style.



##########
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewRule.java:
##########
@@ -1426,6 +1448,61 @@ protected enum MatchModality {
     QUERY_PARTIAL
   }
 
+  /**
+   * Check if the materialization is valid for this rule.
+   * If it does, cache the materialization's RelTableRef and RelOptPredicateList.
+   */
+  protected class MaterializationMetadata {
+    private final Set<RelOptMaterialization> notValidMaterializations = new HashSet<>();
+    private final Map<RelOptMaterialization, Set<RelTableRef>> viewTableRefsMap = new HashMap<>();
+    private final Map<RelOptMaterialization, RelOptPredicateList>
+        viewPredicateListMap = new HashMap<>();
+
+    protected boolean isValidMaterialization(
+        RelMetadataQuery mq, RelOptMaterialization materialization) {
+      if (notValidMaterializations.contains(materialization)) {
+        return false;
+      } else if (viewTableRefsMap.containsKey(materialization)) {
+        return true;

Review Comment:
   > Should we use `viewTableRefsMap.containsKey(materialization) && viewPredicateListMap.containsKey(materialization)` to be more accurate?
   
   Indeed we should.Thanks for your suggestion and review!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org