Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26c9e1b

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/[email protected]
1 parent d3b0884 commit 26c9e1b

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
@@ -1008,6 +1008,26 @@ SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
10081008
9
10091009
(1 row)
10101010

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

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,14 @@ set_transmission_modes(void)
31143114
PGC_USERSET, PGC_S_SESSION,
31153115
GUC_ACTION_SAVE, true, 0, false);
31163116

3117+
/*
3118+
* In addition force restrictive search_path, in case there are any
3119+
* regproc or similar constants to be printed.
3120+
*/
3121+
(void) set_config_option("search_path", "pg_catalog",
3122+
PGC_USERSET, PGC_S_SESSION,
3123+
GUC_ACTION_SAVE, true, 0, false);
3124+
31173125
return nestlevel;
31183126
}
31193127

contrib/postgres_fdw/sql/postgres_fdw.sql

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

367+
-- check schema-qualification of regconfig constant
368+
CREATE TEXT SEARCH CONFIGURATION public.custom_search
369+
(COPY = pg_catalog.english);
370+
EXPLAIN (VERBOSE, COSTS OFF)
371+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
372+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
373+
SELECT c1, to_tsvector('custom_search'::regconfig, c3) FROM ft1
374+
WHERE c1 = 642 AND length(to_tsvector('custom_search'::regconfig, c3)) > 0;
375+
367376
-- ===================================================================
368377
-- JOIN queries
369378
-- ===================================================================

0 commit comments

Comments
 (0)