You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2021/03/29 16:23:30 UTC

[asterixdb] branch master updated: [NO ISSUE][COMP] Avoid variable reference sharing

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new b0be3fc  [NO ISSUE][COMP] Avoid variable reference sharing
b0be3fc is described below

commit b0be3fc1328d9c0e5ca431861ce457c072875f91
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Fri Mar 26 11:17:14 2021 -0700

    [NO ISSUE][COMP] Avoid variable reference sharing
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - IntroduceSecondaryIndexInsertDeleteRule should
      not share variable reference expressions
    
    Change-Id: I1d8d25cf2ea78016b7f090398656f6dac718e573
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10724
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Reviewed-by: Glenn Galvizo <gg...@uci.edu>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../IntroduceSecondaryIndexInsertDeleteRule.java   | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
index bf87fc0..c3859be 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
@@ -686,9 +686,7 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
         int sourceIndicatorForBaseRecord = workingElement.getSourceIndicator();
         LogicalVariable sourceVarForBaseRecord = hasMetaPart
                 ? ((sourceIndicatorForBaseRecord == Index.RECORD_INDICATOR) ? recordVar : metaVar) : recordVar;
-        VariableReferenceExpression baseRecordVarRef = new VariableReferenceExpression(sourceVarForBaseRecord);
-        baseRecordVarRef.setSourceLocation(sourceLoc);
-        UnnestBranchCreator branchCreator = new UnnestBranchCreator(baseRecordVarRef, unnestSourceOp);
+        UnnestBranchCreator branchCreator = new UnnestBranchCreator(sourceVarForBaseRecord, unnestSourceOp);
 
         int initialKeyPositionQueueSize = keyPositionQueue.size();
         Set<LogicalVariable> secondaryKeyVars = new HashSet<>();
@@ -739,7 +737,7 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
                 for (int j = 1; j < workingElement.getProjectList().size(); j++) {
                     LogicalVariable newVar = context.newVar();
                     AbstractFunctionCallExpression newVarRef =
-                            getFieldAccessFunction(new MutableObject<>(branchCreator.lastRecordVarRef), -1,
+                            getFieldAccessFunction(new MutableObject<>(branchCreator.createLastRecordVarRef()), -1,
                                     workingElement.getProjectList().get(j));
 
                     AssignOperator newAssignOp = new AssignOperator(newVar, new MutableObject<>(newVarRef));
@@ -988,12 +986,12 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
      */
     private class UnnestBranchCreator implements ArrayIndexUtil.TypeTrackerCommandExecutor {
         private final List<LogicalVariable> lastFieldVars;
-        private VariableReferenceExpression lastRecordVarRef;
+        private LogicalVariable lastRecordVar;
         private ILogicalOperator currentTop, currentBottom;
         private boolean isFirstWalk = true;
 
-        public UnnestBranchCreator(VariableReferenceExpression recordVarRef, ILogicalOperator sourceOperator) {
-            this.lastRecordVarRef = recordVarRef;
+        public UnnestBranchCreator(LogicalVariable recordVar, ILogicalOperator sourceOperator) {
+            this.lastRecordVar = recordVar;
             this.currentTop = sourceOperator;
             this.lastFieldVars = new ArrayList<>();
         }
@@ -1006,6 +1004,12 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
             isFirstWalk = false;
         }
 
+        public VariableReferenceExpression createLastRecordVarRef() {
+            VariableReferenceExpression varRef = new VariableReferenceExpression(lastRecordVar);
+            varRef.setSourceLocation(sourceLoc);
+            return varRef;
+        }
+
         @SafeVarargs
         public final void applyProjectDistinct(List<Mutable<ILogicalExpression>>... auxiliaryExpressions)
                 throws AlgebricksException {
@@ -1061,9 +1065,9 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
             if (isFirstUnnestInStep) {
                 // This is the first UNNEST step. Get the field we want to UNNEST from our record.
                 accessToUnnestVar = (startingStepRecordType != null)
-                        ? getFieldAccessFunction(new MutableObject<>(lastRecordVarRef),
+                        ? getFieldAccessFunction(new MutableObject<>(createLastRecordVarRef()),
                                 startingStepRecordType.getFieldIndex(fieldName.get(0)), fieldName)
-                        : getFieldAccessFunction(new MutableObject<>(lastRecordVarRef), -1, fieldName);
+                        : getFieldAccessFunction(new MutableObject<>(createLastRecordVarRef()), -1, fieldName);
             } else {
                 // This is the second+ UNNEST step. Refer back to the previously unnested variable.
                 accessToUnnestVar = new VariableReferenceExpression(this.lastFieldVars.get(0));
@@ -1086,8 +1090,7 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
 
             if (isLastUnnestInIntermediateStep) {
                 // This is the last UNNEST before the next array step. Update our record variable.
-                this.lastRecordVarRef = new VariableReferenceExpression(unnestVar);
-                this.lastRecordVarRef.setSourceLocation(sourceLoc);
+                this.lastRecordVar = unnestVar;
                 this.lastFieldVars.clear();
             }
         }
@@ -1102,9 +1105,9 @@ public class IntroduceSecondaryIndexInsertDeleteRule implements IAlgebraicRewrit
 
             // Create the function to access our final field.
             AbstractFunctionCallExpression accessToFinalVar = (startingStepRecordType != null)
-                    ? getFieldAccessFunction(new MutableObject<>(lastRecordVarRef),
+                    ? getFieldAccessFunction(new MutableObject<>(createLastRecordVarRef()),
                             startingStepRecordType.getFieldIndex(fieldName.get(0)), fieldName)
-                    : getFieldAccessFunction(new MutableObject<>(lastRecordVarRef), -1, fieldName);
+                    : getFieldAccessFunction(new MutableObject<>(createLastRecordVarRef()), -1, fieldName);
 
             LogicalVariable finalVar = context.newVar();
             this.lastFieldVars.add(finalVar);