Skip to content

feat: jdbc set query timeout (#20546) #20550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion develop/dev-guide-timeouts-in-tidb.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ TiDB 还提供了一个系统变量来限制单条 SQL 语句的执行时间,

## JDBC 查询超时

MySQL jdbc 的查询超时设置 `setQueryTimeout()` 对 TiDB 不起作用。这是因为现实客户端感知超时时,向数据库发送一个 KILL 命令。但是由于 tidb-server 是负载均衡的,为防止在错误的 tidb-server 上终止连接,tidb-server 不会执行这个 KILL。这时就要用 `MAX_EXECUTION_TIME` 实现查询超时的效果。
从 v6.1.0 起,当 [`enable-global-kill`](/tidb-configuration-file.md#enable-global-kill-从-v610-版本开始引入) 配置项为默认值 `true` 时,你可以使用 MySQL JDBC 提供的 `setQueryTimeout()` 方法来控制查询的超时时间。

>**注意:**
>
> 当 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 兼容的超时控制参数:

Expand Down