| From: | Vitaly Davydov <v(dot)davydov(at)postgrespro(dot)ru> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
| Cc: | Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Hou, Zhijie/侯 志杰 <houzj(dot)fnst(at)fujitsu(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: DDL deparse |
| Date: | 2026-06-25 08:12:07 |
| Message-ID: | 6d7807d9-ee94-4dfd-bed9-d743ecb8e9db@postgrespro.ru |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Dear Hackers,
> So my question is: should DDL deparse preserve user intent, or is it
> acceptable to materialize the catalog state (in which case, should we
> just extend pg_get_table_ddl instead)?
I think, it depends on the usage scenarios. There are some use cases of:
major upgrade, replication to other databases, replication to other
cliends, DDL mining from WAL, logging and audit. In case of replication to
other databases, splitting a complex command to a number of simple commands
that materialize the same schema looks ok. In case of DDL mining from WAL
or logging and audit scenarios it would be preferable to keep user intent.
Sorry for off-topic, but I'm still not sure that deparsing the original DDL
command from the parse tree is the best approach. Below are some problem
queries for deparsing original DDL from the parse tree.
Query 1: CTAS with function
CREATE OR REPLACE FUNCTION f1()
RETURNS integer
AS $$
CREATE TABLE t2(c INT);
SELECT 10;
$$
LANGUAGE SQL;
CREATE TABLE t AS SELECT f1();
Query 2: CTAS with a temp table
CREATE TABLE t AS SELECT * FROM temptable;
Query 3: CTAS with a function parameter
CREATE TABLE t AS SELECT @mypar
Decoding final changes in the WAL seems to be the more suitable approach
for such cases.
Adding a new data into the WAL like a new record type with original DDL for
for logical decoding seems redundant. Decoding system catalog changes from
the WAL with some new hints may help to decode the commands like
ALTER TABLE ALTER COLUMN TYPE USING. Defining user command boundaries in the
WAL may help to decode the original command as well.
With best regards,
Vitaly
| From | Date | Subject | |
|---|---|---|---|
| Next Message | wufengwufengwufeng | 2026-06-25 08:21:11 | [PATCH] Check dead heap items before marking them unused |
| Previous Message | Michael Paquier | 2026-06-25 08:00:33 | Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks |