>From Preetham Poluparthi <[email protected]>:

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


Change subject: [ASTERIXDB-3648][COMP] Fix incorrect replacement of Left Outer 
Joins with Unnest in CBO
......................................................................

[ASTERIXDB-3648][COMP] Fix incorrect replacement of Left Outer Joins with 
Unnest in CBO

- user model changes: no
- storage format changes: no
- interface changes: no

Ext-ref: MB-68691

Change-Id: I3f1d4d093cf1bd23f5db75fce569fd174e8cedb4
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
1 file changed, 16 insertions(+), 13 deletions(-)



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

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
index 8406520..799fb83 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
@@ -308,7 +308,7 @@
                 modifyUnnestInfo = new ArrayList<>();
                 collectUnnestModificationInfo(null, root, cheapestPlanNode);
                 for (int k = 0; k < modifyUnnestInfo.size(); k++) {
-                    modifyTree(null, root, k);
+                    modifyTree(null, 0, root, modifyUnnestInfo.get(k));
                     if (newRootAfterUnnest != null) {
                         root = newRootAfterUnnest;
                     }
@@ -384,30 +384,33 @@
         return false;
     }

-    private void modifyTree(ILogicalOperator parent, ILogicalOperator op, int 
k) {
-        if (modifyUnnestInfo.get(k).second == op) { // found the one to get 
rid off; this should be an OJ
-            int size = modifyUnnestInfo.get(k).third.size();
-            UnnestOperator uOp = (UnnestOperator) 
modifyUnnestInfo.get(k).third.get(size - 1); // UnnestOp is always at the end
+    private void modifyTree(ILogicalOperator parent, int index, 
ILogicalOperator op,
+            Triple<ILogicalOperator, ILogicalOperator, List<ILogicalOperator>> 
modifyUnnestInfoTriple) {
+        if (modifyUnnestInfoTriple.second == op) { // found the one to get rid 
off; this should be an OJ
+            int size = modifyUnnestInfoTriple.third.size();
+            UnnestOperator uOp = (UnnestOperator) 
modifyUnnestInfoTriple.third.get(size - 1); // UnnestOp is always at the end
             uOp.getInputs().get(0).setValue(op.getInputs().get(0).getValue()); 
//The unnestOp is at the lowest position and points to the op below it.
             if (parent == null) { // change is happening at the very top, so 
the root will change
-                newRootAfterUnnest = modifyUnnestInfo.get(k).third.get(0); // 
the first assign that belongs to this unnestOp. Or an only one UnnestOp with no 
assigns
+                newRootAfterUnnest = modifyUnnestInfoTriple.third.get(0); // 
the first assign that belongs to this unnestOp. Or an only one UnnestOp with no 
assigns
                 ILogicalOperator q = newRootAfterUnnest;
-                if (modifyUnnestInfo.get(k).third.size() > 1) {
-                    for (ILogicalOperator p : modifyUnnestInfo.get(k).third) {
-                        q.getInputs().get(0).setValue(p);
+                if (modifyUnnestInfoTriple.third.size() > 1) {
+                    for (ILogicalOperator p : modifyUnnestInfoTriple.third) {
+                        q.getInputs().get(index).setValue(p);
                         q = p;
                     }
                 }
             } else {
                 ILogicalOperator q = parent;
-                for (ILogicalOperator p : modifyUnnestInfo.get(k).third) {
-                    q.getInputs().get(0).setValue(p);
+                for (ILogicalOperator p : modifyUnnestInfoTriple.third) {
+                    q.getInputs().get(index).setValue(p);
                     q = p;
                 }
             }
         }
-        for (Mutable<ILogicalOperator> input : op.getInputs()) {
-            modifyTree(op, input.getValue(), k);
+        int size = op.getInputs().size();
+        for (int i = 0; i < size; i++) {
+            Mutable<ILogicalOperator> input = op.getInputs().get(i);
+            modifyTree(op, i, input.getValue(), modifyUnnestInfoTriple);
         }
     }


--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20426?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: phoenix
Gerrit-Change-Id: I3f1d4d093cf1bd23f5db75fce569fd174e8cedb4
Gerrit-Change-Number: 20426
Gerrit-PatchSet: 1
Gerrit-Owner: Preetham Poluparthi <[email protected]>

Reply via email to