Skip to content

Commit 87ed6b9

Browse files
author
Timur Magomedov
committed
Reset aqo mode to frozen in case of shmem overflow
1 parent 1e2e081 commit 87ed6b9

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Diff for: preprocessing.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@ aqo_planner(Query *parse, const char *query_string, int cursorOptions,
316316
disable_aqo_for_query();
317317

318318
/*
319-
* Switch AQO to controlled mode. In this mode we wouldn't add new
320-
* query classes, just use and learn on existed set.
319+
* Switch AQO to frozen mode. In this mode we wouldn't collect
320+
* any new data, just read collected statistics for already
321+
* known query classes.
321322
*/
322-
aqo_mode = AQO_MODE_CONTROLLED;
323+
aqo_mode = AQO_MODE_FROZEN;
323324
}
324325
}
325326

Diff for: t/006_overflow.pl

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgreSQL::Test::Cluster;
5+
use PostgreSQL::Test::Utils;
6+
use Test::More tests => 4;
7+
8+
my $node = PostgreSQL::Test::Cluster->new('aqotest');
9+
$node->init;
10+
$node->append_conf('postgresql.conf', qq{
11+
shared_preload_libraries = 'aqo'
12+
aqo.join_threshold = 0
13+
aqo.mode = 'frozen'
14+
aqo.show_details = 'on'
15+
aqo.dsm_size_max = 10
16+
aqo.force_collect_stat = 'on'
17+
aqo.fs_max_items = 3
18+
aqo.fss_max_items = 10
19+
});
20+
21+
# General purpose variables.
22+
my $res;
23+
my $mode;
24+
25+
# Disable default settings, forced by PGOPTIONS in AQO Makefile
26+
$ENV{PGOPTIONS}="";
27+
28+
$node->start();
29+
$node->safe_psql('postgres', 'CREATE EXTENSION aqo');
30+
31+
$mode = $node->safe_psql('postgres',"show aqo.mode");
32+
like($mode, qr/frozen/);
33+
34+
$node->safe_psql('postgres', 'CREATE TABLE a (x int);
35+
INSERT INTO a (x) SELECT mod(ival,10) FROM generate_series(1,1000) As ival');
36+
37+
$res = $node->safe_psql('postgres', 'EXPLAIN ANALYZE SELECT x FROM a WHERE x < 5;');
38+
like($res, qr/AQO mode: FROZEN/);
39+
40+
$res = $node->safe_psql('postgres', 'EXPLAIN ANALYZE SELECT count(x) FROM a WHERE x > 5;');
41+
like($res, qr/AQO mode: FROZEN/);
42+
43+
$mode = $node->safe_psql('postgres',"show aqo.mode");
44+
like($mode, qr/frozen/);
45+
46+
$node->stop();
47+
done_testing();

0 commit comments

Comments
 (0)