Skip to content

Commit 288e499

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 1661c40 commit 288e499

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

1037+
-- check schema-qualification of regconfig constant
1038+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
1039+
(COPY = pg_catalog.english);
1040+
EXPLAIN (VERBOSE, COSTS OFF)
1041+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1042+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1043+
QUERY PLAN
1044+
----------------------------------------------------------------------------------------------------------------------------------------------
1045+
Foreign Scan on public.ft1
1046+
Output: c1, to_tsvector('custom_search'::regconfig, c3)
1047+
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))
1048+
(3 rows)
1049+
1050+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1051+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1052+
c1 | to_tsvector
1053+
-----+-------------
1054+
642 | '00642':1
1055+
(1 row)
1056+
10371057
-- ===================================================================
10381058
-- JOIN queries
10391059
-- ===================================================================

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,14 @@ set_transmission_modes(void)
34413441
PGC_USERSET, PGC_S_SESSION,
34423442
GUC_ACTION_SAVE, true, 0, false);
34433443

3444+
/*
3445+
* In addition force restrictive search_path, in case there are any
3446+
* regproc or similar constants to be printed.
3447+
*/
3448+
(void) set_config_option("search_path", "pg_catalog",
3449+
PGC_USERSET, PGC_S_SESSION,
3450+
GUC_ACTION_SAVE, true, 0, false);
3451+
34443452
return nestlevel;
34453453
}
34463454

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ EXPLAIN (VERBOSE, COSTS OFF)
373373
SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
374374
SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
375375

376+
-- check schema-qualification of regconfig constant
377+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
378+
(COPY = pg_catalog.english);
379+
EXPLAIN (VERBOSE, COSTS OFF)
380+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
381+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
382+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
383+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
384+
376385
-- ===================================================================
377386
-- JOIN queries
378387
-- ===================================================================

0 commit comments

Comments
 (0)