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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d6dcf962a93 [Enhancement](page cache) insert into setting to disable 
page cache (#28913)
d6dcf962a93 is described below

commit d6dcf962a9385b27659989795bd40a03be445683
Author: 赵硕 <1443539...@qq.com>
AuthorDate: Fri Dec 29 15:11:41 2023 +0800

    [Enhancement](page cache) insert into setting to disable page cache (#28913)
---
 .../java/org/apache/doris/analysis/QueryStmt.java  |  4 ++
 .../nereids/processor/pre/PlanPreprocessors.java   |  3 +-
 .../pre/TurnOffPageCacheForInsertIntoSelect.java   | 66 ++++++++++++++++++++++
 .../java/org/apache/doris/qe/StmtExecutor.java     |  6 ++
 4 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
index e92fcc2c8f2..c1d879fd060 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java
@@ -824,6 +824,10 @@ public abstract class QueryStmt extends StatementBase 
implements Queriable {
         this.fromInsert = value;
     }
 
+    public boolean isFromInsert() {
+        return fromInsert;
+    }
+
     @Override
     public abstract QueryStmt clone();
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/PlanPreprocessors.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/PlanPreprocessors.java
index 9dfc12b2c10..dad0a4d07f0 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/PlanPreprocessors.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/PlanPreprocessors.java
@@ -46,7 +46,8 @@ public class PlanPreprocessors {
     public List<PlanPreprocessor> getProcessors() {
         // add processor if we need
         return ImmutableList.of(
-                new TurnOffPipelineForDml()
+                new TurnOffPipelineForDml(),
+                new TurnOffPageCacheForInsertIntoSelect()
         );
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/TurnOffPageCacheForInsertIntoSelect.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/TurnOffPageCacheForInsertIntoSelect.java
new file mode 100644
index 00000000000..77955a94114
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/pre/TurnOffPageCacheForInsertIntoSelect.java
@@ -0,0 +1,66 @@
+// 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.doris.nereids.processor.pre;
+
+import org.apache.doris.analysis.SetVar;
+import org.apache.doris.analysis.StringLiteral;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.analyzer.UnboundTableSink;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFileSink;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOlapTableSink;
+import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.VariableMgr;
+
+/**
+ * TODO turnoff pagecache for insert into select
+ */
+public class TurnOffPageCacheForInsertIntoSelect extends PlanPreprocessor {
+
+    @Override
+    public Plan visitUnboundTableSink(UnboundTableSink<? extends Plan> 
unboundTableSink,
+            StatementContext context) {
+        turnOffPageCache(context);
+        return unboundTableSink;
+    }
+
+    @Override
+    public Plan visitLogicalFileSink(LogicalFileSink<? extends Plan> fileSink, 
StatementContext context) {
+        turnOffPageCache(context);
+        return fileSink;
+    }
+
+    @Override
+    public Plan visitLogicalOlapTableSink(LogicalOlapTableSink<? extends Plan> 
tableSink, StatementContext context) {
+        turnOffPageCache(context);
+        return tableSink;
+    }
+
+    private void turnOffPageCache(StatementContext context) {
+        SessionVariable sessionVariable = 
context.getConnectContext().getSessionVariable();
+        // set temporary session value, and then revert value in the 'finally 
block' of StmtExecutor#execute
+        sessionVariable.setIsSingleSetVar(true);
+        try {
+            VariableMgr.setVar(sessionVariable,
+                new SetVar(SessionVariable.ENABLE_PAGE_CACHE, new 
StringLiteral("false")));
+        } catch (Throwable t) {
+            throw new AnalysisException("Can not set turn off page cache for 
insert into select", t);
+        }
+    }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 2851304dc37..25f2f2e2e28 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -886,8 +886,14 @@ public class StmtExecutor {
         if (statement instanceof SelectStmt) {
             SelectStmt selectStmt = (SelectStmt) statement;
             Map<String, String> optHints = 
selectStmt.getSelectList().getOptHints();
+            if (optHints == null) {
+                optHints = new HashMap<>();
+            }
             if (optHints != null) {
                 sessionVariable.setIsSingleSetVar(true);
+                if (selectStmt.isFromInsert()) {
+                    optHints.put("enable_page_cache", "false");
+                }
                 for (String key : optHints.keySet()) {
                     VariableMgr.setVar(sessionVariable, new SetVar(key, new 
StringLiteral(optHints.get(key))));
                 }


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

Reply via email to