This is an automated email from the ASF dual-hosted git repository. caogaofei pushed a commit to branch beyyes/join in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b95142ff69e23f00026bf7901f61151ab2e7b2da Author: Beyyes <[email protected]> AuthorDate: Fri Aug 16 12:30:12 2024 +0800 add SortMergeJoin --- .../planner/iterative/rule/SortMergeJoin.java | 57 ++++++++++++++++++++++ .../optimizations/LogicalOptimizeFactory.java | 6 +++ 2 files changed, 63 insertions(+) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/SortMergeJoin.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/SortMergeJoin.java new file mode 100644 index 00000000000..9e7634fae4e --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/SortMergeJoin.java @@ -0,0 +1,57 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.rule; + +import org.apache.iotdb.db.queryengine.plan.relational.planner.SortOrder; +import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol; +import org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.Rule; +import org.apache.iotdb.db.queryengine.plan.relational.planner.node.JoinNode; +import org.apache.iotdb.db.queryengine.plan.relational.planner.node.SortNode; +import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Captures; +import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Pattern; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.Patterns.join; + +public class SortMergeJoin implements Rule<JoinNode> { + private static final Pattern<JoinNode> PATTERN = join(); + + @Override + public Pattern<JoinNode> getPattern() { + return PATTERN; + } + + @Override + public Result apply(JoinNode node, Captures captures, Context context) { + List<JoinNode.EquiJoinClause> criteria = node.getCriteria(); + List<Symbol> orderBy = new ArrayList<>(); + Map<Symbol, SortOrder> orderings = new HashMap<>(); + // OrderingScheme scheme = new OrderingScheme(); + + JoinNode newJoinNode = (JoinNode) node.clone(); + SortNode leftSortNode = + new SortNode( + context.getIdAllocator().genPlanNodeId(), node.getLeftChild(), null, false, false); + SortNode rightSortNode = + new SortNode( + context.getIdAllocator().genPlanNodeId(), node.getLeftChild(), null, false, false); + newJoinNode.setLeftChild(leftSortNode); + newJoinNode.setRightChild(rightSortNode); + return Result.ofPlanNode(node); + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/LogicalOptimizeFactory.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/LogicalOptimizeFactory.java index d0ed1b6e42e..e0a1a824ca7 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/LogicalOptimizeFactory.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/LogicalOptimizeFactory.java @@ -49,6 +49,12 @@ public class LogicalOptimizeFactory { PlanOptimizer pushPredicateIntoTableScanOptimizer = new PushPredicateIntoTableScan(); PlanOptimizer transformSortToStreamSortOptimizer = new TransformSortToStreamSort(); + IterativeOptimizer usingSortMegeJoinOptimizer = + new IterativeOptimizer( + plannerContext, + new RuleStatsRecorder(), + ImmutableSet.of(new InlineProjections(plannerContext))); + Set<Rule<?>> columnPruningRules = ImmutableSet.of( new PruneFilterColumns(),
