Skip to content

Commit 5bde165

Browse files
committed
Switch function current_schema[s]() to be parallel-unsafe
When invoked for the first time in a session, current_schema() and current_schemas() can finish by creating a temporary schema. Currently those functions are parallel-safe, however if for a reason or another they get launched across multiple parallel workers, they would fail when attempting to create a temporary schema as temporary contexts are not supported in this case. The original issue has been spotted by buildfarm members crake and lapwing, after commit c5660e0 has introduced the first regression tests based on current_schema() in the tree. After that, 396676b has introduced a workaround to avoid parallel plans but that was not completely right either. Catversion is bumped. Author: Michael Paquier Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/20190118024618.GF1883@paquier.xyz
1 parent 6ca015f commit 5bde165

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201903251
56+
#define CATALOG_VERSION_NO 201903271
5757

5858
#endif

src/include/catalog/pg_proc.dat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,11 +2787,11 @@
27872787
prosrc => 'name_text' },
27882788

27892789
{ oid => '1402', descr => 'current schema name',
2790-
proname => 'current_schema', provolatile => 's', prorettype => 'name',
2791-
proargtypes => '', prosrc => 'current_schema' },
2790+
proname => 'current_schema', provolatile => 's', proparallel => 'u',
2791+
prorettype => 'name', proargtypes => '', prosrc => 'current_schema' },
27922792
{ oid => '1403', descr => 'current schema search list',
2793-
proname => 'current_schemas', provolatile => 's', prorettype => '_name',
2794-
proargtypes => 'bool', prosrc => 'current_schemas' },
2793+
proname => 'current_schemas', provolatile => 's', proparallel => 'u',
2794+
prorettype => '_name', proargtypes => 'bool', prosrc => 'current_schemas' },
27952795

27962796
{ oid => '1404', descr => 'substitute portion of string',
27972797
proname => 'overlay', prorettype => 'text',

src/test/regress/expected/temp.out

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,8 @@ prepare transaction 'twophase_tab';
360360
ERROR: cannot PREPARE a transaction that has operated on temporary objects
361361
-- Corner case: current_schema may create a temporary schema if namespace
362362
-- creation is pending, so check after that. First reset the connection
363-
-- to remove the temporary namespace, and make sure that non-parallel plans
364-
-- are used.
363+
-- to remove the temporary namespace.
365364
\c -
366-
SET max_parallel_workers = 0;
367-
SET max_parallel_workers_per_gather = 0;
368365
SET search_path TO 'pg_temp';
369366
BEGIN;
370367
SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;

src/test/regress/sql/temp.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,8 @@ prepare transaction 'twophase_tab';
274274

275275
-- Corner case: current_schema may create a temporary schema if namespace
276276
-- creation is pending, so check after that. First reset the connection
277-
-- to remove the temporary namespace, and make sure that non-parallel plans
278-
-- are used.
277+
-- to remove the temporary namespace.
279278
\c -
280-
SET max_parallel_workers = 0;
281-
SET max_parallel_workers_per_gather = 0;
282279
SET search_path TO 'pg_temp';
283280
BEGIN;
284281
SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;

0 commit comments

Comments
 (0)