Review
v19 Preserve index DEPENDS ON EXTENSION, statistics targets, and descendant partition index properties across ALTER COLUMN TYPE
- Proposal version
- 19
- Base commit
- 412848dac37f2e4455e1505f83f0af0f3d28a67d
The latest emailed series is not the replica-identity-only fix in the Commitfest title. v19 is three patches. 0001 restores DEPENDS ON EXTENSION (pg_depend rows with deptype DEPENDENCY_AUTO_EXTENSION) for any index rebuilt by ALTER COLUMN TYPE. 0002 restores per-column attstattarget values, including for ALTER COLUMN ... SET EXPRESSION. 0003 is where replica identity still lives, together with descendant names, comments, indisclustered, statistics targets, reloptions, tablespaces, and extension dependencies. Replica identity of the table that owns the rebuilt index is still restored by the existing RememberReplicaIdentityForRebuilding() and AT_ReplicaIdentity path, which calls relation_mark_replica_identity().
git am -3 applied 0001 onto 412848dac37f2e4455e1505f83f0af0f3d28a67d and stopped on 0002. The blob ids are not in this repository, so a 3-way merge could not run. git apply accepts every 0002 and 0003 hunk except 0002's typedefs.list context: IndexScanHeapData now sits between IndexScanDescData and IndexScanInstrumentation, so the IndexStatTarget insertion does not match. 0003's PartitionIndexProps context still matches PartitionHashBound. Both names were inserted in sorted order so the rest of the series could be read. The emailed files do not apply unmodified.
indexcmds.c, tablecmds.c, repack.c, and parse_utilcmd.c then compiled with no warnings, after nodetags.h was regenerated so T_IndexStatTarget and T_PartitionIndexProps exist. The reference build's nodetags.h does not. The commitfest page shows cfbot green; that run is not this compile.
The bug is real. ALTER COLUMN TYPE deparses an index with pg_get_indexdef_string() and creates a replacement. That string cannot express an extension dependency or a statistics target. For a partitioned index, DefineIndex() builds each child with generateClonedIndexStmt(), which drops child-only names, comments, replica identity, clustering, reloptions, and tablespaces. In ATRewriteCatalogs(), the parent's ATPostAlterTypeCleanup() runs before children scan their own columns, and dropping the parent index drops the descendants. The old per-partition call to RememberReplicaIdentityForRebuilding() therefore never saw those pg_index rows. That matches the original report: the parent index keeps indisreplident and the partition indexes do not.
State is captured before performMultipleDeletions(). RememberPartitionIndexProps() walks find_all_inheritors() and stores one PartitionIndexProps per descendant, keyed by the partition table OID. DefineIndex() copies that list through the recursion, and TransferPartitionIndexProps() fills the child IndexStmt. SetIndexStatTargets() writes pg_attribute.attstattarget. Extension links are recorded again with recordDependencyOn() and DEPENDENCY_AUTO_EXTENSION, which is what ExecAlterObjectDependsStmt() stores, using OIDs from getAutoExtensionsOfObject(). indisreplident and indisclustered are written with one pg_index update rather than relation_mark_replica_identity() or mark_index_clustered(). Those helpers clear the flag on sibling indexes; the patch comment says the siblings are mid-drop, and at most one index per table holds each flag. relreplident is updated only when it is not already REPLICA_IDENTITY_INDEX. ATExecCmd() increments the command counter after the subcommand, and index_create() has already queued a heap relcache invalidation that is sent at commit, so this path does not leave rd_replidindex stale. An explicit CacheInvalidateRelcache() next to that pg_index update would still match relation_mark_replica_identity(), which invalidates when the pg_class row does not change, and would not depend on that ordering.
ChooseRelationName() now takes the same "already reserved" name list used for constraints. CollectReservedIndexNames() passes the saved names of other descendants in the same namespace, and IndexNameIsReserved() rejects them. That is the right fix for the reported error, where an attached index had been renamed to the default name of a partition that had no index yet. In-tree callers were updated. The extra argument is an exported signature change, which is acceptable on this branch.
The new expected output also shows the limit of that fix. The command used to abort. It now commits with partition p1 indexed as p1_a_idx1 while p2 keeps p1_a_idx. pg_get_indexdef_string() passes inherits as true, so ONLY is not deparsed, and DefineIndex() creates an index on the partition that previously had none. Losing ON ONLY is older than v19; the reserved-name change is what lets this particular case commit, and the test freezes that result. Preserving ON ONLY is not part of this patch.
The tests otherwise hit the right catalogs: plain and constraint indexes, SET EXPRESSION, multi-level partitions, renamed descendants, comments, attstattarget, fillfactor, a tablespace that differs from default_tablespace, indisreplident, indisclustered, and deptype 'x' rows. The jsonb before/after diff of pg_class, pg_index, pg_attribute, comments, and relreplident is the right check. The regression suite was not run here. No documentation change; silent preservation of existing catalog state does not need one.
Assessment 74 starts at 70. The design follows the existing rebuild path and the tests pin the catalog rows down. It does not go higher, because the series still needs a typedefs.list rebase, ON ONLY is still discarded, and the direct pg_index update is thinner than the helper it avoids. Consensus 60 starts at 50. Paquier's test that did not fail, the mismatched elog, and the name clash were answered, including in the v19 note. It is not 70: the 2026-10-06 note that 0003 overlaps another patch, which tries to avoid rebuilding leaf indexes, has no reply, and the entry is still Needs review.