Skip to content

Commit 45e1d58

Browse files
committed
Improvement of time-dependent test statement_timeout.
Remember, each query can be executed longer than the timeout on an ancient machines of buildfarm. So, RESET this GUC each time when it isn't really needed for a test query.
1 parent 398d200 commit 45e1d58

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

expected/statement_timeout.out

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SET statement_timeout = 80; -- [0.1s]
3535
SELECT *, pg_sleep(0.1) FROM t;
3636
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
3737
ERROR: canceling statement due to statement timeout
38+
RESET statement_timeout;
3839
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;'); -- haven't any partial data
3940
check_estimated_rows
4041
----------------------
@@ -46,6 +47,7 @@ SET statement_timeout = 350;
4647
SELECT *, pg_sleep(0.1) FROM t;
4748
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
4849
ERROR: canceling statement due to statement timeout
50+
RESET statement_timeout;
4951
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
5052
check_estimated_rows
5153
----------------------
@@ -64,6 +66,7 @@ SELECT *, pg_sleep(0.1) FROM t;
6466
5 |
6567
(5 rows)
6668

69+
RESET statement_timeout;
6770
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
6871
check_estimated_rows
6972
----------------------
@@ -84,6 +87,7 @@ SET statement_timeout = 80;
8487
SELECT *, pg_sleep(0.1) FROM t; -- Not learned
8588
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
8689
ERROR: canceling statement due to statement timeout
90+
RESET statement_timeout;
8791
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
8892
check_estimated_rows
8993
----------------------
@@ -94,6 +98,7 @@ SET statement_timeout = 350;
9498
SELECT *, pg_sleep(0.1) FROM t; -- Learn!
9599
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
96100
ERROR: canceling statement due to statement timeout
101+
RESET statement_timeout;
97102
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
98103
check_estimated_rows
99104
----------------------
@@ -111,6 +116,7 @@ SELECT *, pg_sleep(0.1) FROM t; -- Get reliable data
111116
5 |
112117
(5 rows)
113118

119+
RESET statement_timeout;
114120
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
115121
check_estimated_rows
116122
----------------------
@@ -134,18 +140,19 @@ SELECT count(*) FROM aqo_data; -- Must be zero
134140
SELECT x, pg_sleep(0.1) FROM t WHERE x > 0;
135141
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
136142
ERROR: canceling statement due to statement timeout
143+
RESET statement_timeout;
137144
SELECT count(*) FROM aqo_data; -- Must be one
138145
count
139146
-------
140147
1
141148
(1 row)
142149

150+
DROP TABLE t;
151+
DROP FUNCTION check_estimated_rows;
143152
SELECT true AS success FROM aqo_reset();
144153
success
145154
---------
146155
t
147156
(1 row)
148157

149-
DROP TABLE t;
150158
DROP EXTENSION aqo;
151-
DROP FUNCTION check_estimated_rows;

sql/statement_timeout.sql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ SET aqo.learn_statement_timeout = 'on';
3232

3333
SET statement_timeout = 80; -- [0.1s]
3434
SELECT *, pg_sleep(0.1) FROM t;
35+
36+
RESET statement_timeout;
3537
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;'); -- haven't any partial data
3638

3739
-- Don't learn because running node has smaller cardinality than an optimizer prediction
3840
SET statement_timeout = 350;
3941
SELECT *, pg_sleep(0.1) FROM t;
42+
43+
RESET statement_timeout;
4044
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
4145

4246
-- We have a real learning data.
4347
SET statement_timeout = 800;
4448
SELECT *, pg_sleep(0.1) FROM t;
49+
50+
RESET statement_timeout;
4551
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
4652

4753
-- Force to make an underestimated prediction
@@ -52,24 +58,33 @@ SELECT true AS success FROM aqo_reset();
5258

5359
SET statement_timeout = 80;
5460
SELECT *, pg_sleep(0.1) FROM t; -- Not learned
61+
62+
RESET statement_timeout;
5563
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
5664

5765
SET statement_timeout = 350;
5866
SELECT *, pg_sleep(0.1) FROM t; -- Learn!
67+
68+
RESET statement_timeout;
5969
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
6070

6171
SET statement_timeout = 550;
6272
SELECT *, pg_sleep(0.1) FROM t; -- Get reliable data
73+
74+
RESET statement_timeout;
6375
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
6476

6577
-- Interrupted query should immediately appear in aqo_data
6678
SELECT true AS success FROM aqo_reset();
6779
SET statement_timeout = 500;
6880
SELECT count(*) FROM aqo_data; -- Must be zero
6981
SELECT x, pg_sleep(0.1) FROM t WHERE x > 0;
82+
83+
RESET statement_timeout;
7084
SELECT count(*) FROM aqo_data; -- Must be one
7185

72-
SELECT true AS success FROM aqo_reset();
7386
DROP TABLE t;
74-
DROP EXTENSION aqo;
7587
DROP FUNCTION check_estimated_rows;
88+
89+
SELECT true AS success FROM aqo_reset();
90+
DROP EXTENSION aqo;

0 commit comments

Comments
 (0)