>From Rithwik Koul <[email protected]>:

Rithwik Koul has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21345?usp=email )


Change subject: [ASTERIXDB-3183][COMP] scenerio where cacheVlaue only contain  
IlogicalPlan
......................................................................

[ASTERIXDB-3183][COMP] scenerio where cacheVlaue only contain  IlogicalPlan

Change-Id: Id152e2ea2d60303f4bcfe007aa1211f83f3151f0
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cache/QueryCacheValue.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
M 
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
3 files changed, 29 insertions(+), 33 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/45/21345/1

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cache/QueryCacheValue.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cache/QueryCacheValue.java
index b935ff9..78822de 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cache/QueryCacheValue.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cache/QueryCacheValue.java
@@ -21,8 +21,8 @@

 import java.util.Set;

-import org.apache.asterix.metadata.entities.EntityDetails;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
+import org.apache.hyracks.api.exceptions.Warning;

 /**
  * A query plan cache entry. Rather than caching a fully built {@link 
org.apache.hyracks.api.job.JobSpecification}
@@ -34,34 +34,25 @@
  * <p>Job generation is read-only over the cached plan, so two requests may 
regenerate a job from the same entry
  * concurrently without locking.
  *
- * <p>{@code accessedEntities} is the set of datasets/views/functions the 
query reads, captured at compile (miss)
- * time. Authorization is enforced from this set ({@code 
AuthorizationProvider*.ensureAuthorized}); because a cache
- * hit skips compilation (which is what normally populates it), the hit path 
must replay this set into the request's
- * {@code MetadataProvider} so a user whose access was revoked is still 
denied. See {@code QueryTranslator.handleQuery}.
+ * <p>{@code warnings} is the set of compile-time warnings produced while 
compiling the query (miss) time, e.g.
+ * {@code RemoveDuplicateFieldsRule} emitting {@code 
COMPILATION_DUPLICATE_FIELD_NAME}. A cache hit skips the
+ * rewrite + optimize phases that emit these warnings, so the hit path replays 
this set into the request's
+ * {@code WarningCollector} to preserve identical warning feedback across 
runs. See {@code QueryTranslator.handleQuery}.
  */
 public class QueryCacheValue {
     private final ILogicalPlan plan;
-    // The optimization context's variable counter as of the end of the 
(miss-path) compilation, i.e. the highest
-    // variable id allocated in the cached plan. A cache hit seeds its fresh 
optimization context with this value so
-    // any variables allocated during job generation do not collide with ids 
already present in the cached plan.
-    private final int varCounter;
-    private final Set<EntityDetails> accessedEntities;
+    private final Set<Warning> warnings;

-    public QueryCacheValue(ILogicalPlan plan, int varCounter, 
Set<EntityDetails> accessedEntities) {
+    public QueryCacheValue(ILogicalPlan plan, Set<Warning> warnings) {
         this.plan = plan;
-        this.varCounter = varCounter;
-        this.accessedEntities = accessedEntities;
+        this.warnings = warnings;
     }

     public ILogicalPlan getPlan() {
         return plan;
     }

-    public int getVarCounter() {
-        return varCounter;
-    }
-
-    public Set<EntityDetails> getAccessedEntities() {
-        return accessedEntities;
+    public Set<Warning> getWarnings() {
+        return warnings;
     }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index eaed557..fa7b468 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -4681,13 +4681,13 @@
             Map<String, IAObject> stmtParams, IRequestParameters 
requestParameters)
             throws AlgebricksException, ACIDException {
         return rewriteCompileQuery(clusterInfoCollector, metadataProvider, 
query, stmt, stmtParams, requestParameters,
-                null, null, 0);
+                null, null);
     }

     public JobSpecification rewriteCompileQuery(IClusterInfoCollector 
clusterInfoCollector,
             MetadataProvider metadataProvider, Query query, 
ICompiledDmlStatement stmt,
             Map<String, IAObject> stmtParams, IRequestParameters 
requestParameters,
-            org.apache.asterix.translator.ResultMetadata resultMetadata, 
ILogicalPlan cachePlan, int cachedVarCounter)
+            org.apache.asterix.translator.ResultMetadata resultMetadata, 
ILogicalPlan cachePlan)
             throws AlgebricksException, ACIDException {

         Map<VarIdentifier, IAObject> externalVars = 
createExternalVariables(query, stmtParams);
@@ -4698,14 +4698,9 @@
         Pair<IReturningStatement, Integer> rewrittenResult = 
apiFramework.reWriteQuery(langRewritingContext, query,
                 sessionOutput, true, true, externalVars.keySet());

-        // On a cache hit (cachePlan != null) the rewritten query is discarded 
in favor of the cached optimized plan,
-        // so seed compilation with the cached plan's (post-optimize) var 
counter instead of the post-rewrite value to
-        // avoid variable-id collisions during job generation.
-        int planVarCounter = cachePlan != null ? cachedVarCounter : 
rewrittenResult.second;
-
         // Query Compilation (happens under the same ongoing metadata 
transaction)
         return apiFramework.compileQuery(clusterInfoCollector, 
metadataProvider, (Query) rewrittenResult.first,
-                planVarCounter, stmt == null ? null : stmt.getDatasetName(), 
sessionOutput, stmt, externalVars,
+                rewrittenResult.second, stmt == null ? null : 
stmt.getDatasetName(), sessionOutput, stmt, externalVars,
                 responsePrinter, warningCollector, requestParameters, 
jobFlags, resultMetadata, cachePlan);
     }

@@ -5688,7 +5683,7 @@
                 final JobSpecification jobSpec;
                 if (ignoreCache) {
                     jobSpec = rewriteCompileQuery(hcc, metadataProvider, 
query, null, stmtParams, requestParameters,
-                            resultMetadata, null, 0);
+                            resultMetadata, null);
                     stats.setWasFetchedFromPlanCache(false);
                 } else {
                     // Key on the raw request text (the resultSetId in the key 
disambiguates statements within a
@@ -5754,12 +5749,15 @@
             Pair<QueryCacheKey, QueryCacheValue> toCache, QueryCacheKey 
cacheKey) throws AlgebricksException {
         final JobSpecification jobSpec;
         jobSpec = rewriteCompileQuery(hcc, metadataProvider, query, null, 
stmtParams, requestParameters, resultMetadata,
-                null, 0);
+                null);
         final Pair<ILogicalPlan, IOptimizationContext> compiledPlan = 
apiFramework.getLastCompiledPlan();
         if (compiledPlan != null && compiledPlan.first != null && 
compiledPlan.second != null) {
             toCache.setFirst(cacheKey);
-            toCache.setSecond(new QueryCacheValue(compiledPlan.first, 
compiledPlan.second.getVarCounter(),
-                    Set.copyOf(metadataProvider.getAccessedEntities())));
+            // Snapshot the compile-time warnings produced by rewrite + 
optimize (e.g. duplicate-field) so a later
+            // hit, which skips those phases, can replay them and preserve 
identical warning feedback.
+            Set<Warning> warnings = new LinkedHashSet<>();
+            warningCollector.getWarnings(warnings, Long.MAX_VALUE);
+            toCache.setSecond(new QueryCacheValue(compiledPlan.first, 
warnings));
         }
         stats.setWasFetchedFromPlanCache(false);
         return jobSpec;
@@ -5770,7 +5768,14 @@
             Map<String, IAObject> stmtParams, 
org.apache.asterix.translator.ResultMetadata resultMetadata,
             QueryCacheValue cacheValue, QueryCacheKey cacheKey) throws 
AlgebricksException {
         final JobSpecification jobSpec = rewriteCompileQuery(hcc, 
metadataProvider, query, null, stmtParams,
-                requestParameters, resultMetadata, cacheValue.getPlan(), 
cacheValue.getVarCounter());
+                requestParameters, resultMetadata, cacheValue.getPlan());
+        // The hit path skipped the rewrite + optimize phases that emit 
compile-time warnings; replay the warnings
+        // captured at miss time through the per-request collector so repeated 
runs report identically.
+        for (Warning warning : cacheValue.getWarnings()) {
+            if (warningCollector.shouldWarn()) {
+                warningCollector.warn(warning);
+            }
+        }
         stats.setWasFetchedFromPlanCache(true);
         return jobSpec;
     }
diff --git 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
index 5e2a3be..eb0dee1 100644
--- 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
+++ 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
@@ -74,7 +74,7 @@
         }
     }

-    private void runLogicalOptimizationSets(ILogicalPlan plan,
+    private void  runLogicalOptimizationSets(ILogicalPlan plan,
             List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> 
optimizationSet)
             throws AlgebricksException {
         if (AlgebricksConfig.ALGEBRICKS_LOGGER.isTraceEnabled()) {

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21345?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Id152e2ea2d60303f4bcfe007aa1211f83f3151f0
Gerrit-Change-Number: 21345
Gerrit-PatchSet: 1
Gerrit-Owner: Rithwik Koul <[email protected]>

Reply via email to