]> granicus.if.org Git - postgresql/commitdiff
Switch function current_schema[s]() to be parallel-unsafe
authorMichael Paquier <michael@paquier.xyz>
Wed, 27 Mar 2019 02:35:12 +0000 (11:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 27 Mar 2019 02:35:12 +0000 (11:35 +0900)
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

src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/temp.out
src/test/regress/sql/temp.sql

index c1e1d601ec52e5489d1aa16fea19708f340635c8..f01087614e42265426108d18956ac6f6617e55d4 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     201903251
+#define CATALOG_VERSION_NO     201903271
 
 #endif
index acf1131b521a68a7de0624effac09b8b6420ee92..8cf77297e14f494807907dc5b8f134baf0122677 100644 (file)
   prosrc => 'name_text' },
 
 { oid => '1402', descr => 'current schema name',
-  proname => 'current_schema', provolatile => 's', prorettype => 'name',
-  proargtypes => '', prosrc => 'current_schema' },
+  proname => 'current_schema', provolatile => 's', proparallel => 'u',
+  prorettype => 'name', proargtypes => '', prosrc => 'current_schema' },
 { oid => '1403', descr => 'current schema search list',
-  proname => 'current_schemas', provolatile => 's', prorettype => '_name',
-  proargtypes => 'bool', prosrc => 'current_schemas' },
+  proname => 'current_schemas', provolatile => 's', proparallel => 'u',
+  prorettype => '_name', proargtypes => 'bool', prosrc => 'current_schemas' },
 
 { oid => '1404', descr => 'substitute portion of string',
   proname => 'overlay', prorettype => 'text',
index 056e5ecf33c9c621d7d12ced9f3b3ba0b812b266..ad7d558191142fc45653f45f32450e4d2cc244fa 100644 (file)
@@ -360,11 +360,8 @@ prepare transaction 'twophase_tab';
 ERROR:  cannot PREPARE a transaction that has operated on temporary objects
 -- Corner case: current_schema may create a temporary schema if namespace
 -- creation is pending, so check after that.  First reset the connection
--- to remove the temporary namespace, and make sure that non-parallel plans
--- are used.
+-- to remove the temporary namespace.
 \c -
-SET max_parallel_workers = 0;
-SET max_parallel_workers_per_gather = 0;
 SET search_path TO 'pg_temp';
 BEGIN;
 SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;
index 17366a33a919b40ec99cf973dd526455d00289a2..e634ddb9ca4202b187fd22604c69cb252f34dd04 100644 (file)
@@ -274,11 +274,8 @@ prepare transaction 'twophase_tab';
 
 -- Corner case: current_schema may create a temporary schema if namespace
 -- creation is pending, so check after that.  First reset the connection
--- to remove the temporary namespace, and make sure that non-parallel plans
--- are used.
+-- to remove the temporary namespace.
 \c -
-SET max_parallel_workers = 0;
-SET max_parallel_workers_per_gather = 0;
 SET search_path TO 'pg_temp';
 BEGIN;
 SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;