cannot start commands during a parallel operation

Justin Pryzby pryzby at telsasoft.com
Sat Aug 10 10:45:45 PDT 2024


On Fri, Aug 09, 2024 at 02:09:44PM -0700, Paul Ramsey wrote:
> Crazy… it’s just a short little C function. Why wouldn’t this happen with every/any extension function?
> 
> https://github.com/postgis/postgis/blob/master/postgis/lwgeom_ogc.c#L609-L623

It turns out this isn't limited to postgis, nor extensions, nor even
functions called by plpgsql.  I think it's an issue with the parallel
safety exceptions for CREATE AS + SELECT INTO.  This fails back to pg11,
probably due to pg commit e9baa5e9f (Allow DML commands that create
tables to use parallel query.).  I'll report it on their development
list at a later date.

CREATE FUNCTION fn(i int) RETURNS int PARALLEL SAFE LANGUAGE plpgsql AS $$ DECLARE res int; BEGIN SELECT a AS a INTO res FROM tab WHERE a=i; RETURN res; END $$;
CREATE TABLE tab AS SELECT generate_series(1,99)a;
SET parallel_tuple_cost=0; SET parallel_setup_cost=0; SET min_parallel_table_scan_size=0;
CREATE TABLE new AS SELECT fn(a) FROM tab;

\errverbose 
ERROR:  XX000: cannot start commands during a parallel operation
CONTEXT:  SQL statement "SELECT a AS a          FROM tab WHERE a=i"
PL/pgSQL function fn(integer) line 1 at SQL statement
LOCATION:  CommandCounterIncrement, xact.c:1094


More information about the postgis-devel mailing list