Skip to content

Commit b8032f4

Browse files
committed
postgres_fdw: set search_path to 'pg_catalog' while deparsing constants.
The motivation for this is to ensure successful transmission of the values of constants of regconfig and other reg* types. The remote will be reading them with search_path = 'pg_catalog', so schema qualification is necessary when referencing objects in other schemas. Per bug #17483 from Emmanuel Quincerot. Back-patch to all supported versions. (There's some other stuff to do here, but it's less back-patchable.) Discussion: https://postgr.es/m/1423433.1652722406@sss.pgh.pa.us
1 parent 91377a4 commit b8032f4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,26 @@ SELECT * FROM ft1 WHERE CASE c3 COLLATE "C" WHEN c6 THEN true ELSE c3 < 'bar' EN
11631163
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
11641164
(4 rows)
11651165

1166+
-- check schema-qualification of regconfig constant
1167+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
1168+
(COPY = pg_catalog.english);
1169+
EXPLAIN (VERBOSE, COSTS OFF)
1170+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1171+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1172+
QUERY PLAN
1173+
----------------------------------------------------------------------------------------------------------------------------------------------
1174+
Foreign Scan on public.ft1
1175+
Output: c1, to_tsvector('custom_search'::regconfig, c3)
1176+
Remote SQL: SELECT "C 1", c3 FROM "S 1"."T 1" WHERE (("C 1" = 642)) AND ((length(to_tsvector('public.custom_search'::regconfig, c3)) > 0))
1177+
(3 rows)
1178+
1179+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1180+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1181+
c1 | to_tsvector
1182+
-----+-------------
1183+
642 | '00642':1
1184+
(1 row)
1185+
11661186
-- ===================================================================
11671187
-- JOIN queries
11681188
-- ===================================================================

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,14 @@ set_transmission_modes(void)
38993899
PGC_USERSET, PGC_S_SESSION,
39003900
GUC_ACTION_SAVE, true, 0, false);
39013901

3902+
/*
3903+
* In addition force restrictive search_path, in case there are any
3904+
* regproc or similar constants to be printed.
3905+
*/
3906+
(void) set_config_option("search_path", "pg_catalog",
3907+
PGC_USERSET, PGC_S_SESSION,
3908+
GUC_ACTION_SAVE, true, 0, false);
3909+
39023910
return nestlevel;
39033911
}
39043912

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,15 @@ SELECT * FROM ft1 WHERE CASE c3 WHEN c6 THEN true ELSE c3 < 'bar' END;
442442
EXPLAIN (VERBOSE, COSTS OFF)
443443
SELECT * FROM ft1 WHERE CASE c3 COLLATE "C" WHEN c6 THEN true ELSE c3 < 'bar' END;
444444

445+
-- check schema-qualification of regconfig constant
446+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
447+
(COPY = pg_catalog.english);
448+
EXPLAIN (VERBOSE, COSTS OFF)
449+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
450+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
451+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
452+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
453+
445454
-- ===================================================================
446455
-- JOIN queries
447456
-- ===================================================================

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