IMMUTABLE and PARALLEL SAFE function markings

From: Gajus Kuizinas <gajus(at)gajus(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: IMMUTABLE and PARALLEL SAFE function markings
Date: 2018-11-26 21:23:27
Message-ID: CA+6d-n4dOakgLu2gsTfk9uD2CC9ueNCg+z_mnXA2-=Qaod1Wuw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have defined a function "is_not_distinct" for the purpose of creating a
custom operator "===".

CREATE FUNCTION is_not_distinct(a anyelement, b anyelement)
returns boolean
language sql as $$
select a is not distinct from b;
$$
IMMUTABLE;

CREATE OPERATOR === (
LEFTARG = anyelement,
RIGHTARG = anyelement,
PROCEDURE = is_not_distinct,
NEGATOR = !==
);

I have observed that the resulting queries were executed without using
parallelisation.

I have learned by asking on Freenode that the reason my queries are not
using parallelisation is because I have not configured PARALLEL SAFE.

I find it counter-intuitive that a function with IMMUTABLE marking would
require an explicit PARALLEL SAFE. It would seem logical that in all cases
where a function is appropriately market as IMMUTABLE it would also
be PARALLEL SAFE.

I was wondering what is the reason IMMUTABLE functions are not by
default PARALLEL SAFE and if the default behaviour could be changed to make
IMMUTABLE functions PARALLEL SAFE?

Thank you,

Gajus

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2018-11-26 22:05:51 Re: csv format for psql
Previous Message Stephen Frost 2018-11-26 21:22:53 Re: pgsql: Integrate recovery.conf into postgresql.conf