Partition with its own VIRTUAL generation expression: wrong result with constraint_exclusion = on, and shihao's v1 against every DDL path ========================================================================= Correctness only, no timings. One machine (x86_64, Linux), gcc, --enable-cassert --enable-debug, CFLAGS=-O2. 17 and older not run (no virtual generated columns before 18). Builds 18.6 REL_18_6 release 19beta4 REL_19_BETA4 (before d8444163d22) 19rc1 REL_19_RC1 (contains d8444163d22) master dfd7ede529f (2026-10-25) m-v1 master + v1-0001 (applies cleanly) 19-v1 REL_19_STABLE 2b491ff1cd2 + v1-0001; plain "git am" fails on the src/bin/pg_upgrade/check.c prototype context (check_for_pg_role_prefix is still there in 19); "git am -3" applies it without conflicts 18-v1 REL_18_STABLE 1735ad557d3 + nocfbot-v1-REL_18-0001 mutant m-v1 with the CheckPartitionVirtualGeneratedExprs() call in MergeAttributesIntoExisting() removed (ATTACH unchecked) 1. repro-ce-on.sql.txt (correct answer: 1 in every cell) ------------------------------------------------------- 18.6 19beta4 19rc1 master NOT NULL: count(*) WHERE v IS NULL constraint_exclusion=partition 1 1 1 1 constraint_exclusion=on 0 0 0 0 CHECK (v > 0): count(*) WHERE v < 0 constraint_exclusion=partition 1 1 1 1 constraint_exclusion=on 0 0 0 0 Plan with "on": Result, One-Time Filter: false, on all four. m-v1, 19-v1, 18-v1: both CREATE TABLE ... PARTITION OF are rejected, so the case cannot be built. 2. paths.sql.txt: DDL paths that create a divergent expression -------------------------------------------------------------- A = accepted, R = rejected 18.6/master m-v1/19-v1/18-v1 P1 CREATE TABLE ... PARTITION OF, LIST A R P2 same, RANGE and HASH A R P3 ATTACH PARTITION A R P4 DEFAULT partition A R P5 SET EXPRESSION on a partition A R SET EXPRESSION on ONLY parent A R P6 partitioned partition, own expression A R leaf under it, own expression A R SET EXPRESSION on the middle level A R ATTACH of a partitioned table (its leaf matches it, it differs from the parent) A R P7 CREATE FOREIGN TABLE ... PARTITION OF A R ATTACH of a foreign table A R 13 divergent statements: 13 errors on each patched build, the same 13 statements, and 0 on 18.6/master. Every control with the parent's expression is accepted on all builds: CREATE ... PARTITION OF with the same or no expression, ATTACH with a different column order, recursive SET EXPRESSION on the parent, a leaf under a partitioned partition. P8 (STORED partitions, INHERITS children, SET EXPRESSION on an INHERITS child) is accepted on all builds. Final query (the one from nocfbot-find-mismatched-virtual-exprs.sql): 7 rows on 18.6/master, 0 rows on each patched build. mutant: the 3 ATTACH statements are accepted again (10 errors), and the final query lists the 2 that survive to the end (m3, f2). 3. legacy.sh.txt: divergent partitions that already exist --------------------------------------------------------- Created on 18.6: p1 (NOT NULL broken through the parent), c1 (CHECK on v broken), b1 (no constraint), k1 (CHECK (a > 0), not on v). 1 18.6: the query lists 4; constraint_exclusion=on gives 0 and 0. 3 pg_upgrade --check 18.6 -> m-v1 and -> 19-v1: fatal, the report file lists the 4 columns, on both. 4 same data directory started with 18-v1: the query lists 4; constraint_exclusion=on still gives 0 and 0 (the patch prevents new ones; existing ones stay until fixed). 5 18.6 pg_dump restored into 18-v1: each of the 4 ATTACH PARTITION fails, as the v1 mail says. 7 ALTER TABLE ALTER COLUMN v SET EXPRESSION (on 18-v1): b ok p ERROR: column "v" of relation "p1" contains null values c ERROR: ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints k same ERROR as c, although its CHECK does not involve v 7b after deleting the violating rows: p ok, c same ERROR. The restriction is in REL_18_STABLE ATExecSetExpression() (num_check > 0 on the relation, any CHECK); f80bedd52b1 lifted it in 19 and it was not back-patched. 7c in one transaction: DROP CONSTRAINT, SET EXPRESSION on the parent, ADD CONSTRAINT again, for c and k: ok; the query lists 0. 8 pg_upgrade --check after 7c -> m-v1 and -> 19-v1: compatible. 4. Tests on the patched builds ------------------------------ make check: m-v1 239/239, 19-v1 239/239, 18-v1 231/231. src/bin/pg_upgrade TAP on m-v1 (--enable-tap-tests, PROVE_FLAGS=-j1): 8 files, 160 tests, PASS. Not run: check-world, meson/clang, cross-version pg_upgrade TAP. How to repeat psql -X -f repro-ce-on.sql.txt (any database) psql -X -f paths.sql.txt (fresh database) bash legacy.sh.txt OLD18=<18.x bindir> NEW18= \