From 26a4e5c8627cce89659fd15aa8fc8078eb30a8a1 Mon Sep 17 00:00:00 2001 From: Huqing Yan Date: Tue, 14 Dec 2021 13:41:32 +0800 Subject: [PATCH] inner-1519 (#3000) * inner-1519 * subquery contains only one table --- .../dble/plan/optimizer/JoinChooser.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/actiontech/dble/plan/optimizer/JoinChooser.java b/src/main/java/com/actiontech/dble/plan/optimizer/JoinChooser.java index 21dbbec6e..7382b5f0f 100644 --- a/src/main/java/com/actiontech/dble/plan/optimizer/JoinChooser.java +++ b/src/main/java/com/actiontech/dble/plan/optimizer/JoinChooser.java @@ -665,19 +665,34 @@ public class JoinChooser { } - private ERTable getERKey(PlanNode tn, Item c) { - if (!(c instanceof ItemField)) - return null; - if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) { - return null; + private boolean onlyContainsOneTable(PlanNode queryNode) { + PlanNode child = queryNode.getChildren().get(0); + if (child.type() == PlanNode.PlanNodeType.TABLE) { + return true; + } else if (child.type() == PlanNode.PlanNodeType.QUERY) { + return onlyContainsOneTable(child); + } else { + return false; + } + } + + private ERTable getERKey(PlanNode tn, Item column) { + if (!(column instanceof ItemField)) + return null; + Pair pair = null; + if (tn.type() == PlanNode.PlanNodeType.QUERY && onlyContainsOneTable(tn)) { + pair = PlanUtil.findColumnInTableLeaf((ItemField) column, tn); + } else if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) { + return null; + } else { + pair = PlanUtil.findColumnInTableLeaf((ItemField) column, tn); } - Pair pair = PlanUtil.findColumnInTableLeaf((ItemField) c, tn); if (pair == null) return null; TableNode tableNode = pair.getKey(); ItemField col = pair.getValue(); ERTable erTable = new ERTable(tableNode.getSchema(), tableNode.getPureName(), col.getItemName()); - if (tn.type() == PlanNode.PlanNodeType.TABLE) { + if (tn.type() == PlanNode.PlanNodeType.TABLE || tn.type() == PlanNode.PlanNodeType.QUERY) { return erTable; } else { List erList = ((JoinNode) tn).getERkeys();