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

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

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


##########
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?



##########
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? 



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