Skip to content

Commit 810bcbd

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 c412c60 commit 810bcbd

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
@@ -1067,6 +1067,26 @@ SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
10671067
1 | 1 | 00001 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
10681068
(1 row)
10691069

1070+
-- check schema-qualification of regconfig constant
1071+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
1072+
(COPY = pg_catalog.english);
1073+
EXPLAIN (VERBOSE, COSTS OFF)
1074+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1075+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1076+
QUERY PLAN
1077+
----------------------------------------------------------------------------------------------------------------------------------------------
1078+
Foreign Scan on public.ft1
1079+
Output: c1, to_tsvector('custom_search'::regconfig, c3)
1080+
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))
1081+
(3 rows)
1082+
1083+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1084+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1085+
c1 | to_tsvector
1086+
-----+-------------
1087+
642 | '00642':1
1088+
(1 row)
1089+
10701090
-- ===================================================================
10711091
-- JOIN queries
10721092
-- ===================================================================

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
@@ -408,6 +408,15 @@ EXPLAIN (VERBOSE, COSTS OFF)
408408
SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
409409
SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
410410

411+
-- check schema-qualification of regconfig constant
412+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
413+
(COPY = pg_catalog.english);
414+
EXPLAIN (VERBOSE, COSTS OFF)
415+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
416+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
417+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
418+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
419+
411420
-- ===================================================================
412421
-- JOIN queries
413422
-- ===================================================================

0 commit comments

Comments
 (0)