86
86
#define PARALLEL_KEY_BTREE_SHARED UINT64CONST(0xA000000000000001)
87
87
#define PARALLEL_KEY_TUPLESORT UINT64CONST(0xA000000000000002)
88
88
#define PARALLEL_KEY_TUPLESORT_SPOOL2 UINT64CONST(0xA000000000000003)
89
+ #define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xA000000000000004)
89
90
90
91
/*
91
92
* DISABLE_LEADER_PARTICIPATION disables the leader's participation in
@@ -1195,6 +1196,8 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
1195
1196
BTSpool * btspool = buildstate -> spool ;
1196
1197
BTLeader * btleader = (BTLeader * ) palloc0 (sizeof (BTLeader ));
1197
1198
bool leaderparticipates = true;
1199
+ char * sharedquery ;
1200
+ int querylen ;
1198
1201
1199
1202
#ifdef DISABLE_LEADER_PARTICIPATION
1200
1203
leaderparticipates = false;
@@ -1223,9 +1226,8 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
1223
1226
snapshot = RegisterSnapshot (GetTransactionSnapshot ());
1224
1227
1225
1228
/*
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
1229
1231
*/
1230
1232
estbtshared = _bt_parallel_estimate_shared (snapshot );
1231
1233
shm_toc_estimate_chunk (& pcxt -> estimator , estbtshared );
@@ -1234,7 +1236,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
1234
1236
1235
1237
/*
1236
1238
* 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
1238
1240
*/
1239
1241
if (!btspool -> isunique )
1240
1242
shm_toc_estimate_keys (& pcxt -> estimator , 2 );
@@ -1244,6 +1246,11 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
1244
1246
shm_toc_estimate_keys (& pcxt -> estimator , 3 );
1245
1247
}
1246
1248
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
+
1247
1254
/* Everyone's had a chance to ask for space, so now create the DSM */
1248
1255
InitializeParallelDSM (pcxt );
1249
1256
@@ -1293,6 +1300,11 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
1293
1300
shm_toc_insert (pcxt -> toc , PARALLEL_KEY_TUPLESORT_SPOOL2 , sharedsort2 );
1294
1301
}
1295
1302
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
+
1296
1308
/* Launch workers, saving status for leader/caller */
1297
1309
LaunchParallelWorkers (pcxt );
1298
1310
btleader -> pcxt = pcxt ;
@@ -1459,6 +1471,7 @@ _bt_leader_participate_as_worker(BTBuildState *buildstate)
1459
1471
void
1460
1472
_bt_parallel_build_main (dsm_segment * seg , shm_toc * toc )
1461
1473
{
1474
+ char * sharedquery ;
1462
1475
BTSpool * btspool ;
1463
1476
BTSpool * btspool2 ;
1464
1477
BTShared * btshared ;
@@ -1475,7 +1488,14 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
1475
1488
ResetUsage ();
1476
1489
#endif /* BTREE_BUILD_STATS */
1477
1490
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 */
1479
1499
btshared = shm_toc_lookup (toc , PARALLEL_KEY_BTREE_SHARED , false);
1480
1500
1481
1501
/* Open relations using lock modes known to be obtained by index.c */
0 commit comments