Skip to content

Keep what partitions and inheritance children have of their own - #364

Merged
archlemon merged 4 commits into
mainfrom
partition-child-fidelity
Nov 21, 2026
Merged

archlemon merged 4 commits into
mainfrom
partition-child-fidelity

Conversation

@archlemon

Copy link
Copy Markdown
Member

Fixes #342
Fixes #344
Fixes #345
Fixes #348
Fixes #361

Partitions and inheritance children lost what they have of their own on pull/rebuild. Every probe fixture now rebuilds with a matching pg_dump on 17, 18 and 19 (f8_am also on 17, f23b_genpart on 17–19, f21_odd and f9_cons on 18–19).

#342: access methods

  • Pull compares a partition's access method with what it would get without USING: the access method of the closest ancestor that has one (17+), else default_table_access_method. A heap partition under a parent on a custom method now gets accessMethod: heap. A partition whose method matches its parent's no longer gets the key written. A partitioned table set explicitly to the default now gets it written.
  • Diff sets an existing partitioned table's new access method in Creates, before the partitions the plan creates, so they inherit it. A partition without accessMethod stays unmanaged, as before.
  • Pull now warns about access methods that no extension creates (CREATE ACCESS METHOD has no YAML), through the existing unsupported-objects warnings.

#344: NOT NULL NO INHERIT

  • New column key notNullNoInherit: true. It is introspected from connoinherit.
  • Diff: NOT NULL NO INHERIT in CREATE and ADD COLUMN, ADD CONSTRAINT ... NOT NULL col NO INHERIT [NOT VALID] when the constraint is added, and ALTER CONSTRAINT ... [NO] INHERIT to change an existing one (18+).
  • On a child's inherited column, with nullable: false, it applies to the NOT NULL constraint the child adds itself. Pull treats a parent's NO INHERIT constraint as nullable for its children.
  • pgy validate rejects the key on a partitioned table and warns on a nullable column. There is a version warning before 18.

#345: generation expressions a partition or child overrides

  • Pull writes generated on an inherited column whose expression differs from its parent's.
  • A table the plan creates gets the expression in CREATE (16+): PARTITION OF parent (col GENERATED ALWAYS AS (...) STORED|VIRTUAL), using the parent's kind. For an inheritance child, the column is written with the parent's type and collation, and PostgreSQL merges it, so attislocal matches the source. pg_dump leaves out a non-local override entirely, so a rebuild through SET EXPRESSION alone would have looked lossy.
  • An existing table is changed with ALTER TABLE ONLY ... SET EXPRESSION (17+, under --unsafe like a declared column, with a warning before 17). ONLY leaves grandchildren alone. A parent's changed expression recurses into its partitions and children, so the ones that declare their own get it set again after it.

#348: validity of an inherited NOT NULL NOT VALID

  • Fixed rather than documented as a limitation. A child created after its parent's NOT VALID constraint has a validated copy, and one created before has a NOT VALID copy. Creation order can't recover that, because the source DB can hold both kinds.
  • Pull writes notValid: false on an inherited column whose copy is validated while the parent's isn't. notValid now records whether it was written (NotValidSet).
  • Diff validates that copy with VALIDATE CONSTRAINT after the parent's constraint is added, or in the no-transaction migration for an existing table.

#361 (found along the way): NOT NULL names of partitions and children

  • A partition that was attached keeps its own NOT NULL constraint names, and so does a child created with a named NOT NULL. They were rebuilt with the parent's names.
  • Pull writes notNullName on such a copy. Diff names it in the CREATE (PARTITION OF parent (col CONSTRAINT name NOT NULL), or the full column for a child).
  • A NOT NULL the table adds itself is added or renamed under its name. On an existing table, an inherited copy can't be renamed (PostgreSQL refuses), so diff warns.
  • The validate warning that notNullName is ignored on partitions and children is gone.

Tests

  • Unit tests: diff, pull, schema parse, validate and JSON Schema.
  • Integration: TestIntegrationInheritedGeneratedOverrides (17+), TestIntegrationNotNullNoInheritAltered (18+), and an extended TestIntegrationAccessMethods.
  • Two new pull fixtures: generated_overrides.sql (16+) and not_null_inheritance.sql (18+). The fixture runner now skips a fixture whose first line is -- requires server_version_num N on older servers.
  • make test, go vet ./..., and the integration suites (./internal/cli/... ./internal/integration/... with PL and pg_dump) pass on PostgreSQL 15, 17, 18 and 19.

…ap partition under a parent on another access method, generation expressions, NOT NULL NO INHERIT, validated copies of a parent's NOT VALID NOT NULL and their constraint names; report access methods pull cannot express.
# Conflicts:
#	docs/feature_support.md
#	internal/diff/diff.go
#	internal/integration/pull_fixtures_test.go
@archlemon
archlemon merged commit f9b9d81 into main Nov 21, 2026
8 checks passed
@archlemon
archlemon deleted the partition-child-fidelity branch November 21, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant