1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
#
# 1. Test MAX_EXECUTION_TIME option syntax.
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10);
SET @var= (SELECT /*+ MAX_EXECUTION_TIME(0) */ 1);
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT 1 FROM t1 WHERE a IN (SELECT /*+ MAX_EXECUTION_TIME(0) */ 1);
1
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT (SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
(SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1)
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT a FROM t1 WHERE a IN (SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT * FROM t1 WHERE a IN (SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1
WHERE a IN (SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT * FROM t1
WHERE a IN (SELECT a FROM t1 UNION SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1
WHERE a IN (SELECT a FROM t1 UNION SELECT /*+ MAX_EXECUTION_TIME(0) */ a FROM t1);
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT * FROM t1 UNION SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1;
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1
UNION SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1;
a
10
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
INSERT INTO t1 SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1;
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
CREATE TABLE t2 AS SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1;
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
CREATE TABLE t3 AS SELECT 1 A UNION SELECT 2 UNION SELECT /*+ MAX_EXECUTION_TIME(0) */ 3;
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
CREATE TABLE /*+ MAX_EXECUTION_TIME(100) */ t4 (a int);
CREATE /*+ MAX_EXECUTION_TIME(100) */ TABLE t5 (a int);
DELETE /*+ MAX_EXECUTION_TIME(100) */ FROM t1;
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
UPDATE /*+ MAX_EXECUTION_TIME(100) */ t1 SET a=20;
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
ALTER TABLE /*+ MAX_EXECUTION_TIME(100) */ t1 ADD b VARCHAR(200);
ALTER /*+ MAX_EXECUTION_TIME(100) */ TABLE t1 ADD c VARCHAR(200);
SELECT /*+ MAX_EXECUTION_TIME(0) */ * FROM t1;
a b c
DROP TABLE t1, t2, t3, t4, t5;
#
# 2. Test MAX_EXECUTION_TIME value set at session level.
#
SELECT @@max_execution_time;
@@max_execution_time
0
SET @@SESSION.max_execution_time= 1000;
SELECT @@max_execution_time;
@@max_execution_time
1000
SET @@SESSION.max_execution_time= 0;
#
# 3. Test the MAX_EXECUTION_TIME option by setting value for it at,
# - STATEMENT
# - SESSION
#
SELECT /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(5);
SLEEP(5)
1
SET @@SESSION.max_execution_time= 1000;
SELECT SLEEP(5);
SLEEP(5)
1
SET @@SESSION.max_execution_time= 0;
#
# 4. Test statement timeout functionality.
#
CREATE TABLE t1 (a INT, b VARCHAR(300));
INSERT INTO t1 VALUES (1, 'string');
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
SET @@SESSION.max_execution_time= 2;
SELECT *, SLEEP(0.5) from t1;
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
LOCK TABLE t1 WRITE;
SELECT * FROM t1;
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
SELECT /*+ MAX_EXECUTION_TIME(1) */ * FROM t1;
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
UNLOCK TABLES;
CREATE TABLE t2 SELECT * FROM t1;
ALTER TABLE t2 ADD c VARCHAR(200) default 'new_col';
UPDATE t1 SET b= 'new_string';
INSERT INTO t1 SELECT * FROM t1;
DELETE FROM t2;
#
# 5. Test SELECT with subquery.
#
SELECT /*+ MAX_EXECUTION_TIME(3600000) */ (SELECT SLEEP(0.5)) AS true_if_subquery_is_timedout;
true_if_subquery_is_timedout
0
#
# 6. Test max_execution_time with prepared statements.
#
PREPARE stmt1 FROM "SELECT *, SLEEP(0.5) FROM t1 WHERE b= 'new_string'";
PREPARE stmt2 FROM "SELECT /*+ MAX_EXECUTION_TIME(2) */ *, SLEEP(0.5) FROM t1 WHERE b= 'new_string'";
PREPARE stmt3 FROM "SELECT /*+ MAX_EXECUTION_TIME(3600000) */ count(*) FROM t1";
EXECUTE stmt1;
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
EXECUTE stmt2;
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
EXECUTE stmt3;
count(*)
4096
DEALLOCATE PREPARE stmt1;
DEALLOCATE PREPARE stmt2;
DEALLOCATE PREPARE stmt3;
#
# 7. Test max_execution_time with Stored Routines.
#
CREATE FUNCTION f1() RETURNS INT
BEGIN
SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(1.5) INTO @a;
RETURN 1;
END|
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
DROP FUNCTION f1|
CREATE FUNCTION f1() RETURNS INT
BEGIN
SELECT SLEEP(3) INTO @a;
RETURN 1;
END|
CREATE FUNCTION f2() RETURNS INT
BEGIN
INSERT INTO t2 SELECT * FROM t2;
RETURN 1;
END|
INSERT INTO t2 VALUES (1, 'string1', 'string2');
SET @@SESSION.max_execution_time= 2;
SELECT f1();
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
SELECT /*+ MAX_EXECUTION_TIME(60000) */ f2();
f2()
1
Warnings:
Note 3025 Select is not a read only statement, disabling timer
DROP FUNCTION f1;
DROP FUNCTION f2;
CREATE PROCEDURE p1()
BEGIN
SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(1.5);
INSERT INTO t2 SELECT DISTINCT * FROM t2;
END|
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
DROP PROCEDURE p1|
CREATE PROCEDURE p1()
BEGIN
INSERT INTO t2 SELECT DISTINCT * FROM t2;
SELECT SLEEP(3);
END|
CALL p1();
SLEEP(3)
0
DROP PROCEDURE p1;
DROP TABLE t2;
SET @global_event_scheduler_status= @@global.event_scheduler;
SET @@global.event_scheduler= ON;
SET @@global.max_execution_time= 1000;
CREATE TABLE t2 (f1 int, f2 int);
SELECT SLEEP(5) into @a;
SELECT @a;
@a
1
CREATE EVENT event1 ON SCHEDULE AT CURRENT_TIMESTAMP
DO BEGIN
SELECT SLEEP(2) into @a;
SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(2) into @b;
INSERT INTO t2 VALUES(@a, @b);
END|
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
# Wait until at least one instance of event is executed.
SELECT /*+ MAX_EXECUTION_TIME(3600000) */ * FROM t2;
f1 f2
0 0
DELETE FROM t2;
SET @@global.event_scheduler= @global_event_scheduler_status;
SET @@global.max_execution_time= 0;
CREATE TABLE t3 (f1 int)|
CREATE TRIGGER t1_before_trigger BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
SELECT SLEEP(2) into @a;
SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(2) into @b;
INSERT INTO t3 VALUES(@a);
INSERT INTO t3 VALUES(@b);
END|
Warnings:
Warning 3125 MAX_EXECUTION_TIME hint is supported by top-level standalone SELECT statements only
DROP TRIGGER t1_before_trigger|
CREATE TRIGGER t1_before_trigger BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
SELECT SLEEP(2) into @a;
INSERT INTO t3 VALUES(@a);
END
|
SELECT SLEEP(5) into @a;
SELECT /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(2) into @b;
SELECT @a, @b;
@a @b
1 1
INSERT INTO t1 VALUES (1, 'string');
SELECT /*+ MAX_EXECUTION_TIME(3600000) */ * FROM t3;
f1
0
DROP TABLE t1,t2,t3;
#
# 8. Test MAX_EXECUTION_TIME precedence set at different levels.
#
SET @@SESSION.max_execution_time= 1000;
SELECT sleep(5);
sleep(5)
1
SELECT /*+ MAX_EXECUTION_TIME(20000) */ sleep(5);
sleep(5)
0
SET @@SESSION.max_execution_time= 0;
#
# 9. MAX_EXECUTION_TIME status variables.
#
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_set
FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET';
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_exceeded
FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_EXCEEDED';
SELECT /*+ MAX_EXECUTION_TIME(10) */ SLEEP(1);
SLEEP(1)
1
# Ensure that the counters for:
# - statements that are time limited; and
# - statements that exceeded their maximum execution time
# are incremented.
SELECT 1 AS STATUS FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET'
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_set;
STATUS
1
SELECT 1 AS STATUS FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_EXCEEDED'
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_exceeded;
STATUS
1
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_set_failed
FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET_FAILED';
SET DEBUG= '+d,thd_timer_create_failure';
SELECT /*+ MAX_EXECUTION_TIME(10) */ SLEEP(1);
SLEEP(1)
0
SET DEBUG= '-d,thd_timer_create_failure';
SELECT 1 AS STATUS FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET_FAILED'
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_set_failed;
STATUS
1
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_set_failed
FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET_FAILED';
SET DEBUG= '+d,thd_timer_set_failure';
SELECT /*+ MAX_EXECUTION_TIME(10) */ SLEEP(1);
SLEEP(1)
0
SET DEBUG= '-d,thd_timer_set_failure';
SELECT 1 AS STATUS FROM performance_schema.global_status
WHERE VARIABLE_NAME= 'MAX_EXECUTION_TIME_SET_FAILED'
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_set_failed;
STATUS
1
SET @@SESSION.max_execution_time= 0;
|