Skip to content

Commit 314cfc4

Browse files
author
Andrey Kazarinov
committed
cancel aqo timeout action in the critical section
1 parent e0f0d38 commit 314cfc4

File tree

3 files changed

+383
-1
lines changed

3 files changed

+383
-1
lines changed

expected/statement_timeout.out

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,177 @@ SELECT true AS success FROM aqo_reset();
156156
(1 row)
157157

158158
DROP EXTENSION aqo;
159+
CREATE EXTENSION IF NOT EXISTS aqo;
160+
SET client_min_messages TO WARNING;
161+
CREATE TABLE aqo_test1(a int, b int);
162+
WITH RECURSIVE t(a, b)
163+
AS (
164+
VALUES (1, 2)
165+
UNION ALL
166+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
167+
) INSERT INTO aqo_test1 (SELECT * FROM t);
168+
SET aqo.join_threshold = 0;
169+
SET aqo.mode = 'learn';
170+
SET aqo.show_details = 'off';
171+
SET aqo.learn_statement_timeout = 'on';
172+
SET statement_timeout = 15;
173+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
174+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
175+
WHERE t1.a = t2.b AND t2.a = t3.b;
176+
DROP TABLE IF EXISTS tmp1;
177+
CREATE EXTENSION IF NOT EXISTS aqo;
178+
WITH RECURSIVE t(a, b)
179+
AS (
180+
VALUES (1, 2)
181+
UNION ALL
182+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
183+
) INSERT INTO aqo_test1 (SELECT * FROM t);
184+
SET aqo.join_threshold = 0;
185+
SET aqo.mode = 'learn';
186+
SET aqo.show_details = 'off';
187+
SET aqo.learn_statement_timeout = 'on';
188+
SET statement_timeout = 15;
189+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
190+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
191+
WHERE t1.a = t2.b AND t2.a = t3.b;
192+
DROP TABLE IF EXISTS tmp1;
193+
CREATE EXTENSION IF NOT EXISTS aqo;
194+
WITH RECURSIVE t(a, b)
195+
AS (
196+
VALUES (1, 2)
197+
UNION ALL
198+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
199+
) INSERT INTO aqo_test1 (SELECT * FROM t);
200+
SET aqo.join_threshold = 0;
201+
SET aqo.mode = 'learn';
202+
SET aqo.show_details = 'off';
203+
SET aqo.learn_statement_timeout = 'on';
204+
SET statement_timeout = 15;
205+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
206+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
207+
WHERE t1.a = t2.b AND t2.a = t3.b;
208+
DROP TABLE IF EXISTS tmp1;
209+
CREATE EXTENSION IF NOT EXISTS aqo;
210+
WITH RECURSIVE t(a, b)
211+
AS (
212+
VALUES (1, 2)
213+
UNION ALL
214+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
215+
) INSERT INTO aqo_test1 (SELECT * FROM t);
216+
SET aqo.join_threshold = 0;
217+
SET aqo.mode = 'learn';
218+
SET aqo.show_details = 'off';
219+
SET aqo.learn_statement_timeout = 'on';
220+
SET statement_timeout = 15;
221+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
222+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
223+
WHERE t1.a = t2.b AND t2.a = t3.b;
224+
DROP TABLE IF EXISTS tmp1;
225+
CREATE EXTENSION IF NOT EXISTS aqo;
226+
WITH RECURSIVE t(a, b)
227+
AS (
228+
VALUES (1, 2)
229+
UNION ALL
230+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
231+
) INSERT INTO aqo_test1 (SELECT * FROM t);
232+
SET aqo.join_threshold = 0;
233+
SET aqo.mode = 'learn';
234+
SET aqo.show_details = 'off';
235+
SET aqo.learn_statement_timeout = 'on';
236+
SET statement_timeout = 15;
237+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
238+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
239+
WHERE t1.a = t2.b AND t2.a = t3.b;
240+
DROP TABLE tmp1;
241+
CREATE EXTENSION IF NOT EXISTS aqo;
242+
WITH RECURSIVE t(a, b)
243+
AS (
244+
VALUES (1, 2)
245+
UNION ALL
246+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
247+
) INSERT INTO aqo_test1 (SELECT * FROM t);
248+
SET aqo.join_threshold = 0;
249+
SET aqo.mode = 'learn';
250+
SET aqo.show_details = 'off';
251+
SET aqo.learn_statement_timeout = 'on';
252+
SET statement_timeout = 15;
253+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
254+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
255+
WHERE t1.a = t2.b AND t2.a = t3.b;
256+
ERROR: canceling statement due to statement timeout
257+
DROP TABLE IF EXISTS tmp1;
258+
CREATE EXTENSION IF NOT EXISTS aqo;
259+
WITH RECURSIVE t(a, b)
260+
AS (
261+
VALUES (1, 2)
262+
UNION ALL
263+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
264+
) INSERT INTO aqo_test1 (SELECT * FROM t);
265+
SET aqo.join_threshold = 0;
266+
SET aqo.mode = 'learn';
267+
SET aqo.show_details = 'off';
268+
SET aqo.learn_statement_timeout = 'on';
269+
SET statement_timeout = 15;
270+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
271+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
272+
WHERE t1.a = t2.b AND t2.a = t3.b;
273+
ERROR: canceling statement due to statement timeout
274+
DROP TABLE IF EXISTS tmp1;
275+
CREATE EXTENSION IF NOT EXISTS aqo;
276+
WITH RECURSIVE t(a, b)
277+
AS (
278+
VALUES (1, 2)
279+
UNION ALL
280+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
281+
) INSERT INTO aqo_test1 (SELECT * FROM t);
282+
SET aqo.join_threshold = 0;
283+
SET aqo.mode = 'learn';
284+
SET aqo.show_details = 'off';
285+
SET aqo.learn_statement_timeout = 'on';
286+
SET statement_timeout = 15;
287+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
288+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
289+
WHERE t1.a = t2.b AND t2.a = t3.b;
290+
ERROR: canceling statement due to statement timeout
291+
DROP TABLE IF EXISTS tmp1;
292+
CREATE EXTENSION IF NOT EXISTS aqo;
293+
WITH RECURSIVE t(a, b)
294+
AS (
295+
VALUES (1, 2)
296+
UNION ALL
297+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
298+
) INSERT INTO aqo_test1 (SELECT * FROM t);
299+
SET aqo.join_threshold = 0;
300+
SET aqo.mode = 'learn';
301+
SET aqo.show_details = 'off';
302+
SET aqo.learn_statement_timeout = 'on';
303+
SET statement_timeout = 15;
304+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
305+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
306+
WHERE t1.a = t2.b AND t2.a = t3.b;
307+
ERROR: canceling statement due to statement timeout
308+
DROP TABLE IF EXISTS tmp1;
309+
CREATE EXTENSION IF NOT EXISTS aqo;
310+
WITH RECURSIVE t(a, b)
311+
AS (
312+
VALUES (1, 2)
313+
UNION ALL
314+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 20
315+
) INSERT INTO aqo_test1 (SELECT * FROM t);
316+
SET aqo.join_threshold = 0;
317+
SET aqo.mode = 'learn';
318+
SET aqo.show_details = 'off';
319+
SET aqo.learn_statement_timeout = 'on';
320+
SET statement_timeout = 15;
321+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
322+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
323+
WHERE t1.a = t2.b AND t2.a = t3.b;
324+
ERROR: canceling statement due to statement timeout
325+
DROP TABLE IF EXISTS tmp1;
326+
SELECT true AS success FROM aqo_reset();
327+
success
328+
---------
329+
t
330+
(1 row)
331+
332+
DROP EXTENSION aqo;

postprocessing.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "optimizer/optimizer.h"
2323
#include "postgres_fdw.h"
2424
#include "utils/queryenvironment.h"
25+
#include "miscadmin.h"
2526

2627
#include "aqo.h"
2728
#include "hash.h"
@@ -622,7 +623,7 @@ aqo_timeout_handler(void)
622623
MemoryContext oldctx = MemoryContextSwitchTo(AQOLearnMemCtx);
623624
aqo_obj_stat ctx = {NIL, NIL, NIL, false, false};
624625

625-
if (!timeoutCtl.queryDesc || !ExtractFromQueryEnv(timeoutCtl.queryDesc))
626+
if (!timeoutCtl.queryDesc || !ExtractFromQueryEnv(timeoutCtl.queryDesc) || CritSectionCount > 0)
626627
return;
627628

628629
/* Now we can analyze execution state of the query. */

0 commit comments

Comments
 (0)