Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2370582

Browse files
committed
Don't enter parallel mode when holding interrupts.
Doing so caused the leader to hang in wait_event=ParallelFinish, whichrequired an immediate shutdown to resolve. Back-patch to v12 (allsupported versions).Francesco DegrassiDiscussion:https://postgr.es/m/CAC-SaSzHUKT=vZJ8MPxYdC_URPfax+yoA1hKTcF4ROz_Q6z0_Q@mail.gmail.com
1 parent7db9bfc commit2370582

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
@@ -340,6 +340,11 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
340340
* we want to allow parallel inserts in general; updates and deletes have
341341
* additional problems especially around combo CIDs.)
342342
*
343+
* We don't try to use parallel mode unless interruptible. The leader
344+
* expects ProcessInterrupts() calls to reach HandleParallelMessages().
345+
* Even if we called HandleParallelMessages() another way, starting a
346+
* parallel worker is too delay-prone to be prudent when uncancellable.
347+
*
343348
* For now, we don't try to use parallel mode if we're running inside a
344349
* parallel worker. We might eventually be able to relax this
345350
* restriction, but for now it seems best not to have parallel workers
@@ -350,6 +355,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
350355
parse->commandType==CMD_SELECT&&
351356
!parse->hasModifyingCTE&&
352357
max_parallel_workers_per_gather>0&&
358+
INTERRUPTS_CAN_BE_PROCESSED()&&
353359
!IsParallelWorker())
354360
{
355361
/* 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
@@ -1327,3 +1327,27 @@ reset debug_parallel_query;
13271327
drop function set_and_report_role();
13281328
drop function set_role_and_error(int);
13291329
drop role regress_parallel_worker;
1330+
-- don't freeze in ParallelFinish while holding an LWLock
1331+
BEGIN;
1332+
CREATE FUNCTION my_cmp (int4, int4)
1333+
RETURNS int LANGUAGE sql AS
1334+
$$
1335+
SELECT
1336+
CASE WHEN $1 < $2 THEN -1
1337+
WHEN $1 > $2 THEN 1
1338+
ELSE 0
1339+
END;
1340+
$$;
1341+
CREATE TABLE parallel_hang (i int4);
1342+
INSERT INTO parallel_hang
1343+
(SELECT * FROM generate_series(1, 400) gs);
1344+
CREATE OPERATOR CLASS int4_custom_ops FOR TYPE int4 USING btree AS
1345+
OPERATOR 1 < (int4, int4), OPERATOR 2 <= (int4, int4),
1346+
OPERATOR 3 = (int4, int4), OPERATOR 4 >= (int4, int4),
1347+
OPERATOR 5 > (int4, int4), FUNCTION 1 my_cmp(int4, int4);
1348+
CREATE UNIQUE INDEX parallel_hang_idx
1349+
ON parallel_hang
1350+
USING btree (i int4_custom_ops);
1351+
SET debug_parallel_query = on;
1352+
DELETE FROM parallel_hang WHERE 380 <= i AND i <= 420;
1353+
ROLLBACK;

‎src/test/regress/sql/select_parallel.sql‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,34 @@ reset debug_parallel_query;
519519
dropfunction set_and_report_role();
520520
dropfunction set_role_and_error(int);
521521
drop role regress_parallel_worker;
522+
523+
-- don't freeze in ParallelFinish while holding an LWLock
524+
BEGIN;
525+
526+
CREATEFUNCTIONmy_cmp (int4, int4)
527+
RETURNSint LANGUAGE sqlAS
528+
$$
529+
SELECT
530+
CASE WHEN $1< $2 THEN-1
531+
WHEN $1> $2 THEN1
532+
ELSE0
533+
END;
534+
$$;
535+
536+
CREATETABLEparallel_hang (i int4);
537+
INSERT INTO parallel_hang
538+
(SELECT*FROM generate_series(1,400) gs);
539+
540+
CREATEOPERATOR CLASSint4_custom_ops FOR TYPE int4 USING btreeAS
541+
OPERATOR1< (int4, int4), OPERATOR2<= (int4, int4),
542+
OPERATOR3= (int4, int4), OPERATOR4>= (int4, int4),
543+
OPERATOR5> (int4, int4), FUNCTION1 my_cmp(int4, int4);
544+
545+
CREATEUNIQUE INDEXparallel_hang_idx
546+
ON parallel_hang
547+
USING btree (i int4_custom_ops);
548+
549+
SET debug_parallel_query=on;
550+
DELETEFROM parallel_hangWHERE380<= iAND i<=420;
551+
552+
ROLLBACK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp