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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 2626981e41b [feature](expr) Support kill query by query_id (#28530) 
(#30130)
2626981e41b is described below

commit 2626981e41bb67a6d853667a7b27c4b988a26cf5
Author: Mingyu Chen <[email protected]>
AuthorDate: Fri Jan 19 17:55:40 2024 +0800

    [feature](expr) Support kill query by query_id (#28530) (#30130)
---
 .../Database-Administration-Statements/KILL.md           | 11 ++++++++++-
 .../Database-Administration-Statements/KILL.md           | 12 +++++++++++-
 fe/fe-core/src/main/cup/sql_parser.cup                   |  4 ++++
 .../main/java/org/apache/doris/analysis/KillStmt.java    | 12 ++++++++++++
 .../src/main/java/org/apache/doris/common/ErrorCode.java |  1 +
 .../main/java/org/apache/doris/qe/ConnectScheduler.java  |  9 +++++++++
 .../src/main/java/org/apache/doris/qe/StmtExecutor.java  | 16 +++++++++++++---
 7 files changed, 60 insertions(+), 5 deletions(-)

diff --git 
a/docs/en/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
 
b/docs/en/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
index 04106a48f1f..67f948c9640 100644
--- 
a/docs/en/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
+++ 
b/docs/en/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
@@ -39,9 +39,18 @@ The thread process list identifier can be determined from 
the ID column of the I
 grammar:
 
 ```sql
-KILL [CONNECTION | QUERY] processlist_id
+KILL [CONNECTION] processlist_id
 ````
 
+In addition, you can also use processlist_id or query_id terminates the 
executing query command
+
+grammar:
+
+```sql
+KILL QUERY processlist_id | query_id
+````
+
+
 ### Example
 
 ### Keywords
diff --git 
a/docs/zh-CN/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
 
b/docs/zh-CN/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
index c671abcc5e7..d35cdfa3145 100644
--- 
a/docs/zh-CN/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
+++ 
b/docs/zh-CN/docs/sql-manual/sql-reference/Database-Administration-Statements/KILL.md
@@ -39,9 +39,19 @@ KILL
 语法:
 
 ```sql
-KILL [CONNECTION | QUERY] processlist_id
+KILL [CONNECTION] processlist_id
 ```
 
+除此之外,您还可以使用 processlist_id 或者 query_id 终止正在执行的查询命令
+
+语法:
+
+```sql
+KILL QUERY processlist_id | query_id
+```
+
+
+
 ### Example
 
 ### Keywords
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 18ca4f4a1a1..9e0ae035bde 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -4928,6 +4928,10 @@ kill_stmt ::=
     {:
         RESULT = new KillStmt(false, value.intValue());
     :}
+    | KW_KILL KW_QUERY STRING_LITERAL:value
+    {:
+        RESULT = new KillStmt(value);
+    :}
     ;
 
 kill_analysis_job_stmt ::=
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/KillStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/KillStmt.java
index 56f4f24d231..77cbafe4a8f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/KillStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/KillStmt.java
@@ -25,10 +25,18 @@ package org.apache.doris.analysis;
 public class KillStmt extends StatementBase {
     private final boolean isConnectionKill;
     private final int connectionId;
+    private final String queryId;
 
     public KillStmt(boolean isConnectionKill, int connectionId) {
         this.isConnectionKill = isConnectionKill;
         this.connectionId = connectionId;
+        this.queryId = "";
+    }
+
+    public KillStmt(String queryId) {
+        this.isConnectionKill = false;
+        this.connectionId = -1;
+        this.queryId = queryId;
     }
 
     public boolean isConnectionKill() {
@@ -39,6 +47,10 @@ public class KillStmt extends StatementBase {
         return connectionId;
     }
 
+    public String getQueryId() {
+        return queryId;
+    }
+
     @Override
     public void analyze(Analyzer analyzer) {
         // No operation.
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
index 66f97b27e04..a6800db6274 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/ErrorCode.java
@@ -43,6 +43,7 @@ public enum ErrorCode {
     ERR_NO_SUCH_THREAD(1094, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown 
thread id: %d"),
     ERR_KILL_DENIED_ERROR(1095, new byte[]{'H', 'Y', '0', '0', '0'}, "You are 
not owner of thread %d"),
     ERR_NO_TABLES_USED(1096, new byte[]{'H', 'Y', '0', '0', '0'}, "No tables 
used"),
+    ERR_NO_SUCH_QUERY(1097, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown 
query id: %s"),
     ERR_WRONG_DB_NAME(1102, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect 
database name '%s'"),
     ERR_WRONG_TABLE_NAME(1103, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect 
table name '%s'. Table name regex is '%s'"),
     ERR_TOO_BIG_SELECT(1104, new byte[]{'4', '2', '0', '0', '0'}, "The SELECT 
would examine more than MAX_JOIN_SIZE "
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java
index acc9ffa0c84..bbc31a32dc7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java
@@ -122,6 +122,15 @@ public class ConnectScheduler {
         return connectionMap.get(connectionId);
     }
 
+    public ConnectContext getContextWithQueryId(String queryId) {
+        for (ConnectContext context : connectionMap.values()) {
+            if (queryId.equals(DebugUtil.printId(context.queryId))) {
+                return context;
+            }
+        }
+        return null;
+    }
+
     public void cancelQuery(String queryId) {
         for (ConnectContext ctx : connectionMap.values()) {
             TUniqueId qid = ctx.queryId();
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 28cb6e21beb..b764fbccc6d 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
@@ -1199,11 +1199,21 @@ public class StmtExecutor {
     // Handle kill statement.
     private void handleKill() throws DdlException {
         KillStmt killStmt = (KillStmt) parsedStmt;
+        ConnectContext killCtx = null;
         int id = killStmt.getConnectionId();
-        ConnectContext killCtx = context.getConnectScheduler().getContext(id);
-        if (killCtx == null) {
-            ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_THREAD, id);
+        String queryId = killStmt.getQueryId();
+        if (id == -1) {
+            killCtx = 
context.getConnectScheduler().getContextWithQueryId(queryId);
+            if (killCtx == null) {
+                ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_QUERY, 
queryId);
+            }
+        } else {
+            killCtx = context.getConnectScheduler().getContext(id);
+            if (killCtx == null) {
+                ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_THREAD, 
id);
+            }
         }
+
         if (context == killCtx) {
             // Suicide
             context.setKilled();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to