Skip to content

Commit b63952a

Browse files
vacuumdb: Fix --missing-stats-only with virtual generated columns.
Statistics aren't created for virtual generated columns, so "vacuumdb --missing-stats-only" always chooses to analyze tables that have them. To fix, modify vacuumdb's query for retrieving relations that are missing statistics to exclude those columns. Oversight in commit edba754. Author: Yugo Nagata <nagata@sraoss.co.jp> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Corey Huinker <corey.huinker@gmail.com> Discussion: https://postgr.es/m/20250820104226.8ba51e43164cd590b863ce41%40sraoss.co.jp Backpatch-through: 18
1 parent 807ee41 commit b63952a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/bin/scripts/t/100_vacuumdb.pl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@
237237
qr/cannot vacuum all databases and a specific one at the same time/,
238238
'cannot use option --all and a dbname as argument at the same time');
239239

240-
$node->safe_psql('postgres',
241-
'CREATE TABLE regression_vacuumdb_test AS select generate_series(1, 10) a, generate_series(2, 11) b;'
242-
);
240+
$node->safe_psql('postgres', q|
241+
CREATE TABLE regression_vacuumdb_test AS select generate_series(1, 10) a, generate_series(2, 11) b;
242+
ALTER TABLE regression_vacuumdb_test ADD COLUMN c INT GENERATED ALWAYS AS (a + b);
243+
|);
243244
$node->issues_sql_like(
244245
[
245246
'vacuumdb', '--analyze-only',

src/bin/scripts/vacuumdb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <limits.h>
1616

17+
#include "catalog/pg_attribute_d.h"
1718
#include "catalog/pg_class_d.h"
1819
#include "common.h"
1920
#include "common/connect.h"
@@ -973,6 +974,8 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
973974
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
974975
" AND NOT a.attisdropped\n"
975976
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
977+
" AND a.attgenerated OPERATOR(pg_catalog.<>) "
978+
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n"
976979
" AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n"
977980
" WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n"
978981
" AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n"
@@ -1010,6 +1013,8 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
10101013
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
10111014
" AND NOT a.attisdropped\n"
10121015
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
1016+
" AND a.attgenerated OPERATOR(pg_catalog.<>) "
1017+
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n"
10131018
" AND c.relhassubclass\n"
10141019
" AND NOT p.inherited\n"
10151020
" AND EXISTS (SELECT NULL FROM pg_catalog.pg_inherits h\n"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy