Skip to content

Commit 547f107

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

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

postprocessing.c

Lines changed: 5 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,8 +623,11 @@ 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 (CritSectionCount > 0 || !timeoutCtl.queryDesc || !ExtractFromQueryEnv(timeoutCtl.queryDesc))
627+
{
628+
MemoryContextSwitchTo(oldctx);
626629
return;
630+
}
627631

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

t/003_assertion_error.pl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use strict;
2+
use warnings;
3+
4+
use Config;
5+
use PostgreSQL::Test::Cluster;
6+
use PostgreSQL::Test::Utils;
7+
8+
use Test::More tests => 1;
9+
10+
my $node = PostgreSQL::Test::Cluster->new('aqotest');
11+
$node->init;
12+
$node->append_conf('postgresql.conf', qq{
13+
shared_preload_libraries = 'aqo'
14+
aqo.join_threshold = 0
15+
aqo.mode = 'learn'
16+
aqo.show_details = 'off'
17+
aqo.learn_statement_timeout = 'on'
18+
});
19+
20+
# Test constants. Default values.
21+
my $TRANSACTIONS = 100;
22+
23+
# Disable connection default settings, forced by PGOPTIONS in AQO Makefile
24+
# $ENV{PGOPTIONS}="";
25+
26+
# Change pgbench parameters according to the environment variable.
27+
if (defined $ENV{TRANSACTIONS})
28+
{
29+
$TRANSACTIONS = $ENV{TRANSACTIONS};
30+
}
31+
32+
my $query_string = '
33+
CREATE TABLE IF NOT EXISTS aqo_test1(a int, b int);
34+
WITH RECURSIVE t(a, b)
35+
AS (
36+
VALUES (1, 2)
37+
UNION ALL
38+
SELECT t.a + 1, t.b + 1 FROM t WHERE t.a < 10
39+
) INSERT INTO aqo_test1 (SELECT * FROM t);
40+
41+
SET statement_timeout = 10;
42+
43+
CREATE TABLE tmp1 AS SELECT t1.a AS a, t2.a AS b, t3.a AS c
44+
FROM aqo_test1 AS t1, aqo_test1 AS t2, aqo_test1 AS t3
45+
WHERE t1.a = t2.b AND t2.a = t3.b;
46+
DROP TABLE tmp1;
47+
';
48+
49+
$node->start();
50+
51+
$node->safe_psql('postgres', 'CREATE EXTENSION IF NOT EXISTS aqo;');
52+
53+
for (1..$TRANSACTIONS) {
54+
$node->psql('postgres', $query_string);
55+
}
56+
57+
ok(1, "There are no segfaults");
58+
59+
$node->stop();

0 commit comments

Comments
 (0)