From 3741ca47cf1fc3d3bef1a383d3ae565db519bdb9 Mon Sep 17 00:00:00 2001 From: Zsolt Parragi Date: Mon, 20 Jul 2026 21:32:08 +0000 Subject: [PATCH] Reject the ANALYZE option in CLUSTER ExecRepack only restricted the CONCURRENTLY option by command, so CLUSTER (ANALYZE) was silently accepted and ran an analyze after clustering, although cluster.sgml documents only VERBOSE. It also made database-wide CLUSTER (ANALYZE) error out with the wrong command name in the message ('cannot execute REPACK (ANALYZE) on multiple tables'). Reject ANALYZE for CLUSTER the same way as CONCURRENTLY. --- src/backend/commands/repack.c | 7 +++++++ src/test/regress/expected/cluster.out | 3 +++ src/test/regress/sql/cluster.sql | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index dde56fb1e8d..edff54e734e 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -265,7 +265,14 @@ ExecRepack(ParseState *pstate, RepackStmt *stmt, bool isTopLevel) verbose = defGetBoolean(opt); else if (strcmp(opt->defname, "analyze") == 0 || strcmp(opt->defname, "analyse") == 0) + { + if (stmt->command != REPACK_COMMAND_REPACK) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ANALYZE option not supported for %s", + RepackCommandAsString(stmt->command))); analyze = defGetBoolean(opt); + } else if (strcmp(opt->defname, "concurrently") == 0) { if (stmt->command != REPACK_COMMAND_REPACK) diff --git a/src/test/regress/expected/cluster.out b/src/test/regress/expected/cluster.out index d1bc8a13286..3ac5cfa73d9 100644 --- a/src/test/regress/expected/cluster.out +++ b/src/test/regress/expected/cluster.out @@ -801,6 +801,9 @@ REPACK (ANALYZE) clstr_tst (a); REPACK (ANALYZE) clstr_tst; REPACK (VERBOSE) clstr_tst (a); ERROR: ANALYZE option must be specified when a column list is provided +-- The ANALYZE option is for REPACK only +CLUSTER (ANALYZE) clstr_tst USING clstr_tst_c; +ERROR: ANALYZE option not supported for CLUSTER -- REPACK w/o argument performs no ordering, so we can only check which tables -- have the relfilenode changed. RESET SESSION AUTHORIZATION; diff --git a/src/test/regress/sql/cluster.sql b/src/test/regress/sql/cluster.sql index e7a62367adf..104cc19888b 100644 --- a/src/test/regress/sql/cluster.sql +++ b/src/test/regress/sql/cluster.sql @@ -385,6 +385,9 @@ REPACK (ANALYZE) clstr_tst (a); REPACK (ANALYZE) clstr_tst; REPACK (VERBOSE) clstr_tst (a); +-- The ANALYZE option is for REPACK only +CLUSTER (ANALYZE) clstr_tst USING clstr_tst_c; + -- REPACK w/o argument performs no ordering, so we can only check which tables -- have the relfilenode changed. RESET SESSION AUTHORIZATION; -- 2.54.0