Re: Proposal to CREATE FOREIGN TABLE LIKE

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Sami Imseih <samimseih(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Proposal to CREATE FOREIGN TABLE LIKE
Date: 2025-02-17 11:14:59
Message-ID: ae691413-72c5-4f17-8a31-141f70bbabd6@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Feb 17, 2025 at 15:24 +0800, Michael Paquier <michael(at)paquier(dot)xyz>, wrote:
>
> + * For foreign tables, they have no storage in Postgres.
> + * Inapplicable options are ignored.
>
> Wording is a bit strange here.
Hi, is this better?

 * Foreign tables do not store data in Postgres.
 * Any options that are not applicable for foreign tables will be ignored:

> + * CREATE_TABLE_LIKE_COMPRESSION
> + * CREATE_TABLE_LIKE_IDENTITY
> + * CREATE_TABLE_LIKE_STORAGE
> + * CREATE_TABLE_LIKE_INDEXES
> [...]
> +DROP FOREIGN TABLE ctl_foreign_table1;
> +DROP FOREIGN TABLE ctl_foreign_table2;
> +DROP FOREIGN TABLE ctl_foreign_table3;
> +DROP FOREIGN TABLE ctl_foreign_table4;
> +DROP FOREIGN TABLE ctl_foreign_table5;
> +DROP FOREIGN TABLE ctl_foreign_table6;
>
> What's the point of creating that many tables, one for each of the
> four INCLUDING options you are testing? It is possible to stack all
> of them in a single CREATE TABLE command, still is that really
> necessary if we have coverage with INCLUDING ALL and EXCLUDING ALL
> (perhaps write it directly in the CREATE query rather than assume that
> it is the default) as these are all-or-nothing switches for all the
> option values. Of course let's be careful with HIDE_TOAST_COMPRESSION
> if need be.

I usually follow the cases within the same file; for each independent option, it becomes easier to identify which options are valid or invalid.
However, if you believe consolidating them into one is better, I’m fine with that. Updated.
> Perhaps the original table should have a primary key, also to track
> the fact that the NOT NULL constraint is always copied but its related
> index is not? Identity columns assign a NOT NULL constraint, as
> documented these are always copied. Just wanted to point out that
> this works the same way for your implementation with foreign tables,
> so perhaps we should have a test for that.
Done, although there is already one in column d.
>
> Glad to see that you did not forget about statistics. I didn't recall
> that these were OK for foreign tables, TBH.
I also didn't realize this until I wrote this patch. This could be useful for the planner?

> expandTableLikeClause() depends on the "constr" built in the first
> phase of transformTableLikeClause() to bypass the parts related to
> generated, default and constraints properties. This dependency
> between both routines should be documented, I guess. Hmm.. Not sure
> where.
Comments are addressed except for this one, it might be worth considering another patch.

--
Zhang Mingli
HashData

Attachment Content-Type Size
v5-0001-CREATE-FOREIGN-TABLE-LIKE.patch application/octet-stream 16.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Shlok Kyal 2025-02-17 11:31:16 Re: Restrict copying of invalidated replication slots
Previous Message Jim Jones 2025-02-17 11:12:21 Re: [PATCH] Add CANONICAL option to xmlserialize