Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSprM-0006Xm-0R for pgsql-general@arkaria.postgresql.org; Mon, 20 May 2019 21:30:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hSprK-0005bq-LU for pgsql-general@arkaria.postgresql.org; Mon, 20 May 2019 21:30:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSprK-0005a8-A7 for pgsql-general@lists.postgresql.org; Mon, 20 May 2019 21:30:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSprI-0001bM-2H for pgsql-general@postgresql.org; Mon, 20 May 2019 21:30:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x4KLU4NS012633; Mon, 20 May 2019 17:30:04 -0400 From: Tom Lane To: PegoraroF10 cc: Peter Eisentraut , pgsql-general@postgresql.org Subject: Re: =?UTF-8?Q?Re:_Refresh_Publication_takes_hours_and_doesn=C2=B4t_finish?= In-reply-to: <1558383480253-0.post@n3.nabble.com> References: <1551385426763-0.post@n3.nabble.com> <1558383480253-0.post@n3.nabble.com> Comments: In-reply-to PegoraroF10 message dated "Mon, 20 May 2019 13:18:00 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <12631.1558387804.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 May 2019 17:30:04 -0400 Message-ID: <12632.1558387804@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PegoraroF10 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=C2=B4t complete. If I ch= ange 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 =3D 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.pubn= ame, > n.nspname AS schemaname, c.relname AS tablename from pg_publication p in= ner > join pg_get_publication_tables(p.pubname) pt on true inner join pg_class= c > on pt.relid =3D c.oid inner join pg_namespace n ON (n.oid =3D c.relnames= pace); > 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 =3D C.relnamespace) - WHERE C.oid IN (SELECT relid FROM pg_get_publication_tables(P.pubname)= ); + JOIN pg_namespace N ON (N.oid =3D C.relnamespace), + LATERAL pg_get_publication_tables(P.pubname) + WHERE C.oid =3D pg_get_publication_tables.relid; regards, tom lane