mariadb/mysql-test/main/opt_hint_timeout.result
Oleg Smirnov a8c1655c84 MDEV-37035 Improve opt_hint_timeout.test to avoid sporadic failures caused by timing
Some queries of the test case used to execute too fast, which caused
`opt_hint_timeout` test failures. This commit replaces those queries
with more complex ones to make sure they cannot be executed in
a couple of milliseconds.
2025-07-13 13:55:32 +07:00

115 lines
4.8 KiB
Text

#
# MAX_EXECUTION_TIME hint testing
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 SELECT seq FROM seq_1_to_5000;
# Correct hint usage
SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(0001490) */* FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5000 100.00
Warnings:
Note 1003 select /*+ MAX_EXECUTION_TIME(0001490) */ `test`.`t1`.`a` AS `a` from `test`.`t1`
SELECT /*+ MAX_EXECUTION_TIME(20) */ *, SLEEP(1) FROM t1 UNION SELECT 1, 2;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
(SELECT /*+ MAX_EXECUTION_TIME(300) */ *, SLEEP(1) FROM t1) UNION (SELECT 1, 2);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
((SELECT /*+ MAX_EXECUTION_TIME(500) */ *, SLEEP(1) FROM t1));
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
# Make sure the hint overrides global/session/statement settings.
# Global setting 30 seconds, won't be exceeded for sure
SET @@max_statement_time = 30;
SELECT /*+ MAX_EXECUTION_TIME(10)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
# Session setting 30 seconds, too long to be exceeded
SET SESSION max_statement_time = 30;
SELECT /*+ MAX_EXECUTION_TIME(15) */ count(*) FROM t1 a natural join t1 b natural join t1 c;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
SET STATEMENT max_statement_time = 20 FOR
SELECT /*+ MAX_EXECUTION_TIME(5)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
# Check that prepared statements process the hint correctly
PREPARE s FROM 'SELECT /*+ MAX_EXECUTION_TIME(20) */ seq, SLEEP(1) FROM seq_1_to_10';
EXECUTE s;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
EXECUTE s;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
# Hint duplication
SELECT /*+ MAX_EXECUTION_TIME(50000) MAX_EXECUTION_TIME(100) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 4219 Hint MAX_EXECUTION_TIME(100) is ignored as conflicting/duplicated
# Wrong values
SELECT /*+ MAX_EXECUTION_TIME(0) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 1912 Incorrect value '0' for option 'MAX_EXECUTION_TIME'
SELECT /*+ MAX_EXECUTION_TIME(-1) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 1064 Optimizer hint syntax error near '-1) */ count(*) FROM t1' at line 1
SELECT /*+ MAX_EXECUTION_TIME(4294967296) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 1912 Incorrect value '4294967296' for option 'MAX_EXECUTION_TIME'
# only SELECT statements support the MAX_EXECUTION_TIME hint (warning):
CREATE TABLE t2 (i INT);
INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1;
Warnings:
Warning 4225 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
INSERT INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
REPLACE /*+ MAX_EXECUTION_TIME(15) */ INTO t2 SELECT 1;
Warnings:
Warning 4225 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
REPLACE INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
UPDATE /*+ MAX_EXECUTION_TIME(23) */ t2 SET i = 1;
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(23)' is not allowed in this context
DELETE /*+ MAX_EXECUTION_TIME(5000) */ FROM t2 WHERE i = 1;
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(5000)' is not allowed in this context
# Not supported inside stored procedures/functions
CREATE PROCEDURE p1() BEGIN SELECT /*+ MAX_EXECUTION_TIME(10) */ count(*) FROM t1 a, t1 b
INTO @a; END|
CALL p1();
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
DROP PROCEDURE p1;
# Hint in a subquery is not allowed (warning):
SELECT 1 FROM (SELECT /*+ MAX_EXECUTION_TIME(10) */ 1) a;
1
1
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
# Hint is allowed only for the first select of UNION (warning):
SELECT /*+ MAX_EXECUTION_TIME(50000) */ count(*) FROM t1
UNION
SELECT /*+ MAX_EXECUTION_TIME(3) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 4219 Hint MAX_EXECUTION_TIME(3) is ignored as conflicting/duplicated
SELECT count(*) FROM t1
UNION
SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1;
count(*)
5000
Warnings:
Warning 4172 'MAX_EXECUTION_TIME(30)' is not allowed in this context
# Check that hint actually works:
SELECT /*+ MAX_EXECUTION_TIME(20) */ count(*), SLEEP(1) FROM t1
UNION
SELECT count(*), SLEEP(1) FROM t1;
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
DROP TABLE t1, t2;