aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-09-06 18:00:32 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-09-06 18:00:32 -0400
commite25631265a233e0c315458b206e419eca69fdb22 (patch)
tree93d27509353cc2e2c8be2af4eac987ee12615377 /src
parent6e55ea79faa56db85a2b6c5bf94cee8acf8bfdb8 (diff)
downloadpostgresql-e25631265a233e0c315458b206e419eca69fdb22.tar.gz
postgresql-e25631265a233e0c315458b206e419eca69fdb22.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/system_views.sql9
-rw-r--r--src/include/catalog/catversion.h2
-rw-r--r--src/test/regress/expected/rules.out9
3 files changed, 7 insertions, 13 deletions
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index fedaed533b9..76e4177c451 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -370,11 +370,10 @@ CREATE VIEW pg_publication_tables AS
N.nspname AS schemaname,
C.relname AS tablename,
( SELECT array_agg(a.attname ORDER BY a.attnum)
- FROM unnest(CASE WHEN GPT.attrs IS NOT NULL THEN GPT.attrs
- ELSE (SELECT array_agg(g) FROM generate_series(1, C.relnatts) g)
- END) k
- JOIN pg_attribute a
- ON (a.attrelid = GPT.relid AND a.attnum = k)
+ FROM pg_attribute a
+ WHERE a.attrelid = GPT.relid AND a.attnum > 0 AND
+ NOT a.attisdropped AND
+ (a.attnum = ANY(GPT.attrs) OR GPT.attrs IS NULL)
) AS attnames,
pg_get_expr(GPT.qual, GPT.relid) AS rowfilter
FROM pg_publication P,
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 24919bdead9..c616a258d58 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202209011
+#define CATALOG_VERSION_NO 202209061
#endif
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index fc3cde32264..5925a792b63 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1439,13 +1439,8 @@ pg_publication_tables| SELECT p.pubname,
n.nspname AS schemaname,
c.relname AS tablename,
( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg
- FROM (unnest(
- CASE
- WHEN (gpt.attrs IS NOT NULL) THEN (gpt.attrs)::integer[]
- ELSE ( SELECT array_agg(g.g) AS array_agg
- FROM generate_series(1, (c.relnatts)::integer) g(g))
- END) k(k)
- JOIN pg_attribute a ON (((a.attrelid = gpt.relid) AND (a.attnum = k.k))))) AS attnames,
+ FROM pg_attribute a
+ 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,
pg_get_expr(gpt.qual, gpt.relid) AS rowfilter
FROM pg_publication p,
LATERAL pg_get_publication_tables((p.pubname)::text) gpt(relid, attrs, qual),