|
| 1 | +# |
| 2 | +# MAX_EXECUTION_TIME hint testing |
| 3 | +# |
| 4 | +CREATE TABLE t1 (a INT, b VARCHAR(300)); |
| 5 | +INSERT INTO t1 VALUES (1, 'string'); |
| 6 | +INSERT INTO t1 SELECT * FROM t1; |
| 7 | +INSERT INTO t1 SELECT * FROM t1; |
| 8 | +INSERT INTO t1 SELECT * FROM t1; |
| 9 | +INSERT INTO t1 SELECT * FROM t1; |
| 10 | +INSERT INTO t1 SELECT * FROM t1; |
| 11 | +INSERT INTO t1 SELECT * FROM t1; |
| 12 | +INSERT INTO t1 SELECT * FROM t1; |
| 13 | +INSERT INTO t1 SELECT * FROM t1; |
| 14 | +INSERT INTO t1 SELECT * FROM t1; |
| 15 | +# Correct hint usage |
| 16 | +SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b; |
| 17 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 18 | +EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(000149) */* FROM t1; |
| 19 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 20 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 512 100.00 |
| 21 | +Warnings: |
| 22 | +Note 1003 select /*+ MAX_EXECUTION_TIME(000149) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` |
| 23 | +SELECT /*+ MAX_EXECUTION_TIME(20) */ *, SLEEP(1) FROM t1 UNION SELECT 1, 2, 3; |
| 24 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 25 | +(SELECT /*+ MAX_EXECUTION_TIME(30) */ *, SLEEP(1) FROM t1) UNION (SELECT 1, 2, 3); |
| 26 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 27 | +((SELECT /*+ MAX_EXECUTION_TIME(50) */ *, SLEEP(1) FROM t1)); |
| 28 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 29 | +# Check that prepared statements process the hint correctly |
| 30 | +PREPARE s FROM 'SELECT /*+ MAX_EXECUTION_TIME(20) */ seq, SLEEP(1) FROM seq_1_to_10'; |
| 31 | +EXECUTE s; |
| 32 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 33 | +EXECUTE s; |
| 34 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 35 | +# Hint duplication |
| 36 | +SELECT /*+ MAX_EXECUTION_TIME(10) MAX_EXECUTION_TIME(100) */ count(*) FROM t1; |
| 37 | +count(*) |
| 38 | +512 |
| 39 | +Warnings: |
| 40 | +Warning 4202 Hint MAX_EXECUTION_TIME(100) is ignored as conflicting/duplicated |
| 41 | +# Wrong values |
| 42 | +SELECT /*+ MAX_EXECUTION_TIME(0) */ count(*) FROM t1; |
| 43 | +count(*) |
| 44 | +512 |
| 45 | +Warnings: |
| 46 | +Warning 1912 Incorrect value '0' for option 'MAX_EXECUTION_TIME' |
| 47 | +SELECT /*+ MAX_EXECUTION_TIME(-1) */ count(*) FROM t1; |
| 48 | +count(*) |
| 49 | +512 |
| 50 | +Warnings: |
| 51 | +Warning 1064 Optimizer hint syntax error near '-1) */ count(*) FROM t1' at line 1 |
| 52 | +SELECT /*+ MAX_EXECUTION_TIME(4294967296) */ count(*) FROM t1; |
| 53 | +count(*) |
| 54 | +512 |
| 55 | +Warnings: |
| 56 | +Warning 1912 Incorrect value '4294967296' for option 'MAX_EXECUTION_TIME' |
| 57 | +# Conflicting max_statement_time and hint (must issue a warning) |
| 58 | +SET STATEMENT max_statement_time=1 FOR |
| 59 | +SELECT /*+ MAX_EXECUTION_TIME(500) */ count(*) FROM t1 a; |
| 60 | +count(*) |
| 61 | +512 |
| 62 | +Warnings: |
| 63 | +Warning 4202 Hint MAX_EXECUTION_TIME(500) is ignored as conflicting/duplicated |
| 64 | + |
| 65 | +# only SELECT statements supports the MAX_EXECUTION_TIME hint (warning): |
| 66 | + |
| 67 | +CREATE TABLE t2 (i INT); |
| 68 | +INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1; |
| 69 | +Warnings: |
| 70 | +Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context |
| 71 | +REPLACE /*+ MAX_EXECUTION_TIME(15) */ INTO t2 SELECT 1; |
| 72 | +Warnings: |
| 73 | +Warning 4172 'MAX_EXECUTION_TIME(15)' is not allowed in this context |
| 74 | +UPDATE /*+ MAX_EXECUTION_TIME(23) */ t2 SET i = 1; |
| 75 | +Warnings: |
| 76 | +Warning 4172 'MAX_EXECUTION_TIME(23)' is not allowed in this context |
| 77 | +DELETE /*+ MAX_EXECUTION_TIME(5000) */ FROM t2 WHERE i = 1; |
| 78 | +Warnings: |
| 79 | +Warning 4172 'MAX_EXECUTION_TIME(5000)' is not allowed in this context |
| 80 | +# Not supported inside stored procedures/functions |
| 81 | +CREATE PROCEDURE p1() BEGIN SELECT /*+ MAX_EXECUTION_TIME(10) */ count(*) FROM t1 a, t1 b |
| 82 | +INTO @a; END| |
| 83 | +CALL p1(); |
| 84 | +Warnings: |
| 85 | +Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context |
| 86 | +DROP PROCEDURE p1; |
| 87 | +# Hint in a subquery is not allowed (warning): |
| 88 | +SELECT 1 FROM (SELECT /*+ MAX_EXECUTION_TIME(10) */ 1) a; |
| 89 | +1 |
| 90 | +1 |
| 91 | +Warnings: |
| 92 | +Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context |
| 93 | +# Hint is allowed only for the first select of UNION (warning): |
| 94 | +SELECT /*+ MAX_EXECUTION_TIME(20) */ count(*) FROM t1 |
| 95 | +UNION |
| 96 | +SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1; |
| 97 | +count(*) |
| 98 | +512 |
| 99 | +Warnings: |
| 100 | +Warning 4202 Hint MAX_EXECUTION_TIME(30) is ignored as conflicting/duplicated |
| 101 | +SELECT count(*) FROM t1 |
| 102 | +UNION |
| 103 | +SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1; |
| 104 | +count(*) |
| 105 | +512 |
| 106 | +Warnings: |
| 107 | +Warning 4172 'MAX_EXECUTION_TIME(30)' is not allowed in this context |
| 108 | +# Check that hint actually works: |
| 109 | +SELECT /*+ MAX_EXECUTION_TIME(20) */ count(*), SLEEP(1) FROM t1 |
| 110 | +UNION |
| 111 | +SELECT count(*), SLEEP(1) FROM t1; |
| 112 | +ERROR 70100: Query execution was interrupted (max_statement_time exceeded) |
| 113 | +DROP TABLE t1, t2; |
0 commit comments