Skip to content

Commit e256312

Browse files
committed
Fix new pg_publication_tables query.
The addition of published column names forgot to filter on attisdropped, leading to cases where you could see "........pg.dropped.1........" or the like as a reportedly-published column. While we're here, rewrite the new subquery to get a more efficient plan for it. Hou Zhijie, per report from Jaime Casanova. Back-patch to v15 where the bug was introduced. (Sadly, this means we need a post-beta4 catversion bump before beta4 has even hit the streets. I see no good alternative though.) Discussion: https://postgr.es/m/Yxa1SU4nH2HfN3/i@ahch-to
1 parent 6e55ea7 commit e256312

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/backend/catalog/system_views.sql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ CREATE VIEW pg_publication_tables AS
370370
N.nspname AS schemaname,
371371
C.relname AS tablename,
372372
( SELECT array_agg(a.attname ORDER BY a.attnum)
373-
FROM unnest(CASE WHEN GPT.attrs IS NOT NULL THEN GPT.attrs
374-
ELSE (SELECT array_agg(g) FROM generate_series(1, C.relnatts) g)
375-
END) k
376-
JOIN pg_attribute a
377-
ON (a.attrelid = GPT.relid AND a.attnum = k)
373+
FROM pg_attribute a
374+
WHERE a.attrelid = GPT.relid AND a.attnum > 0 AND
375+
NOT a.attisdropped AND
376+
(a.attnum = ANY(GPT.attrs) OR GPT.attrs IS NULL)
378377
) AS attnames,
379378
pg_get_expr(GPT.qual, GPT.relid) AS rowfilter
380379
FROM pg_publication P,

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202209011
56+
#define CATALOG_VERSION_NO 202209061
5757

5858
#endif

src/test/regress/expected/rules.out

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,13 +1439,8 @@ pg_publication_tables| SELECT p.pubname,
14391439
n.nspname AS schemaname,
14401440
c.relname AS tablename,
14411441
( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg
1442-
FROM (unnest(
1443-
CASE
1444-
WHEN (gpt.attrs IS NOT NULL) THEN (gpt.attrs)::integer[]
1445-
ELSE ( SELECT array_agg(g.g) AS array_agg
1446-
FROM generate_series(1, (c.relnatts)::integer) g(g))
1447-
END) k(k)
1448-
JOIN pg_attribute a ON (((a.attrelid = gpt.relid) AND (a.attnum = k.k))))) AS attnames,
1442+
FROM pg_attribute a
1443+
WHERE ((a.attrelid = gpt.relid) AND (a.attnum > 0) AND (NOT a.attisdropped) AND ((a.attnum = ANY ((gpt.attrs)::smallint[])) OR (gpt.attrs IS NULL)))) AS attnames,
14491444
pg_get_expr(gpt.qual, gpt.relid) AS rowfilter
14501445
FROM pg_publication p,
14511446
LATERAL pg_get_publication_tables((p.pubname)::text) gpt(relid, attrs, qual),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy