]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Reject ALTER TABLE .. CLUSTER earlier for partitioned tables
authorMichael Paquier <michael@paquier.xyz>
Mon, 16 Mar 2026 08:48:39 +0000 (17:48 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 16 Mar 2026 08:48:39 +0000 (17:48 +0900)
ALTER TABLE .. CLUSTER ON and SET WITHOUT CLUSTER are not supported for
partitioned tables and already fail with a check happening when the
sub-command is executed, not when it is prepared.

This commit moves the relkind check for partitioned tables to happen
when the sub-command is prepared in ATSimplePermissions().  This matches
with the practice of the other sub-commands of ALTER TABLE, shaving one
translatable string.

mark_index_clustered() can be a bit simplified, switching one
elog(ERROR) to an assertion.  Note that mark_index_clustered() can also
be called through a CLUSTER command, but it cannot be reached for a
partitioned table, per the assertion based on the relkind in
cluster_rel(), and there is only one caller of rebuild_relation().

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAEoWx2kggo1N2kDH6OSfXHL_5gKg3DqQ0PdNuL4LH4XSTKJ3-g@mail.gmail.com

src/backend/commands/cluster.c
src/backend/commands/tablecmds.c
src/test/regress/expected/cluster.out

index 3bfaa6636997e56cc4bba498f4c244e271d136ec..09066db095623b2bc44e2e33039d9ff3a69ea623 100644 (file)
@@ -572,11 +572,7 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
        Relation        pg_index;
        ListCell   *index;
 
-       /* Disallow applying to a partitioned table */
-       if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
-               ereport(ERROR,
-                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                errmsg("cannot mark index clustered in partitioned table")));
+       Assert(rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE);
 
        /*
         * If the index is already marked clustered, no need to do anything.
index a2e3b72f15616af95f4a1c90e8cd551ed8e67257..991f3b85df734d30c15a98aa94b8e4b8794277a3 100644 (file)
@@ -5164,7 +5164,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
                case AT_ClusterOn:              /* CLUSTER ON */
                case AT_DropCluster:    /* SET WITHOUT CLUSTER */
                        ATSimplePermissions(cmd->subtype, rel,
-                                                               ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_MATVIEW);
+                                                               ATT_TABLE | ATT_MATVIEW);
                        /* These commands never recurse */
                        /* No command-specific prep needed */
                        pass = AT_PASS_MISC;
index 24b0b1a8fce86a96274935a910fd0d91a771c208..269f163efa6f8cac187f21f32e12782a7968ee3b 100644 (file)
@@ -492,9 +492,11 @@ Number of partitions: 3 (Use \d+ to list them.)
 CLUSTER clstrpart;
 ERROR:  there is no previously clustered index for table "clstrpart"
 ALTER TABLE clstrpart SET WITHOUT CLUSTER;
-ERROR:  cannot mark index clustered in partitioned table
+ERROR:  ALTER action SET WITHOUT CLUSTER cannot be performed on relation "clstrpart"
+DETAIL:  This operation is not supported for partitioned tables.
 ALTER TABLE clstrpart CLUSTER ON clstrpart_idx;
-ERROR:  cannot mark index clustered in partitioned table
+ERROR:  ALTER action CLUSTER ON cannot be performed on relation "clstrpart"
+DETAIL:  This operation is not supported for partitioned tables.
 -- and they cannot get an index-ordered REPACK without an explicit index name
 REPACK clstrpart USING INDEX;
 ERROR:  cannot execute REPACK on partitioned table "clstrpart" USING INDEX with no index name