pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Preserve INCLUDE columns on PRIMARY KEY and UNIQUE constraints

Open zikolach opened this issue 1 month ago • 0 comments

Problem

pgschema dump omits INCLUDE columns from PRIMARY KEY and UNIQUE constraints. Replay therefore creates different backing indexes. A subsequent plan can be empty because the inspector does not retain the included columns in the constraint representation.

Reproduction

Create this schema in an empty source database:

CREATE TABLE events (
    id integer,
    a integer,
    payload text,
    CONSTRAINT root_unique UNIQUE (id, a) INCLUDE (payload)
) PARTITION BY RANGE (id);
CREATE TABLE events_leaf PARTITION OF events FOR VALUES FROM (0) TO (10);

Dump the source and replay the SQL into another empty database. Inspect both databases with:

SELECT t.relname, c.conname, pg_get_constraintdef(c.oid)
FROM pg_constraint c
JOIN pg_class t ON t.oid = c.conrelid
JOIN pg_namespace n ON n.oid = t.relnamespace
WHERE n.nspname = 'public' AND c.contype = 'u'
ORDER BY t.relname, c.conname;

The source contains UNIQUE (id, a) INCLUDE (payload) on the parent and child. Replay contains UNIQUE (id, a) on both.

Expected behavior

Dump, replay, and plan/apply should preserve included columns on ordinary and partitioned PRIMARY KEY and UNIQUE constraints. The planner should detect a change to included columns. Included columns must remain distinct from the uniqueness key.

Verification and scope

Reproduced with synthetic schemas on PostgreSQL 14–18 against main at 36a38ff3. The same loss occurs before #663, so this is an existing limitation.

Related to #653, #663, and closed PR #645. This report isolates INCLUDE preservation from inherited-name restoration, SQL-loader changes, and constraint comments.

zikolach avatar Oct 28 '26 12:10 zikolach