mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
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 edba754f05
.
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
This commit is contained in:
@@ -237,9 +237,10 @@ $node->command_fails_like(
|
||||
qr/cannot vacuum all databases and a specific one at the same time/,
|
||||
'cannot use option --all and a dbname as argument at the same time');
|
||||
|
||||
$node->safe_psql('postgres',
|
||||
'CREATE TABLE regression_vacuumdb_test AS select generate_series(1, 10) a, generate_series(2, 11) b;'
|
||||
);
|
||||
$node->safe_psql('postgres', q|
|
||||
CREATE TABLE regression_vacuumdb_test AS select generate_series(1, 10) a, generate_series(2, 11) b;
|
||||
ALTER TABLE regression_vacuumdb_test ADD COLUMN c INT GENERATED ALWAYS AS (a + b);
|
||||
|);
|
||||
$node->issues_sql_like(
|
||||
[
|
||||
'vacuumdb', '--analyze-only',
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "catalog/pg_attribute_d.h"
|
||||
#include "catalog/pg_class_d.h"
|
||||
#include "common.h"
|
||||
#include "common/connect.h"
|
||||
@@ -973,6 +974,8 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
|
||||
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
|
||||
" AND NOT a.attisdropped\n"
|
||||
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
|
||||
" AND a.attgenerated OPERATOR(pg_catalog.<>) "
|
||||
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n"
|
||||
" AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n"
|
||||
" WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n"
|
||||
" AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n"
|
||||
@@ -1010,6 +1013,8 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
|
||||
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
|
||||
" AND NOT a.attisdropped\n"
|
||||
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
|
||||
" AND a.attgenerated OPERATOR(pg_catalog.<>) "
|
||||
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n"
|
||||
" AND c.relhassubclass\n"
|
||||
" AND NOT p.inherited\n"
|
||||
" AND EXISTS (SELECT NULL FROM pg_catalog.pg_inherits h\n"
|
||||
|
Reference in New Issue
Block a user