Skip to content

Commit ac04aa8

Browse files
committed
Don't enter parallel mode when holding interrupts.
Doing so caused the leader to hang in wait_event=ParallelFinish, which required an immediate shutdown to resolve. Back-patch to v12 (all supported versions). Francesco Degrassi Discussion: https://postgr.es/m/CAC-SaSzHUKT=vZJ8MPxYdC_URPfax+yoA1hKTcF4ROz_Q6z0_Q@mail.gmail.com
1 parent 933848d commit ac04aa8

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
342342
* we want to allow parallel inserts in general; updates and deletes have
343343
* additional problems especially around combo CIDs.)
344344
*
345+
* We don't try to use parallel mode unless interruptible. The leader
346+
* expects ProcessInterrupts() calls to reach HandleParallelMessages().
347+
* Even if we called HandleParallelMessages() another way, starting a
348+
* parallel worker is too delay-prone to be prudent when uncancellable.
349+
*
345350
* For now, we don't try to use parallel mode if we're running inside a
346351
* parallel worker. We might eventually be able to relax this
347352
* restriction, but for now it seems best not to have parallel workers
@@ -352,6 +357,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
352357
parse->commandType == CMD_SELECT &&
353358
!parse->hasModifyingCTE &&
354359
max_parallel_workers_per_gather > 0 &&
360+
INTERRUPTS_CAN_BE_PROCESSED() &&
355361
!IsParallelWorker())
356362
{
357363
/* all the cheap tests pass, so scan the query tree */

src/test/regress/expected/select_parallel.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,3 +1386,27 @@ reset debug_parallel_query;
13861386
drop function set_and_report_role();
13871387
drop function set_role_and_error(int);
13881388
drop role regress_parallel_worker;
1389+
-- don't freeze in ParallelFinish while holding an LWLock
1390+
BEGIN;
1391+
CREATE FUNCTION my_cmp (int4, int4)
1392+
RETURNS int LANGUAGE sql AS
1393+
$$
1394+
SELECT
1395+
CASE WHEN $1 < $2 THEN -1
1396+
WHEN $1 > $2 THEN 1
1397+
ELSE 0
1398+
END;
1399+
$$;
1400+
CREATE TABLE parallel_hang (i int4);
1401+
INSERT INTO parallel_hang
1402+
(SELECT * FROM generate_series(1, 400) gs);
1403+
CREATE OPERATOR CLASS int4_custom_ops FOR TYPE int4 USING btree AS
1404+
OPERATOR 1 < (int4, int4), OPERATOR 2 <= (int4, int4),
1405+
OPERATOR 3 = (int4, int4), OPERATOR 4 >= (int4, int4),
1406+
OPERATOR 5 > (int4, int4), FUNCTION 1 my_cmp(int4, int4);
1407+
CREATE UNIQUE INDEX parallel_hang_idx
1408+
ON parallel_hang
1409+
USING btree (i int4_custom_ops);
1410+
SET debug_parallel_query = on;
1411+
DELETE FROM parallel_hang WHERE 380 <= i AND i <= 420;
1412+
ROLLBACK;

src/test/regress/sql/select_parallel.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,34 @@ reset debug_parallel_query;
543543
drop function set_and_report_role();
544544
drop function set_role_and_error(int);
545545
drop role regress_parallel_worker;
546+
547+
-- don't freeze in ParallelFinish while holding an LWLock
548+
BEGIN;
549+
550+
CREATE FUNCTION my_cmp (int4, int4)
551+
RETURNS int LANGUAGE sql AS
552+
$$
553+
SELECT
554+
CASE WHEN $1 < $2 THEN -1
555+
WHEN $1 > $2 THEN 1
556+
ELSE 0
557+
END;
558+
$$;
559+
560+
CREATE TABLE parallel_hang (i int4);
561+
INSERT INTO parallel_hang
562+
(SELECT * FROM generate_series(1, 400) gs);
563+
564+
CREATE OPERATOR CLASS int4_custom_ops FOR TYPE int4 USING btree AS
565+
OPERATOR 1 < (int4, int4), OPERATOR 2 <= (int4, int4),
566+
OPERATOR 3 = (int4, int4), OPERATOR 4 >= (int4, int4),
567+
OPERATOR 5 > (int4, int4), FUNCTION 1 my_cmp(int4, int4);
568+
569+
CREATE UNIQUE INDEX parallel_hang_idx
570+
ON parallel_hang
571+
USING btree (i int4_custom_ops);
572+
573+
SET debug_parallel_query = on;
574+
DELETE FROM parallel_hang WHERE 380 <= i AND i <= 420;
575+
576+
ROLLBACK;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy