Re: pg_dump compatibility level / use create view instead of create table/rule

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alex Williams <valenceshell(at)protonmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_dump compatibility level / use create view instead of create table/rule
Date: 2019-10-26 20:56:30
Message-ID: 20191026205630.cubjcxgs2rhke7xa@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi,

On 2019-10-10 11:20:14 -0400, Tom Lane wrote:
> regression=# create table mytab (f1 int primary key, f2 text);
> CREATE TABLE
> regression=# create view myview as select * from mytab group by f1;
> CREATE VIEW
>
> This situation is problematic for pg_dump because validity of the
> view depends on the existence of mytab's primary key constraint,
> and we don't create primary keys till late in the restore process.
> So it has to break myview into two parts, one to emit during normal
> table/view creation and one to emit after index creation.
>
> With 9.5's pg_dump, what comes out is:
>
> --
> -- Name: myview; Type: TABLE; Schema: public; Owner: postgres
> --
>
> CREATE TABLE public.myview (
> f1 integer,
> f2 text
> );
>
> ALTER TABLE ONLY public.myview REPLICA IDENTITY NOTHING;

Ick.

> The reason we get "REPLICA IDENTITY NOTHING" is that a view's relreplident
> is set to 'n' not 'd', which might not have been a great choice.

Hm, yea. I wonder if we should add a REPLICA_IDENTITY_INVALID or such,
for non relation relkinds? I'm mildly inclined to think that setting it
to REPLICA_IDENTITY_DEFAULT is at least as confusing as
REPLICA_IDENTITY_DEFAULT...

> This is fixed in v10 and up thanks to d8c05aff5. I was hesitant to
> back-patch that at the time, but now that it's survived in the field
> for a couple years, I think a good case could be made for doing so.

+1

> /* pretend view is a plain table and dump it that way */
> viewinfo->relkind = 'r'; /* RELKIND_RELATION */
> viewinfo->relkind = 'r'; /* RELKIND_RELATION */
> + viewinfo->relreplident = 'd'; /* REPLICA_IDENTITY_DEFAULT */
>
> That's mighty ugly but it doesn't seem to carry any particular
> risk.

I also could live with this, given it'd only be in older back-branches.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-10-26 21:16:37 Re: Proposition to use '==' as synonym for 'IS NOT DISTINCT FROM'
Previous Message Andres Freund 2019-10-26 20:51:57 Re: Proposition to use '==' as synonym for 'IS NOT DISTINCT FROM'

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2019-10-26 21:18:09 Re: pg_dump compatibility level / use create view instead of create table/rule
Previous Message Tom Lane 2019-10-26 19:03:18 Re: pg_dump compatibility level / use create view instead of create table/rule