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

Commit7de4a1b

Browse files
committed
Call pgstat_report_activity() in parallel CREATE INDEX workers.
Also set debug_query_string.Oversight in commit9da0cc3Peter Geoghegan, per a report by Phil Florent.Discussion:https://postgr.es/m/CAH2-Wzmf-34hD4n40uTuE-ZY9P5c%2BmvhFbCdQfN%3DKrKiVm3j3A%40mail.gmail.com
1 parentc35b472 commit7de4a1b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#definePARALLEL_KEY_BTREE_SHAREDUINT64CONST(0xA000000000000001)
8787
#definePARALLEL_KEY_TUPLESORTUINT64CONST(0xA000000000000002)
8888
#definePARALLEL_KEY_TUPLESORT_SPOOL2UINT64CONST(0xA000000000000003)
89+
#definePARALLEL_KEY_QUERY_TEXTUINT64CONST(0xA000000000000004)
8990

9091
/*
9192
* DISABLE_LEADER_PARTICIPATION disables the leader's participation in
@@ -1195,6 +1196,8 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
11951196
BTSpool*btspool=buildstate->spool;
11961197
BTLeader*btleader= (BTLeader*)palloc0(sizeof(BTLeader));
11971198
boolleaderparticipates= true;
1199+
char*sharedquery;
1200+
intquerylen;
11981201

11991202
#ifdefDISABLE_LEADER_PARTICIPATION
12001203
leaderparticipates= false;
@@ -1223,9 +1226,8 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
12231226
snapshot=RegisterSnapshot(GetTransactionSnapshot());
12241227

12251228
/*
1226-
* Estimate size for at least two keys -- our own
1227-
* PARALLEL_KEY_BTREE_SHARED workspace, and PARALLEL_KEY_TUPLESORT
1228-
* tuplesort workspace
1229+
* Estimate size for our own PARALLEL_KEY_BTREE_SHARED workspace, and
1230+
* PARALLEL_KEY_TUPLESORT tuplesort workspace
12291231
*/
12301232
estbtshared=_bt_parallel_estimate_shared(snapshot);
12311233
shm_toc_estimate_chunk(&pcxt->estimator,estbtshared);
@@ -1234,7 +1236,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
12341236

12351237
/*
12361238
* Unique case requires a second spool, and so we may have to account for
1237-
*a thirdshared workspace -- PARALLEL_KEY_TUPLESORT_SPOOL2
1239+
*anothershared workspace for that -- PARALLEL_KEY_TUPLESORT_SPOOL2
12381240
*/
12391241
if (!btspool->isunique)
12401242
shm_toc_estimate_keys(&pcxt->estimator,2);
@@ -1244,6 +1246,11 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
12441246
shm_toc_estimate_keys(&pcxt->estimator,3);
12451247
}
12461248

1249+
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
1250+
querylen=strlen(debug_query_string);
1251+
shm_toc_estimate_chunk(&pcxt->estimator,querylen+1);
1252+
shm_toc_estimate_keys(&pcxt->estimator,1);
1253+
12471254
/* Everyone's had a chance to ask for space, so now create the DSM */
12481255
InitializeParallelDSM(pcxt);
12491256

@@ -1293,6 +1300,11 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
12931300
shm_toc_insert(pcxt->toc,PARALLEL_KEY_TUPLESORT_SPOOL2,sharedsort2);
12941301
}
12951302

1303+
/* Store query string for workers */
1304+
sharedquery= (char*)shm_toc_allocate(pcxt->toc,querylen+1);
1305+
memcpy(sharedquery,debug_query_string,querylen+1);
1306+
shm_toc_insert(pcxt->toc,PARALLEL_KEY_QUERY_TEXT,sharedquery);
1307+
12961308
/* Launch workers, saving status for leader/caller */
12971309
LaunchParallelWorkers(pcxt);
12981310
btleader->pcxt=pcxt;
@@ -1459,6 +1471,7 @@ _bt_leader_participate_as_worker(BTBuildState *buildstate)
14591471
void
14601472
_bt_parallel_build_main(dsm_segment*seg,shm_toc*toc)
14611473
{
1474+
char*sharedquery;
14621475
BTSpool*btspool;
14631476
BTSpool*btspool2;
14641477
BTShared*btshared;
@@ -1475,7 +1488,14 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
14751488
ResetUsage();
14761489
#endif/* BTREE_BUILD_STATS */
14771490

1478-
/* Look up shared state */
1491+
/* Set debug_query_string for individual workers first */
1492+
sharedquery=shm_toc_lookup(toc,PARALLEL_KEY_QUERY_TEXT, false);
1493+
debug_query_string=sharedquery;
1494+
1495+
/* Report the query string from leader */
1496+
pgstat_report_activity(STATE_RUNNING,debug_query_string);
1497+
1498+
/* Look up nbtree shared state */
14791499
btshared=shm_toc_lookup(toc,PARALLEL_KEY_BTREE_SHARED, false);
14801500

14811501
/* Open relations using lock modes known to be obtained by index.c */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp