From 4fbec8e79b39a4883e1479b3e75803f1744e260e Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 24 Jun 2025 10:59:26 +0800 Subject: [PATCH 1/3] feat: jdbc set query timeout --- develop/dev-guide-timeouts-in-tidb.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/develop/dev-guide-timeouts-in-tidb.md b/develop/dev-guide-timeouts-in-tidb.md index 1babbf916c2b..2bf5bbcb5338 100644 --- a/develop/dev-guide-timeouts-in-tidb.md +++ b/develop/dev-guide-timeouts-in-tidb.md @@ -51,7 +51,9 @@ TiDB 还提供了一个系统变量来限制单条 SQL 语句的执行时间, ## JDBC 查询超时 -MySQL jdbc 的查询超时设置 `setQueryTimeout()` 对 TiDB 不起作用。这是因为现实客户端感知超时时,向数据库发送一个 KILL 命令。但是由于 tidb-server 是负载均衡的,为防止在错误的 tidb-server 上终止连接,tidb-server 不会执行这个 KILL。这时就要用 `MAX_EXECUTION_TIME` 实现查询超时的效果。 +对于 `v6.1` 及之后版本的 TiDB,`enable-global-kill` 的参数默认为 `true`, 你可以使用 MySQL JDBC 的查询超时设置 `setQueryTimeout()` 来控制查询超时。 + +然而,`setQueryTimeout()` 对 `v6.1` 版本前的 TiDB 不起作用。这是因为客户端在超时后,会向数据库发送一个 KILL 命令。但是由于 tidb-server 是负载均衡的,为防止在错误的 tidb-server 上终止连接,tidb-server 不会执行这个 KILL。这时就要用 `MAX_EXECUTION_TIME` 实现查询超时的效果。 TiDB 提供了三个与 MySQL 兼容的超时控制参数: From 738b6307e0f04212ce3c857117196ca663758c7d Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 24 Jun 2025 16:04:26 +0800 Subject: [PATCH 2/3] Update develop/dev-guide-timeouts-in-tidb.md Co-authored-by: Grace Cai --- develop/dev-guide-timeouts-in-tidb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/develop/dev-guide-timeouts-in-tidb.md b/develop/dev-guide-timeouts-in-tidb.md index 2bf5bbcb5338..d10c08a5cf5f 100644 --- a/develop/dev-guide-timeouts-in-tidb.md +++ b/develop/dev-guide-timeouts-in-tidb.md @@ -51,7 +51,7 @@ TiDB 还提供了一个系统变量来限制单条 SQL 语句的执行时间, ## JDBC 查询超时 -对于 `v6.1` 及之后版本的 TiDB,`enable-global-kill` 的参数默认为 `true`, 你可以使用 MySQL JDBC 的查询超时设置 `setQueryTimeout()` 来控制查询超时。 +从 v6.1.0 起,当 [`enable-global-kill`](/tidb-configuration-file.md#enable-global-kill-从-v610-版本开始引入) 配置项为默认值 `true` 时,你可以使用 MySQL JDBC 提供的 `setQueryTimeout()` 方法来控制查询的超时时间。 然而,`setQueryTimeout()` 对 `v6.1` 版本前的 TiDB 不起作用。这是因为客户端在超时后,会向数据库发送一个 KILL 命令。但是由于 tidb-server 是负载均衡的,为防止在错误的 tidb-server 上终止连接,tidb-server 不会执行这个 KILL。这时就要用 `MAX_EXECUTION_TIME` 实现查询超时的效果。 From 68440e79bd0f6068ac42e3835eade6fbff66d087 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 24 Jun 2025 16:04:37 +0800 Subject: [PATCH 3/3] Update develop/dev-guide-timeouts-in-tidb.md Co-authored-by: Grace Cai --- develop/dev-guide-timeouts-in-tidb.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/develop/dev-guide-timeouts-in-tidb.md b/develop/dev-guide-timeouts-in-tidb.md index d10c08a5cf5f..dad88b4214ac 100644 --- a/develop/dev-guide-timeouts-in-tidb.md +++ b/develop/dev-guide-timeouts-in-tidb.md @@ -53,7 +53,9 @@ TiDB 还提供了一个系统变量来限制单条 SQL 语句的执行时间, 从 v6.1.0 起,当 [`enable-global-kill`](/tidb-configuration-file.md#enable-global-kill-从-v610-版本开始引入) 配置项为默认值 `true` 时,你可以使用 MySQL JDBC 提供的 `setQueryTimeout()` 方法来控制查询的超时时间。 -然而,`setQueryTimeout()` 对 `v6.1` 版本前的 TiDB 不起作用。这是因为客户端在超时后,会向数据库发送一个 KILL 命令。但是由于 tidb-server 是负载均衡的,为防止在错误的 tidb-server 上终止连接,tidb-server 不会执行这个 KILL。这时就要用 `MAX_EXECUTION_TIME` 实现查询超时的效果。 +>**注意:** +> +> 当 TiDB 版本低于 v6.1.0 或 [`enable-global-kill`](/tidb-configuration-file.md#enable-global-kill-从-v610-版本开始引入) 为 `false` 时,`setQueryTimeout()` 对 TiDB 不起作用。这是因为查询超时后,客户端会向数据库发送一条 `KILL` 命令。但是由于 TiDB 服务是负载均衡的,为防止 `KILL` 命令在错误的 TiDB 节点上终止连接,TiDB 不会执行该命令。此时,可以通过设置 `max_execution_time` 实现查询超时控制。 TiDB 提供了三个与 MySQL 兼容的超时控制参数: