aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2020-10-31 08:43:28 -0700
committerNoah Misch <noah@leadboat.com>2020-10-31 08:44:13 -0700
commit741b84e9f74726fbc97f63ddb46ab5675de98bdf (patch)
treeffab30e3674c35dc153f29c552515527ec2d587f /src
parent25b587f03a8372786ec06fbd033fdf49750be0e5 (diff)
downloadpostgresql-741b84e9f74726fbc97f63ddb46ab5675de98bdf.tar.gz
postgresql-741b84e9f74726fbc97f63ddb46ab5675de98bdf.zip
Reproduce debug_query_string==NULL on parallel workers.
Certain background workers initiate parallel queries while debug_query_string==NULL, at which point they attempted strlen(NULL) and died to SIGSEGV. Older debug_query_string observers allow NULL, so do likewise in these newer ones. Back-patch to v11, where commit 7de4a1bcc56f494acbd0d6e70781df877dc8ecb5 introduced the first of these. Discussion: https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/nbtree/nbtsort.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 1aa2363f1a5..286d2cc93f1 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -1341,7 +1341,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
BTLeader *btleader = (BTLeader *) palloc0(sizeof(BTLeader));
BufferUsage *bufferusage;
bool leaderparticipates = true;
- char *sharedquery;
int querylen;
#ifdef DISABLE_LEADER_PARTICIPATION
@@ -1404,9 +1403,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
shm_toc_estimate_keys(&pcxt->estimator, 1);
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
- querylen = strlen(debug_query_string);
- shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
- shm_toc_estimate_keys(&pcxt->estimator, 1);
+ if (debug_query_string)
+ {
+ querylen = strlen(debug_query_string);
+ shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
+ shm_toc_estimate_keys(&pcxt->estimator, 1);
+ }
+ else
+ querylen = 0; /* keep compiler quiet */
/* Everyone's had a chance to ask for space, so now create the DSM */
InitializeParallelDSM(pcxt);
@@ -1470,9 +1474,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
}
/* Store query string for workers */
- sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
- memcpy(sharedquery, debug_query_string, querylen + 1);
- shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
+ if (debug_query_string)
+ {
+ char *sharedquery;
+
+ sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
+ memcpy(sharedquery, debug_query_string, querylen + 1);
+ shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
+ }
/* Allocate space for each worker's BufferUsage; no need to initialize */
bufferusage = shm_toc_allocate(pcxt->toc,
@@ -1669,7 +1678,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
#endif /* BTREE_BUILD_STATS */
/* Set debug_query_string for individual workers first */
- sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, false);
+ sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
debug_query_string = sharedquery;
/* Report the query string from leader */