You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/02/20 09:38:41 UTC

[iotdb] branch lmh/planPushDown created (now 17dbac9ffe)

This is an automated email from the ASF dual-hosted git repository.

hui pushed a change to branch lmh/planPushDown
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 17dbac9ffe tmp save

This branch includes the following new commits:

     new 17dbac9ffe tmp save

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: tmp save

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/planPushDown
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 17dbac9ffee838c4a92cff5a8fb71e7c7ba681e4
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Mon Feb 20 17:38:10 2023 +0800

    tmp save
---
 .../optimization/LimitOffsetPushDownOptimizer.java | 42 ++++++++++++++++++++++
 .../planner/distribution/DistributionPlanner.java  | 12 +++++--
 .../iotdb/db/mpp/plan/statement/Statement.java     |  2 +-
 .../db/mpp/plan/statement/crud/QueryStatement.java | 13 +++++++
 .../plan/statement/sys/ShowQueriesStatement.java   |  5 +++
 5 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/optimization/LimitOffsetPushDownOptimizer.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/optimization/LimitOffsetPushDownOptimizer.java
new file mode 100644
index 0000000000..088d38a020
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/optimization/LimitOffsetPushDownOptimizer.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.mpp.plan.optimization;
+
+import org.apache.iotdb.db.mpp.common.MPPQueryContext;
+import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanVisitor;
+
+public class LimitOffsetPushDownOptimizer implements PlanOptimizer {
+
+  @Override
+  public PlanNode optimize(PlanNode plan, MPPQueryContext context) {
+    return null;
+  }
+
+  private static class Rewriter extends PlanVisitor<PlanNode, RewriterContext> {
+    @Override
+    public PlanNode visitPlan(PlanNode node, RewriterContext context) {
+      return null;
+    }
+  }
+
+  private static class RewriterContext {
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/DistributionPlanner.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/DistributionPlanner.java
index 0c564a3fa1..e52724453c 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/DistributionPlanner.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/DistributionPlanner.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.db.mpp.common.MPPQueryContext;
 import org.apache.iotdb.db.mpp.common.PlanFragmentId;
 import org.apache.iotdb.db.mpp.plan.analyze.Analysis;
 import org.apache.iotdb.db.mpp.plan.analyze.QueryType;
+import org.apache.iotdb.db.mpp.plan.optimization.LimitOffsetPushDownOptimizer;
 import org.apache.iotdb.db.mpp.plan.planner.IFragmentParallelPlaner;
 import org.apache.iotdb.db.mpp.plan.planner.plan.DistributedQueryPlan;
 import org.apache.iotdb.db.mpp.plan.planner.plan.FragmentInstance;
@@ -33,7 +34,6 @@ import org.apache.iotdb.db.mpp.plan.planner.plan.node.WritePlanNode;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.process.ExchangeNode;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.sink.FragmentSinkNode;
 import org.apache.iotdb.db.mpp.plan.statement.crud.QueryStatement;
-import org.apache.iotdb.db.mpp.plan.statement.sys.ShowQueriesStatement;
 
 import java.util.List;
 
@@ -74,12 +74,18 @@ public class DistributionPlanner {
   public DistributedQueryPlan planFragments() {
     PlanNode rootAfterRewrite = rewriteSource();
     PlanNode rootWithExchange = addExchangeNode(rootAfterRewrite);
-    if (analysis.getStatement() instanceof QueryStatement
-        || analysis.getStatement() instanceof ShowQueriesStatement) {
+    if (analysis.getStatement().isQuery()) {
       analysis
           .getRespDatasetHeader()
           .setColumnToTsBlockIndexMap(rootWithExchange.getOutputColumnNames());
     }
+    if (analysis.getStatement() instanceof QueryStatement) {
+      QueryStatement queryStatement = (QueryStatement) analysis.getStatement();
+      if (!queryStatement.isAggregationQuery()
+          && (queryStatement.hasLimit() || queryStatement.hasOffset())) {
+        rootWithExchange = new LimitOffsetPushDownOptimizer().optimize(rootWithExchange, context);
+      }
+    }
     SubPlan subPlan = splitFragment(rootWithExchange);
     // Mark the root Fragment of root SubPlan as `root`
     subPlan.getPlanFragment().setRoot(true);
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/Statement.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/Statement.java
index a3730c89a0..3962bae22b 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/Statement.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/Statement.java
@@ -55,7 +55,7 @@ public abstract class Statement extends StatementNode {
   }
 
   public boolean isQuery() {
-    return statementType == StatementType.QUERY;
+    return false;
   }
 
   public boolean isAuthenticationRequired() {
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java
index 2fb401d6a9..dce073b72f 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java
@@ -116,6 +116,11 @@ public class QueryStatement extends Statement {
     this.statementType = StatementType.QUERY;
   }
 
+  @Override
+  public boolean isQuery() {
+    return true;
+  }
+
   @Override
   public List<PartialPath> getPaths() {
     Set<PartialPath> authPaths = new HashSet<>();
@@ -373,6 +378,14 @@ public class QueryStatement extends Statement {
     isCqQueryBody = cqQueryBody;
   }
 
+  public boolean hasLimit() {
+    return rowLimit > 0;
+  }
+
+  public boolean hasOffset() {
+    return rowOffset > 0;
+  }
+
   public void semanticCheck() {
     if (isAggregationQuery()) {
       if (disableAlign()) {
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/sys/ShowQueriesStatement.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/sys/ShowQueriesStatement.java
index 1b3439519d..aca81f0b42 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/sys/ShowQueriesStatement.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/sys/ShowQueriesStatement.java
@@ -44,6 +44,11 @@ public class ShowQueriesStatement extends ShowStatement {
 
   public ShowQueriesStatement() {}
 
+  @Override
+  public boolean isQuery() {
+    return true;
+  }
+
   @Override
   public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
     return visitor.visitShowQueries(this, context);