Commit 05d0f13f authored by Tom Lane's avatar Tom Lane

Skip setting up shared instrumentation for Hash node if not needed.

We don't need to set up the shared space for hash join instrumentation data
if instrumentation hasn't been requested.  Let's follow the example of the
similar Sort node code and save a few cycles by skipping that when we can.

This reverts commit d59ff4ab and instead allows us to use the safer choice
of passing noError = false to shm_toc_lookup in ExecHashInitializeWorker,
since if we reach that call there should be a TOC entry to be found.

Thomas Munro

Discussion: https://postgr.es/m/E1ehkoZ-0005uW-43%40gemulon.postgresql.org
parent ad14919a
...@@ -2549,6 +2549,10 @@ ExecHashEstimate(HashState *node, ParallelContext *pcxt) ...@@ -2549,6 +2549,10 @@ ExecHashEstimate(HashState *node, ParallelContext *pcxt)
{ {
size_t size; size_t size;
/* don't need this if not instrumenting or no workers */
if (!node->ps.instrument || pcxt->nworkers == 0)
return;
size = mul_size(pcxt->nworkers, sizeof(HashInstrumentation)); size = mul_size(pcxt->nworkers, sizeof(HashInstrumentation));
size = add_size(size, offsetof(SharedHashInfo, hinstrument)); size = add_size(size, offsetof(SharedHashInfo, hinstrument));
shm_toc_estimate_chunk(&pcxt->estimator, size); shm_toc_estimate_chunk(&pcxt->estimator, size);
...@@ -2564,6 +2568,10 @@ ExecHashInitializeDSM(HashState *node, ParallelContext *pcxt) ...@@ -2564,6 +2568,10 @@ ExecHashInitializeDSM(HashState *node, ParallelContext *pcxt)
{ {
size_t size; size_t size;
/* don't need this if not instrumenting or no workers */
if (!node->ps.instrument || pcxt->nworkers == 0)
return;
size = offsetof(SharedHashInfo, hinstrument) + size = offsetof(SharedHashInfo, hinstrument) +
pcxt->nworkers * sizeof(HashInstrumentation); pcxt->nworkers * sizeof(HashInstrumentation);
node->shared_info = (SharedHashInfo *) shm_toc_allocate(pcxt->toc, size); node->shared_info = (SharedHashInfo *) shm_toc_allocate(pcxt->toc, size);
...@@ -2582,13 +2590,13 @@ ExecHashInitializeWorker(HashState *node, ParallelWorkerContext *pwcxt) ...@@ -2582,13 +2590,13 @@ ExecHashInitializeWorker(HashState *node, ParallelWorkerContext *pwcxt)
{ {
SharedHashInfo *shared_info; SharedHashInfo *shared_info;
/* might not be there ... */ /* don't need this if not instrumenting */
if (!node->ps.instrument)
return;
shared_info = (SharedHashInfo *) shared_info = (SharedHashInfo *)
shm_toc_lookup(pwcxt->toc, node->ps.plan->plan_node_id, true); shm_toc_lookup(pwcxt->toc, node->ps.plan->plan_node_id, false);
if (shared_info)
node->hinstrument = &shared_info->hinstrument[ParallelWorkerNumber]; node->hinstrument = &shared_info->hinstrument[ParallelWorkerNumber];
else
node->hinstrument = NULL;
} }
/* /*
...@@ -2614,6 +2622,9 @@ ExecHashRetrieveInstrumentation(HashState *node) ...@@ -2614,6 +2622,9 @@ ExecHashRetrieveInstrumentation(HashState *node)
SharedHashInfo *shared_info = node->shared_info; SharedHashInfo *shared_info = node->shared_info;
size_t size; size_t size;
if (shared_info == NULL)
return;
/* Replace node->shared_info with a copy in backend-local memory. */ /* Replace node->shared_info with a copy in backend-local memory. */
size = offsetof(SharedHashInfo, hinstrument) + size = offsetof(SharedHashInfo, hinstrument) +
shared_info->num_workers * sizeof(HashInstrumentation); shared_info->num_workers * sizeof(HashInstrumentation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment