Skip to content

Commit 0a7ccee

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 e993166 commit 0a7ccee

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
@@ -3896,6 +3896,14 @@ set_transmission_modes(void)
38963896
PGC_USERSET, PGC_S_SESSION,
38973897
GUC_ACTION_SAVE, true, 0, false);
38983898

3899+
/*
3900+
* In addition force restrictive search_path, in case there are any
3901+
* regproc or similar constants to be printed.
3902+
*/
3903+
(void) set_config_option("search_path", "pg_catalog",
3904+
PGC_USERSET, PGC_S_SESSION,
3905+
GUC_ACTION_SAVE, true, 0, false);
3906+
38993907
return nestlevel;
39003908
}
39013909

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)