Skip to content

Commit

Permalink
Reset aqo mode to frozen in case of shmem overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Magomedov committed Apr 10, 2024
1 parent 70b78c2 commit bc900f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
7 changes: 4 additions & 3 deletions preprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ aqo_planner(Query *parse, const char *query_string, int cursorOptions,
disable_aqo_for_query();

/*
* Switch AQO to controlled mode. In this mode we wouldn't add new
* query classes, just use and learn on existed set.
* Switch AQO to frozen mode. In this mode we wouldn't collect
* any new data, just read collected statistics for already
* known query classes.
*/
aqo_mode = AQO_MODE_CONTROLLED;
aqo_mode = AQO_MODE_FROZEN;
}
}

Expand Down
47 changes: 47 additions & 0 deletions t/006_overflow.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use strict;
use warnings;

use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More tests => 4;

my $node = PostgreSQL::Test::Cluster->new('aqotest');
$node->init;
$node->append_conf('postgresql.conf', qq{
shared_preload_libraries = 'aqo'
aqo.join_threshold = 0
aqo.mode = 'frozen'
aqo.show_details = 'on'
aqo.dsm_size_max = 10
aqo.force_collect_stat = 'on'
aqo.fs_max_items = 3
aqo.fss_max_items = 10
});

# General purpose variables.
my $res;
my $mode;

# Disable default settings, forced by PGOPTIONS in AQO Makefile
$ENV{PGOPTIONS}="";

$node->start();
$node->safe_psql('postgres', 'CREATE EXTENSION aqo');

$mode = $node->safe_psql('postgres',"show aqo.mode");
like($mode, qr/frozen/);

$node->safe_psql('postgres', 'CREATE TABLE a (x int);
INSERT INTO a (x) SELECT mod(ival,10) FROM generate_series(1,1000) As ival');

$res = $node->safe_psql('postgres', 'EXPLAIN ANALYZE SELECT x FROM a WHERE x < 5;');
like($res, qr/AQO mode: FROZEN/);

$res = $node->safe_psql('postgres', 'EXPLAIN ANALYZE SELECT count(x) FROM a WHERE x > 5;');
like($res, qr/AQO mode: FROZEN/);

$mode = $node->safe_psql('postgres',"show aqo.mode");
like($mode, qr/frozen/);

$node->stop();
done_testing();

0 comments on commit bc900f7

Please sign in to comment.