BUG #18314: PARALLEL UNSAFE function does not prevent parallel index build - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18314: PARALLEL UNSAFE function does not prevent parallel index build
Date
Msg-id 18314-5f44050ce33a5492@postgresql.org
Whole thread Raw
Responses Re: BUG #18314: PARALLEL UNSAFE function does not prevent parallel index build  (Tender Wang <tndrwang@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18314
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 16.1
Operating system:   Ubuntu 22.04
Description:

When planner chooses to perform parallel index build, it doesn't
check whether functions used in an index expression or predicate are
parallel-safe. For example:
CREATE FUNCTION f() RETURNS int IMMUTABLE PARALLEL UNSAFE
AS $$
BEGIN    
    RETURN 0;
EXCEPTION WHEN OTHERS THEN
    RETURN 1;
END$$ LANGUAGE plpgsql;

CREATE TABLE t(i int);
INSERT INTO t SELECT g FROM generate_series(1, 300000) g;
CREATE INDEX ON t((i + f()));

results in:
ERROR:  cannot start subtransactions during a parallel operation
CONTEXT:  PL/pgSQL function f() line 2 during statement block entry
parallel worker

Although with 200000 records, the index created with no error.

Reproduced on REL_12_STABLE .. master.


pgsql-bugs by date:

Previous
From: Tender Wang
Date:
Subject: Re: BUG #18310: Some SQL commands fail to process duplicate objects with error: tuple already updated by self
Next
From: David Rowley
Date:
Subject: Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key