Allow parallel plan for referential integrity checks? - Mailing list pgsql-hackers

From Frédéric Yhuel
Subject Allow parallel plan for referential integrity checks?
Date
Msg-id 0d21e3b4-dcde-290c-875e-6ed5013e8e52@dalibo.com
Whole thread Raw
Responses Re: Allow parallel plan for referential integrity checks?
Re: Allow parallel plan for referential integrity checks?
List pgsql-hackers
Hello,

I noticed that referential integrity checks aren't currently 
parallelized. Is it on purpose?

 From the documentation [1], the planner will not generate a parallel 
plan for a given query if any of the following are true:

1) The system is running in single-user mode.
2) max_parallel_workers_per_gather = 0.
3) The query writes any data or locks any database rows.
4) The query might be suspended during execution (cursor or  PL/pgSQL loop).
5) The query uses any function marked PARALLEL UNSAFE.
6) The query is running inside of another query that is already parallel.

 From my understanding of the code, it seems to me that the fourth 
condition is not always accurately detected. In particular, the query 
triggered by a foreign key addition (a Left Excluding JOIN between the 
two tables) isn't parallelized, because the flag CURSOR_OPT_PARALLEL_OK 
hasn't been set at some point. I couldn't find any reason why not, but 
maybe I missed something.

Attached is a (naive) patch that aims to fix the case of a FK addition, 
but the handling of the flag CURSOR_OPT_PARALLEL_OK, generally speaking, 
looks rather hackish.

Best regards,
Frédéric

[1] 
https://www.postgresql.org/docs/current/when-can-parallel-query-be-used.html
Attachment

pgsql-hackers by date:

Previous
From: Yugo NAGATA
Date:
Subject: Re: Fix CheckIndexCompatible comment
Next
From: Julien Rouhaud
Date:
Subject: Re: Database-level collation version tracking