Re: DDL deparse

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Nikhil Sontakke <nikhil(at)planetscale(dot)com>
Cc: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Subject: Re: DDL deparse
Date: 2026-11-14 01:39:06
Message-ID: CAD21AoBSAQNC1kG-9VTsh3URidXSD3+MB4vMipPDPJw=X83y_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 11, 2026 at 4:17 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> Hi,
>
> Sorry for the late reply.
>
> On Wed, Oct 14, 2026 at 12:48 AM Nikhil Sontakke <nikhil(at)planetscale(dot)com> wrote:
> >
> >>
> >> I've rebased and updated the patch.
> >>
> >
> > I reviewed and tested the v2 series. And found some issues that I attempted to fix via
> > two follow-up patches, to apply in order on top of your four-patch series.
> >
> > The first addresses three correctness cases:
> >
> > * Repeated identity clauses on the same column currently match the first
> > raw subcommand more than once. The patch matches successive collected
> > identity subcommands to successive raw occurrences.
> >
> > * ADD COLUMN b int DEFAULT 1 followed by ALTER COLUMN b SET DEFAULT 2
> > currently reads the final catalog default for both clauses. The patch
> > captures each relevant subcommand's cooked default when it is collected,
> > preserving the distinct effects on existing rows and future inserts.
> >
> > * Table-level IF EXISTS is preserved for ordinary ALTER TABLE, column and
> > constraint renames, and SET SCHEMA. Table rename already handles it.
> >
> > The second patch adds SQL regression coverage for nested DDL. I'm happy to
> > report that these cases worked with the existing deparsing logic. The harness changes
> > use the existing settings without adding another GUC.
>
> Thank you for the report and the patch!
>
> I've reviewed and fixed them. I'll post the updated patch soon.

I've attached the updated patches.

While updating the patches, I realized that an event trigger function
had no reliable way to get the raw parse tree of a DDL together with
the commands collected for it. If a DDL is executed while another DDL
is being executed (e.g., by a function called in the USING expression
of ALTER TABLE ... ALTER COLUMN TYPE), the inner DDL is a separate
complete query and fires event triggers with its own collected
commands. Previously, the test module saved the raw parse tree in its
ProcessUtility hook, but nothing tied it to the collected commands, so
it could be paired with the inner DDL's commands. I think the event
trigger state is the right place to keep it. So the 0001 patch makes
the event trigger code keep a copy of the raw parse tree in the
per-complete-query state, and adds EventTriggerGetParsetree() to get
it. The parse tree and the collected commands then always come from
the same query.

I've also implemented DROP TABLE support (see 0006 patch). Other
changes are mostly bug fixes and cleanups I found while reviewing the
patches.

Please note that these patches are still at the PoC phase. Feedback is
very welcome.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v3-0005-Update-the-DDL-deparse-regression-tests-for-ALTER.patch application/x-patch 45.1 KB
v3-0006-Deparse-DROP-TABLE.patch application/x-patch 21.8 KB
v3-0002-Add-a-DDL-deparser-for-CREATE-TABLE.patch application/x-patch 83.2 KB
v3-0003-Add-regression-tests-for-DDL-deparse.patch application/x-patch 56.5 KB
v3-0004-Deparse-ALTER-TABLE.patch application/x-patch 74.1 KB
v3-0001-Keep-the-statement-of-a-complete-query-in-the-eve.patch application/x-patch 5.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Henson Choi 2026-11-14 02:09:11 Re: Add wait events for server logging destination writes
Previous Message xnervwang 2026-11-14 01:29:11 Re: [PATCH] pg_input_is_valid() reuses the first type name inside a PL/pgSQL loop