Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7de4a1b

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

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/backend/access/nbtree/nbtsort.c

+25-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#define PARALLEL_KEY_BTREE_SHARED UINT64CONST(0xA000000000000001)
8787
#define PARALLEL_KEY_TUPLESORT UINT64CONST(0xA000000000000002)
8888
#define PARALLEL_KEY_TUPLESORT_SPOOL2 UINT64CONST(0xA000000000000003)
89+
#define PARALLEL_KEY_QUERY_TEXT UINT64CONST(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
bool leaderparticipates = true;
1199+
char *sharedquery;
1200+
int querylen;
11981201

11991202
#ifdef DISABLE_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 third shared workspace -- PARALLEL_KEY_TUPLESORT_SPOOL2
1239+
* another shared 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)