8000 postgres_fdw: set search_path to 'pg_catalog' while deparsing constants. · postgres/postgres@94bcb48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94bcb48

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 3f2344d commit 94bcb48

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
@@ -1013,6 +1013,26 @@ SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
10131013
9
10141014
(1 row)
10151015

1016+
-- check schema-qualification of regconfig constant
1017+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
1018+
(COPY = pg_catalog.english);
1019+
EXPLAIN (VERBOSE, COSTS OFF)
1020+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1021+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1022+
QUERY PLAN
1023+
----------------------------------------------------------------------------------------------------------------------------------------------
1024+
Foreign Scan on public.ft1
1025+
Output: c1, to_tsvector('custom_search'::regconfig, c3)
1026+
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))
1027+
(3 rows)
1028+
1029+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
1030+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
1031+
c1 | to_tsvector
1032+
-----+-------------
1033+
642 | '00642':1
1034+
(1 row)
1035+
10161036
-- ===================================================================
10171037
-- JOIN queries
10181038
-- ===================================================================

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,14 @@ set_transmission_modes(void)
33123312
PGC_USERSET, PGC_S_SESSION,
33133313
GUC_ACTION_SAVE, true, 0, false);
33143314

3315+
/*
3316+
* In addition force restrictive search_path, in case there are any
3317+
* regproc or similar constants to be printed.
3318+
*/
3319+
(void) set_config_option("search_path", "pg_catalog",
3320+
PGC_USERSET, PGC_S_SESSION,
3321+
GUC_ACTION_SAVE, true, 0, false);
3322+
33153323
return nestlevel;
33163324
}
33173325

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ EXPLAIN (VERBOSE, COSTS OFF)
370370
SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
371371
SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
372372

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

0 commit comments

Comments
 (0)
0