Skip to content

Commit 667c5e0

Browse files
Olernovmariadb-OlegSmirnov
authored andcommitted
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.
1 parent 5999a8d commit 667c5e0

File tree

2 files changed

+40
-58
lines changed

2 files changed

+40
-58
lines changed

mysql-test/main/opt_hint_timeout.result

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
#
22
# MAX_EXECUTION_TIME hint testing
33
#
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;
4+
CREATE TABLE t1 (a INT);
5+
INSERT INTO t1 SELECT seq FROM seq_1_to_5000;
156
# Correct hint usage
167
SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b;
178
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
18-
EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(000149) */* FROM t1;
9+
EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(0001490) */* FROM t1;
1910
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
11+
1 SIMPLE t1 ALL NULL NULL NULL NULL 5000 100.00
2112
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;
13+
Note 1003 select /*+ MAX_EXECUTION_TIME(0001490) */ `test`.`t1`.`a` AS `a` from `test`.`t1`
14+
SELECT /*+ MAX_EXECUTION_TIME(20) */ *, SLEEP(1) FROM t1 UNION SELECT 1, 2;
2415
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);
16+
(SELECT /*+ MAX_EXECUTION_TIME(300) */ *, SLEEP(1) FROM t1) UNION (SELECT 1, 2);
2617
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
27-
((SELECT /*+ MAX_EXECUTION_TIME(50) */ *, SLEEP(1) FROM t1));
18+
((SELECT /*+ MAX_EXECUTION_TIME(500) */ *, SLEEP(1) FROM t1));
2819
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
2920
# Make sure the hint overrides global/session/statement settings.
3021
# Global setting 30 seconds, won't be exceeded for sure
3122
SET @@max_statement_time = 30;
32-
SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b;
23+
SELECT /*+ MAX_EXECUTION_TIME(10)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
3324
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
34-
# Session setting 10 seconds, too long to be exceeded
35-
SET SESSION max_statement_time = 10;
36-
SELECT /*+ MAX_EXECUTION_TIME(15) */* FROM t1 a, t1 b;
25+
# Session setting 30 seconds, too long to be exceeded
26+
SET SESSION max_statement_time = 30;
27+
SELECT /*+ MAX_EXECUTION_TIME(15) */ count(*) FROM t1 a natural join t1 b natural join t1 c;
3728
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
3829
SET STATEMENT max_statement_time = 20 FOR
39-
SELECT /*+ MAX_EXECUTION_TIME(5) */* FROM t1 a, t1 b;
30+
SELECT /*+ MAX_EXECUTION_TIME(5)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
4031
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
4132
# Check that prepared statements process the hint correctly
4233
PREPARE s FROM 'SELECT /*+ MAX_EXECUTION_TIME(20) */ seq, SLEEP(1) FROM seq_1_to_10';
@@ -45,29 +36,29 @@ ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
4536
EXECUTE s;
4637
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
4738
# Hint duplication
48-
SELECT /*+ MAX_EXECUTION_TIME(10) MAX_EXECUTION_TIME(100) */ count(*) FROM t1;
39+
SELECT /*+ MAX_EXECUTION_TIME(50000) MAX_EXECUTION_TIME(100) */ count(*) FROM t1;
4940
count(*)
50-
512
41+
5000
5142
Warnings:
5243
Warning 4219 Hint MAX_EXECUTION_TIME(100) is ignored as conflicting/duplicated
5344
# Wrong values
5445
SELECT /*+ MAX_EXECUTION_TIME(0) */ count(*) FROM t1;
5546
count(*)
56-
512
47+
5000
5748
Warnings:
5849
Warning 1912 Incorrect value '0' for option 'MAX_EXECUTION_TIME'
5950
SELECT /*+ MAX_EXECUTION_TIME(-1) */ count(*) FROM t1;
6051
count(*)
61-
512
52+
5000
6253
Warnings:
6354
Warning 1064 Optimizer hint syntax error near '-1) */ count(*) FROM t1' at line 1
6455
SELECT /*+ MAX_EXECUTION_TIME(4294967296) */ count(*) FROM t1;
6556
count(*)
66-
512
57+
5000
6758
Warnings:
6859
Warning 1912 Incorrect value '4294967296' for option 'MAX_EXECUTION_TIME'
6960

70-
# only SELECT statements supports the MAX_EXECUTION_TIME hint (warning):
61+
# only SELECT statements support the MAX_EXECUTION_TIME hint (warning):
7162

7263
CREATE TABLE t2 (i INT);
7364
INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1;
@@ -102,18 +93,18 @@ SELECT 1 FROM (SELECT /*+ MAX_EXECUTION_TIME(10) */ 1) a;
10293
Warnings:
10394
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
10495
# Hint is allowed only for the first select of UNION (warning):
105-
SELECT /*+ MAX_EXECUTION_TIME(20) */ count(*) FROM t1
96+
SELECT /*+ MAX_EXECUTION_TIME(50000) */ count(*) FROM t1
10697
UNION
107-
SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1;
98+
SELECT /*+ MAX_EXECUTION_TIME(3) */ count(*) FROM t1;
10899
count(*)
109-
512
100+
5000
110101
Warnings:
111-
Warning 4219 Hint MAX_EXECUTION_TIME(30) is ignored as conflicting/duplicated
102+
Warning 4219 Hint MAX_EXECUTION_TIME(3) is ignored as conflicting/duplicated
112103
SELECT count(*) FROM t1
113104
UNION
114105
SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1;
115106
count(*)
116-
512
107+
5000
117108
Warnings:
118109
Warning 4172 'MAX_EXECUTION_TIME(30)' is not allowed in this context
119110
# Check that hint actually works:

mysql-test/main/opt_hint_timeout.test

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,9 @@
1111
--echo #
1212
--enable_prepare_warnings
1313

14-
CREATE TABLE t1 (a INT, b VARCHAR(300));
15-
INSERT INTO t1 VALUES (1, 'string');
16-
INSERT INTO t1 SELECT * FROM t1;
17-
INSERT INTO t1 SELECT * FROM t1;
18-
INSERT INTO t1 SELECT * FROM t1;
19-
INSERT INTO t1 SELECT * FROM t1;
20-
INSERT INTO t1 SELECT * FROM t1;
21-
INSERT INTO t1 SELECT * FROM t1;
22-
INSERT INTO t1 SELECT * FROM t1;
23-
INSERT INTO t1 SELECT * FROM t1;
24-
INSERT INTO t1 SELECT * FROM t1;
14+
CREATE TABLE t1 (a INT);
15+
16+
INSERT INTO t1 SELECT seq FROM seq_1_to_5000;
2517

2618
-- disable_query_log
2719
-- disable_result_log
@@ -33,29 +25,29 @@ analyze table t1;
3325
--error ER_STATEMENT_TIMEOUT
3426
SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b;
3527

36-
EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(000149) */* FROM t1;
28+
EXPLAIN EXTENDED SELECT /*+ MAX_EXECUTION_TIME(0001490) */* FROM t1;
3729

3830
--error ER_STATEMENT_TIMEOUT
39-
SELECT /*+ MAX_EXECUTION_TIME(20) */ *, SLEEP(1) FROM t1 UNION SELECT 1, 2, 3;
31+
SELECT /*+ MAX_EXECUTION_TIME(20) */ *, SLEEP(1) FROM t1 UNION SELECT 1, 2;
4032
--error ER_STATEMENT_TIMEOUT
41-
(SELECT /*+ MAX_EXECUTION_TIME(30) */ *, SLEEP(1) FROM t1) UNION (SELECT 1, 2, 3);
33+
(SELECT /*+ MAX_EXECUTION_TIME(300) */ *, SLEEP(1) FROM t1) UNION (SELECT 1, 2);
4234
--error ER_STATEMENT_TIMEOUT
43-
((SELECT /*+ MAX_EXECUTION_TIME(50) */ *, SLEEP(1) FROM t1));
35+
((SELECT /*+ MAX_EXECUTION_TIME(500) */ *, SLEEP(1) FROM t1));
4436

4537
--echo # Make sure the hint overrides global/session/statement settings.
4638
--echo # Global setting 30 seconds, won't be exceeded for sure
4739
SET @@max_statement_time = 30;
4840
--error ER_STATEMENT_TIMEOUT
49-
SELECT /*+ MAX_EXECUTION_TIME(10) */* FROM t1 a, t1 b;
41+
SELECT /*+ MAX_EXECUTION_TIME(10)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
5042

51-
--echo # Session setting 10 seconds, too long to be exceeded
52-
SET SESSION max_statement_time = 10;
43+
--echo # Session setting 30 seconds, too long to be exceeded
44+
SET SESSION max_statement_time = 30;
5345
--error ER_STATEMENT_TIMEOUT
54-
SELECT /*+ MAX_EXECUTION_TIME(15) */* FROM t1 a, t1 b;
46+
SELECT /*+ MAX_EXECUTION_TIME(15) */ count(*) FROM t1 a natural join t1 b natural join t1 c;
5547

5648
--error ER_STATEMENT_TIMEOUT
5749
SET STATEMENT max_statement_time = 20 FOR
58-
SELECT /*+ MAX_EXECUTION_TIME(5) */* FROM t1 a, t1 b;
50+
SELECT /*+ MAX_EXECUTION_TIME(5)*/ count(*) FROM t1 a natural join t1 b natural join t1 c;
5951

6052
--echo # Check that prepared statements process the hint correctly
6153
PREPARE s FROM 'SELECT /*+ MAX_EXECUTION_TIME(20) */ seq, SLEEP(1) FROM seq_1_to_10';
@@ -65,16 +57,15 @@ EXECUTE s;
6557
EXECUTE s;
6658

6759
--echo # Hint duplication
68-
69-
SELECT /*+ MAX_EXECUTION_TIME(10) MAX_EXECUTION_TIME(100) */ count(*) FROM t1;
60+
SELECT /*+ MAX_EXECUTION_TIME(50000) MAX_EXECUTION_TIME(100) */ count(*) FROM t1;
7061

7162
--echo # Wrong values
7263
SELECT /*+ MAX_EXECUTION_TIME(0) */ count(*) FROM t1;
7364
SELECT /*+ MAX_EXECUTION_TIME(-1) */ count(*) FROM t1;
7465
SELECT /*+ MAX_EXECUTION_TIME(4294967296) */ count(*) FROM t1;
7566

7667
--echo
77-
--echo # only SELECT statements supports the MAX_EXECUTION_TIME hint (warning):
68+
--echo # only SELECT statements support the MAX_EXECUTION_TIME hint (warning):
7869
--echo
7970
CREATE TABLE t2 (i INT);
8071
INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1;
@@ -97,9 +88,9 @@ DROP PROCEDURE p1;
9788
SELECT 1 FROM (SELECT /*+ MAX_EXECUTION_TIME(10) */ 1) a;
9889

9990
--echo # Hint is allowed only for the first select of UNION (warning):
100-
SELECT /*+ MAX_EXECUTION_TIME(20) */ count(*) FROM t1
91+
SELECT /*+ MAX_EXECUTION_TIME(50000) */ count(*) FROM t1
10192
UNION
102-
SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1;
93+
SELECT /*+ MAX_EXECUTION_TIME(3) */ count(*) FROM t1;
10394

10495
SELECT count(*) FROM t1
10596
UNION

0 commit comments

Comments
 (0)