pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: PegoraroF10 <marcos@f10.com.br>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Re: Refresh Publication takes hours and doesn´t finish
Date: Mon, 20 May 2019 17:30:04 -0400
Message-ID: <12632.1558387804@sss.pgh.pa.us> (raw)
In-Reply-To: <1558383480253-0.post@n3.nabble.com>
References: <1551385426763-0.post@n3.nabble.com>
	<1558383480253-0.post@n3.nabble.com>

PegoraroF10 <marcos@f10.com.br> writes:
> I tried sometime ago ... but with no responses, I ask you again.
> pg_publication_tables is a view that is used to refresh publication, but as
> we have 15.000 tables, it takes hours and doesn´t complete. If I change that
> view I can have an immediate result. The question is: Can I change that view
> ? There is some trouble changing those system views ?

> Original View is ...
> create view pg_catalog.pg_publication_tables as
> SELECT p.pubname, n.nspname AS schemaname, c.relname AS tablename FROM
> pg_publication p,
> (pg_class c JOIN pg_namespace n ON ((n.oid = c.relnamespace))) 
> WHERE (c.oid IN (SELECT pg_get_publication_tables.relid FROM
> pg_get_publication_tables((p.pubname)::text)
> pg_get_publication_tables(relid)));
> This way it takes 45 minutes to respond.

> I changed it to ... 
> create or replace pg_catalog.view pg_publication_tables as SELECT p.pubname,
> n.nspname AS schemaname, c.relname AS tablename from pg_publication p inner
> join pg_get_publication_tables(p.pubname) pt on true inner join pg_class c
> on pt.relid = c.oid inner join pg_namespace n ON (n.oid = c.relnamespace);
> This one takes just one or two seconds.

Hmm ... given that pg_get_publication_tables() shouldn't return any
duplicate OIDs, it does seem unnecessarily inefficient to put it in
an IN-subselect condition.  Peter, is there a reason why this isn't
a straight lateral join?  I get a much saner-looking plan from

    FROM pg_publication P, pg_class C
-        JOIN pg_namespace N ON (N.oid = C.relnamespace)
-   WHERE C.oid IN (SELECT relid FROM pg_get_publication_tables(P.pubname));
+        JOIN pg_namespace N ON (N.oid = C.relnamespace),
+        LATERAL pg_get_publication_tables(P.pubname)
+   WHERE C.oid = pg_get_publication_tables.relid;

			regards, tom lane





view thread (14+ messages)  latest in thread

Message-ID: <12632.1558387804@sss.pgh.pa.us>
Permalink:  ../12632.1558387804@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12632.1558387804@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, marcos@f10.com.br, peter.eisentraut@2ndquadrant.com
  Subject: Re: Refresh Publication takes hours and doesn´t finish
  In-Reply-To: <12632.1558387804@sss.pgh.pa.us>
  References: <1551385426763-0.post@n3.nabble.com> <1558383480253-0.post@n3.nabble.com> <12632.1558387804@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox