amansinha100 commented on a change in pull request #1744: Drill 7148 - Join 
order, multi-col ndv and aggregate rowcount fixes for TPCH queries
URL: https://github.com/apache/drill/pull/1744#discussion_r275079302
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
 ##########
 @@ -667,4 +667,66 @@ public static DrillTable getDrillTable(final TableScan 
scan) {
     }
     return drillTable;
   }
+
+  public static List<Pair<Integer, Integer>> analyzeSimpleEquiJoin(Join join) {
+    List<Pair<Integer, Integer>> joinConditions = new ArrayList<>();
+    try {
+      RexVisitor<Void> visitor =
+          new RexVisitorImpl<Void>(true) {
+            public Void visitCall(RexCall call) {
+              if (call.getKind() == SqlKind.AND || call.getKind() == 
SqlKind.OR) {
+                super.visitCall(call);
+              } else {
+                if (call.getKind() == SqlKind.EQUALS) {
+                  int leftFieldCount = 
join.getLeft().getRowType().getFieldCount();
+                  int rightFieldCount = 
join.getRight().getRowType().getFieldCount();
+                  RexNode leftComparand = call.operands.get(0);
+                  RexNode rightComparand = call.operands.get(1);
+                  RexInputRef leftFieldAccess = (RexInputRef) leftComparand;
+                  RexInputRef rightFieldAccess = (RexInputRef) rightComparand;
+                  if (leftFieldAccess.getIndex() >= leftFieldCount + 
rightFieldCount ||
+                      rightFieldAccess.getIndex() >= leftFieldCount + 
rightFieldCount) {
+                    joinConditions.clear();
+                    throw new Util.FoundOne(call);
+                  }
+                  /* Both columns reference same table */
+                  if ((leftFieldAccess.getIndex() >= leftFieldCount &&
 
 Review comment:
   If you have a condition such as t1.a1 = t1.b1, in theory this should not 
cause problems since the NDV of a1 and b1 is known and we can use the same join 
cardinality formula.  

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to