You can create SQL bindings with the MAX_EXECUTION_TIME
hint to limit the execution time of a particular statement to a small value (for example, 1ms). In this way, the statement is terminated automatically by the threshold.
For example, to prevent the execution of SELECT * FROM t1, t2 WHERE t1.id = t2.id
, you can use the following SQL binding to limit the execution time of the statement to 1ms:
CREATE GLOBAL BINDING for
SELECT * FROM t1, t2 WHERE t1.id = t2.id
USING
SELECT /*+ MAX_EXECUTION_TIME(1) */ * FROM t1, t2 WHERE t1.id = t2.id;
Note:
The precision of
MAX_EXECUTION_TIME
is roughly 100ms. Before TiDB terminates the SQL statement, the tasks in TiKV might be started. To reduce the TiKV resource consumption in such case, it is recommended to settidb_enable_paging
toON
.
Dropping this SQL binding will remove the limit.
DROP GLOBAL BINDING for
SELECT * FROM t1, t2 WHERE t1.id = t2.id;