From 312af5d32c376cb0d4ed4dcac320e0ffbfc569b1 Mon Sep 17 00:00:00 2001 From: EmmyMiao87 <522274284@qq.com> Date: Fri, 13 Nov 2020 15:24:57 +0800 Subject: [PATCH] Avoid duplicate column when adding slot in empty tuple Fixed #4900 --- .../doris/planner/SingleNodePlanner.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index fd81c33facf3c9..98d05e80e5cf3c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -1401,7 +1401,7 @@ private PlanNode createScanNode(Analyzer analyzer, TableRef tblRef, SelectStmt s if ((tblRef.getJoinOp().isInnerJoin() || tblRef.getJoinOp().isLeftOuterJoin())) { List allConjuncts = analyzer.getConjuncts(analyzer.getAllTupleIds()); allConjuncts.removeAll(conjuncts); - for (Expr conjunct: allConjuncts) { + for (Expr conjunct : allConjuncts) { if (org.apache.doris.analysis.Predicate.canPushDownPredicate(conjunct)) { for (Expr eqJoinPredicate : eqJoinPredicates) { // we can ensure slot is left node, because NormalizeBinaryPredicatesRule @@ -1473,7 +1473,7 @@ private Expr rewritePredicate(Analyzer analyzer, Expr oldPredicate, Expr leftChi if (oldPredicate instanceof InPredicate) { InPredicate oldIP = (InPredicate) oldPredicate; - InPredicate ip = new InPredicate(leftChild, oldIP.getListChildren(), oldIP.isNotIn()); + InPredicate ip = new InPredicate(leftChild, oldIP.getListChildren(), oldIP.isNotIn()); ip.analyzeNoThrow(analyzer); return ip; } @@ -1898,10 +1898,11 @@ private void materializeTableResultForCrossJoinOrCountStar(TableRef tblRef, Anal * Inner tuple: tuple 0 with a not materialized slot k1 * In the above two cases, it is necessary to add a mini column to the inner tuple * to ensure that the number of rows in the inner query result is the number of rows in the table. - * + *

* After this function, the inner tuple is following: * case1. tuple 0: slot materialized true (new slot) * case2. tuple 0: slot materialized true (changed) + * * @param tblRef * @param analyzer */ @@ -1915,9 +1916,14 @@ private void materializeSlotForEmptyMaterializedTableRef(BaseTableRef tblRef, An } } if (minimuColumn != null) { - SlotDescriptor slot = analyzer.getDescTbl().addSlotDescriptor(tblRef.getDesc()); - slot.setColumn(minimuColumn); - slot.setIsMaterialized(true); + SlotDescriptor slot = tblRef.getDesc().getColumnSlot(minimuColumn.getName()); + if (slot != null) { + slot.setIsMaterialized(true); + } else { + slot = analyzer.getDescTbl().addSlotDescriptor(tblRef.getDesc()); + slot.setColumn(minimuColumn); + slot.setIsMaterialized(true); + } } } } @@ -2087,7 +2093,7 @@ private List getPredicatesBoundedByGroupbysSourceExpr(List predicate } else { // if grouping type is GROUPING_SETS and the predicate not in all grouping list, // the predicate cannot be push down - for (List exprs: stmt.getGroupByClause().getGroupingSetList()) { + for (List exprs : stmt.getGroupByClause().getGroupingSetList()) { if (!exprs.contains(sourceExpr)) { isAllSlotReferingGroupBys = false; break;