Skip to content

Commit

Permalink
Fix svace warnings
Browse files Browse the repository at this point in the history
Fixed arithmetics in check_dsa_file_size to avoid server startup failure
when aqo.dsm_size_max in bytes overflows signed integer. Updated
corresponding tap-test.

Two unreachable paths were removed.

(cherry-picked from master with a minor change in tap-test)
  • Loading branch information
Artem Fadeev committed Aug 23, 2024
1 parent bc900f7 commit 8060672
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions cardinality_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ aqo_estimate_num_groups(PlannerInfo *root, List *groupExprs,
/* It is unclear that to do in situation of such kind. Just report it */
elog(WARNING, "AQO is in the middle of the estimate_num_groups_hook chain");

if (groupExprs == NIL)
return 1.0;

old_ctx_m = MemoryContextSwitchTo(AQOPredictMemCtx);

predicted = predict_num_groups(root, subpath, groupExprs, &fss);
Expand Down
4 changes: 1 addition & 3 deletions storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,6 @@ aqo_get_file_size(const char *filename)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", filename)));
if (file)
FreeFile(file);
unlink(filename);
return -1;
}
Expand All @@ -981,7 +979,7 @@ check_dsa_file_size(void)
long data_size = aqo_get_file_size(PGAQO_DATA_FILE);

if (qtext_size == -1 || data_size == -1 ||
qtext_size + data_size >= dsm_size_max * 1024 * 1024)
((unsigned long) qtext_size + (unsigned long) data_size) >> 20 >= dsm_size_max)
{
elog(ERROR, "aqo.dsm_size_max is too small");
}
Expand Down
8 changes: 7 additions & 1 deletion t/004_dsm_size_max.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;

use Test::More tests => 5;
use Test::More tests => 6;

my $node = PostgreSQL::Test::Cluster->new('aqotest');
$node->init;
Expand Down Expand Up @@ -58,6 +58,12 @@
$node->psql('postgres', 'select * from aqo_reset();');
$node->stop();

# 3000mb (more than 2*31 bytes) overflows 4-byte signed int
$node->append_conf('postgresql.conf', 'aqo.dsm_size_max = 3000');
is($node->start(fail_ok => 1), 1, "Large aqo.dsm_size_max doesn't cause integer overflow");
$node->stop();


my $regex;
$long_string = 'a' x 100000;
$regex = qr/.*WARNING: \[AQO\] Not enough DSA\. AQO was disabled for this query/;
Expand Down

0 comments on commit 8060672

Please sign in to comment.