Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 20b6847

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 cec2754 commit 20b6847

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/backend/catalog/system_views.sql

+4-5
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202209011
60+
#define CATALOG_VERSION_NO 202209062
6161

6262
#endif

src/test/regress/expected/rules.out

+2-7
Original file line numberDiff line numberDiff line change
@@ -1440,13 +1440,8 @@ pg_publication_tables| SELECT p.pubname,
14401440
n.nspname AS schemaname,
14411441
c.relname AS tablename,
14421442
( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg
1443-
FROM (unnest(
1444-
CASE
1445-
WHEN (gpt.attrs IS NOT NULL) THEN (gpt.attrs)::integer[]
1446-
ELSE ( SELECT array_agg(g.g) AS array_agg
1447-
FROM generate_series(1, (c.relnatts)::integer) g(g))
1448-
END) k(k)
1449-
JOIN pg_attribute a ON (((a.attrelid = gpt.relid) AND (a.attnum = k.k))))) AS attnames,
1443+
FROM pg_attribute a
1444+
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,
14501445
pg_get_expr(gpt.qual, gpt.relid) AS rowfilter
14511446
FROM pg_publication p,
14521447
LATERAL pg_get_publication_tables((p.pubname)::text) gpt(relid, attrs, qual),

0 commit comments

Comments
 (0)