Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6230bd7

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 c75b6b4 commit 6230bd7

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

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

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,14 @@ set_transmission_modes(void)
34953495
PGC_USERSET, PGC_S_SESSION,
34963496
GUC_ACTION_SAVE, true, 0, false);
34973497

3498+
/*
3499+
* In addition force restrictive search_path, in case there are any
3500+
* regproc or similar constants to be printed.
3501+
*/
3502+
(void) set_config_option("search_path", "pg_catalog",
3503+
PGC_USERSET, PGC_S_SESSION,
3504+
GUC_ACTION_SAVE, true, 0, false);
3505+
34983506
return nestlevel;
34993507
}
35003508

contrib/postgres_fdw/sql/postgres_fdw.sql

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

401+
-- check schema-qualification of regconfig constant
402+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
403+
(COPY = pg_catalog.english);
404+
EXPLAIN (VERBOSE, COSTS OFF)
405+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
406+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
407+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
408+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
409+
401410
-- ===================================================================
402411
-- JOIN queries
403412
-- ===================================================================

0 commit comments

Comments
 (0)