You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/07/03 03:04:54 UTC

[GitHub] [incubator-doris] spaces-X commented on a change in pull request #4000: applyInnerJoinConditionReorganizeRule

spaces-X commented on a change in pull request #4000:
URL: https://github.com/apache/incubator-doris/pull/4000#discussion_r449353484



##########
File path: fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
##########
@@ -816,9 +816,103 @@ protected void reorderTable(Analyzer analyzer) throws AnalysisException {
 
         // can not get AST only with equal join, MayBe cross join can help
         fromClause_.clear();
+        List<Pair<Expr, Expr>> misMatchJoinConditions = Lists.newArrayList();
+        List<TupleId> tupleIds = Lists.newArrayList();
+
         for (Pair<TableRef, Long> candidate : candidates) {
-            fromClause_.add(candidate.first);
+            TableRef tableRef = candidate.first;
+            fromClause_.add(tableRef);
+            tupleIds.add(tableRef.desc.getId());
+            applyInnerJoinConditionReorganizeRule(tableRef, tupleIds, misMatchJoinConditions);
+        }
+
+        Preconditions.checkState(misMatchJoinConditions.isEmpty());
+    }
+
+    /**
+     *  After adjusting the order of tables, it is necessary to reselect the join condition of each table,
+     *  otherwise some columns will not be recognized by the current table space
+     * @param tableRef:
+     * @param tupleIds: TableSpaces visible up to now
+     * @param misMatchJoinConditions: join conditions no matching yet, the first is fatherExpr, the second is sonExpr need to replace
+     */
+    void applyInnerJoinConditionReorganizeRule(TableRef tableRef, List<TupleId> tupleIds,
+                List<Pair<Expr, Expr>> misMatchJoinConditions) {
+        List<Pair<Expr, Expr>> tempMisMatchConjuncts = Lists.newArrayList();
+
+        // Extract all join conditions from joinOnClause to misMatchJoinConditions,
+        // which cannot be bound by existing tableSpaces(tupleIds)
+        findUnboundedJoinConditions(tableRef.getOnClause(), tupleIds, misMatchJoinConditions);
+
+        for (Pair<Expr, Expr> exprPair : misMatchJoinConditions) {
+            Expr father = exprPair.first;
+            Expr expr = exprPair.second;
+            if (!expr.isBoundByTupleIds(tupleIds)) {
+                tempMisMatchConjuncts.add(new Pair<Expr, Expr>(null, expr));
+                if (father.getChild(0) == expr) {

Review comment:
       father may be null here.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org