Hi,

I have gone through all our extensions and tried to tag all functions correctly according to their parallel safety.

I also did the same for the aggregate functions in a second patch, and for min(citext)/max(citext) set a COMBINEFUNC.

The changes for the functions is attached as one huge patch. Feel free to suggest a way to split it up or change it in any way if that would make it easier to review/apply.

Some open questions:

- How should we modify the aggregate functions when upgrading extensions? ALTER AGGREGATE cannot change COMBINEFUNC or PARALLEL. My current patch updates the system catalogs directly, which should be safe in this case, but is this an acceptable solution?

- Do you think we should add PARALLEL UNSAFE to the functions which we know are unsafe to make it obvious that it is intentional?

- I have not added the parallel tags to the functions used by our procedural languages. Should we do so?

- I have marked uuid-ossp, chkpass_in() and pgcrypto functions which generate random data as safe, despite that they depend on state in the backend. My reasoning is that, especially for the pgcrypto functions, that nobody should not rely on the PRNG state. For uuid-ossp I am on the fence.

- I have touched a lot of legacy libraries, like tsearch2 and the spi/* stuff. Is that a good idea?

- I decided to ignore that isn_weak() exists (and would make all input functions PARALLEL RESTRICTED) since it is only there is ISN_WEAK_MODE is defined. Is that ok?

Andreas

Attachment: parallel-contrib-1-funcs-v1.patch.gz
Description: application/gzip

diff --git a/contrib/citext/citext--1.1--1.2.sql b/contrib/citext/citext--1.1--1.2.sql
index 5d5e48d..074eec1 100644
--- a/contrib/citext/citext--1.1--1.2.sql
+++ b/contrib/citext/citext--1.1--1.2.sql
@@ -40,3 +40,29 @@ ALTER FUNCTION strpos(citext, citext) PARALLEL SAFE;
 ALTER FUNCTION replace(citext, citext, citext) PARALLEL SAFE;
 ALTER FUNCTION split_part(citext, citext, int) PARALLEL SAFE;
 ALTER FUNCTION translate(citext, citext, text) PARALLEL SAFE;
+
+UPDATE pg_proc SET proparallel = 's'
+WHERE proname = 'min'
+AND proargtypes = 'citext'::regtype::oid::text::oidvector
+AND pronamespace = current_schema()::regnamespace;
+
+UPDATE pg_proc SET proparallel = 's'
+WHERE proname = 'max'
+AND proargtypes = 'citext'::regtype::oid::text::oidvector
+AND pronamespace = current_schema()::regnamespace;
+
+UPDATE pg_aggregate SET aggcombinefn = 'citext_smaller'
+WHERE aggfnoid = (
+	SELECT oid FROM pg_proc
+	WHERE proname = 'min'
+	AND proargtypes = 'citext'::regtype::oid::text::oidvector
+	AND pronamespace = current_schema()::regnamespace
+);
+
+UPDATE pg_aggregate SET aggcombinefn = 'citext_larger'
+WHERE aggfnoid = (
+	SELECT oid FROM pg_proc
+	WHERE proname = 'max'
+	AND proargtypes = 'citext'::regtype::oid::text::oidvector
+	AND pronamespace = current_schema()::regnamespace
+);
diff --git a/contrib/citext/citext--1.2.sql b/contrib/citext/citext--1.2.sql
index 01fbb93..c2d0c0c 100644
--- a/contrib/citext/citext--1.2.sql
+++ b/contrib/citext/citext--1.2.sql
@@ -242,13 +242,17 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
 CREATE AGGREGATE min(citext)  (
     SFUNC = citext_smaller,
     STYPE = citext,
-    SORTOP = <
+    SORTOP = <,
+    PARALLEL = SAFE,
+    COMBINEFUNC = citext_smaller
 );
 
 CREATE AGGREGATE max(citext)  (
     SFUNC = citext_larger,
     STYPE = citext,
-    SORTOP = >
+    SORTOP = >,
+    PARALLEL = SAFE,
+    COMBINEFUNC = citext_larger
 );
 
 --
diff --git a/contrib/intagg/intagg--1.0--1.1.sql b/contrib/intagg/intagg--1.0--1.1.sql
index 9bdf355..ad69146 100644
--- a/contrib/intagg/intagg--1.0--1.1.sql
+++ b/contrib/intagg/intagg--1.0--1.1.sql
@@ -6,3 +6,8 @@
 ALTER FUNCTION int_agg_state(internal, int4) PARALLEL SAFE;
 ALTER FUNCTION int_agg_final_array(internal) PARALLEL SAFE;
 ALTER FUNCTION int_array_enum(int4[]) PARALLEL SAFE;
+
+UPDATE pg_proc SET proparallel = 's'
+WHERE proname = 'int_array_aggregate'
+AND proargtypes = 'int4'::regtype::oid::text::oidvector
+AND pronamespace = current_schema()::regnamespace;
diff --git a/contrib/intagg/intagg--1.1.sql b/contrib/intagg/intagg--1.1.sql
index 32b84e4..3796a2a 100644
--- a/contrib/intagg/intagg--1.1.sql
+++ b/contrib/intagg/intagg--1.1.sql
@@ -21,11 +21,11 @@ LANGUAGE INTERNAL;
 
 -- The aggregate function itself
 -- uses the above functions to create an array of integers from an aggregation.
-CREATE AGGREGATE int_array_aggregate (
-	BASETYPE = int4,
+CREATE AGGREGATE int_array_aggregate(int4) (
 	SFUNC = int_agg_state,
 	STYPE = internal,
-	FINALFUNC = int_agg_final_array
+	FINALFUNC = int_agg_final_array,
+	PARALLEL = SAFE
 );
 
 -- The enumeration function
diff --git a/contrib/tsearch2/tsearch2--1.0--1.1.sql b/contrib/tsearch2/tsearch2--1.0--1.1.sql
index e8d3518..b3687e8 100644
--- a/contrib/tsearch2/tsearch2--1.0--1.1.sql
+++ b/contrib/tsearch2/tsearch2--1.0--1.1.sql
@@ -82,3 +82,8 @@ ALTER FUNCTION rewrite_accum(tsquery, tsquery[]) PARALLEL SAFE;
 ALTER FUNCTION rewrite_finish(tsquery) PARALLEL SAFE;
 ALTER FUNCTION tsq_mcontains(tsquery, tsquery) PARALLEL SAFE;
 ALTER FUNCTION tsq_mcontained(tsquery, tsquery) PARALLEL SAFE;
+
+UPDATE pg_proc SET proparallel = 's'
+WHERE proname = 'rewrite'
+AND proargtypes = 'tsquery[]'::regtype::oid::text::oidvector
+AND pronamespace = current_schema()::regnamespace;
diff --git a/contrib/tsearch2/tsearch2--1.1.sql b/contrib/tsearch2/tsearch2--1.1.sql
index 3eca510..f65c6ac 100644
--- a/contrib/tsearch2/tsearch2--1.1.sql
+++ b/contrib/tsearch2/tsearch2--1.1.sql
@@ -587,11 +587,11 @@ CREATE FUNCTION rewrite_finish(tsquery)
       LANGUAGE C
       PARALLEL SAFE;
 
-CREATE AGGREGATE rewrite (
-      BASETYPE = tsquery[],
+CREATE AGGREGATE rewrite(tsquery[]) (
       SFUNC = rewrite_accum,
       STYPE = tsquery,
-      FINALFUNC = rewrite_finish
+      FINALFUNC = rewrite_finish,
+      PARALLEL = SAFE
 );
 
 CREATE FUNCTION tsq_mcontains(tsquery, tsquery)
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to