| From: | Nikhil Sontakke <nikhil(at)planetscale(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Subject: | Fix CYCLE clause deparsing and dump/restore |
| Date: | 2026-11-12 09:56:37 |
| Message-ID: | CA+UBoq07qeS8mLMV+_Pjp_-gTYZDAPEzG7OXQ-CH5vP4+Z+oRA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Dirkjan Bussink reported that a view using CYCLE markers 'Y' and 'N'
cannot be recreated from pg_get_viewdef output. The deparser emits
TO 'Y'::text DEFAULT 'N'::text, but the CYCLE grammar rejects the casts.
This also breaks dump/restore of such views.
The attached patch allows casts and parentheses around CYCLE literals,
while continuing to reject general expressions. It also fixes a separate
crash in pg_get_viewdef for domain markers: the default-Boolean check
assumes that both markers are bare Const nodes, which need not be true
for domain or typmod coercions.
Allowing explicit casts also introduces a way to invoke volatile
user-defined cast functions in cycle marks. The patch rejects these,
since repeated evaluation of a changing mark can defeat cycle detection.
The check runs after common-type coercion and also catches a pre-existing
case: volatile implicit casts applied to otherwise valid literal marks.
Tests cover both the newly allowed explicit-cast syntax and the existing
implicit-cast case.
There is a back-branch compatibility question here. The implicit-cast
case already parses on existing releases, and applying this volatility
check would prevent views using such casts from restoring after a minor
upgrade. Although the case requires a volatile user-defined implicit
cast and already has unreliable cycle detection, should we keep the
volatility check master-only? Another option is to check explicit casts
on back branches while preserving the existing implicit-coercion behavior.
The grammar and deparser fixes themselves are candidates for back-patching
to 14, where SEARCH and CYCLE were introduced.
The usual sanity checks and tests have been performed on 20devel.
The regression tests include ten representative marker pairs, view
recreation in both output formats, visible domain-view deparser output,
and rejection of general expressions and volatile casts.
Regards,
Nikhil Sontakke
PlanetScale
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-CYCLE-clause-deparsing-and-dump-restore.patch | application/octet-stream | 19.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dean Rasheed | 2026-11-12 09:58:28 | Re: [PG19] Wrong results from NOT NULL-based expression simplification |
| Previous Message | Amit Kapila | 2026-11-12 09:32:44 | Re: Add a hook for handling logical decoding messages on subscribers. |