Use the SOCKET_TIMEOUT hint to override the default timeout for a specific SQL statement. This is useful for long-running operations—such as bulk writes or full-table scans—that are expected to exceed the default limit.
This topic applies to PolarDB-X 1.0 V5.3 and later.
Background
PolarDB-X 1.0 applies a default timeout of 900 seconds to SQL statements running on both PolarDB-X 1.0 instances and ApsaraDB RDS instances. For statements that legitimately require more time, use the SOCKET_TIMEOUT hint to set a per-statement timeout without changing the global configuration.
Syntax
/*+TDDL:SOCKET_TIMEOUT(time)*/
The time value is in milliseconds.
Usage notes
PolarDB-X 1.0 hints support two formats:
| Format | Requires -c flag in mysql client |
|---|---|
/*+TDDL:hint_command*/ |
Yes |
/!+TDDL:hint_command*/ |
No |
When using the /*+TDDL:hint_command*/ format with the MySQL command-line client (mysql), add the -c flag to the login command. Without -c, the client strips comments before sending the statement to the server. Because PolarDB-X 1.0 hints in this format are defined as MySQL comments, they are removed and cannot take effect. For all available mysql client options, see mysql client options.
Example
Set the timeout for a single SELECT statement to 40 seconds (40,000 milliseconds):
/*+TDDL:SOCKET_TIMEOUT(40000)*/SELECT * FROM t_item;
A longer timeout keeps database connections open for more time. If many long-running statements run concurrently, database resources can be exhausted and PolarDB-X 1.0 services may become unavailable. Optimize slow SQL statements whenever possible rather than relying solely on increased timeouts.