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

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: pg_dump compatibility level / use create view instead of createtable/rule
Дата
Msg-id 20191026205630.cubjcxgs2rhke7xa@alap3.anarazel.de
обсуждение исходный текст
Ответ на Re: pg_dump compatibility level / use create view instead of create table/rule  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: pg_dump compatibility level / use create view instead of create table/rule
Re: pg_dump compatibility level / use create view instead of create table/rule
Список 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_dump compatibility level / use create view instead of create table/rule
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pg_dump compatibility level / use create view instead of create table/rule