1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Minor optimizations based on ParallelContext having nworkers_launched.

Originally, we didn't have nworkers_launched, so code that used parallel
contexts had to be preprared for the possibility that not all of the
workers requested actually got launched.  But now we can count on knowing
the number of workers that were successfully launched, which can shave
off a few cycles and simplify some code slightly.

Amit Kapila, reviewed by Haribabu Kommi, per a suggestion from Peter
Geoghegan.
This commit is contained in:
Robert Haas
2016-03-04 12:59:10 -05:00
parent 546cd0d766
commit df4685fb0c
3 changed files with 12 additions and 16 deletions

View File

@ -153,7 +153,6 @@ ExecGather(GatherState *node)
if (gather->num_workers > 0 && IsInParallelMode())
{
ParallelContext *pcxt;
bool got_any_worker = false;
/* Initialize the workers required to execute Gather node. */
if (!node->pei)
@ -169,29 +168,26 @@ ExecGather(GatherState *node)
LaunchParallelWorkers(pcxt);
/* Set up tuple queue readers to read the results. */
if (pcxt->nworkers > 0)
if (pcxt->nworkers_launched > 0)
{
node->nreaders = 0;
node->reader =
palloc(pcxt->nworkers * sizeof(TupleQueueReader *));
palloc(pcxt->nworkers_launched * sizeof(TupleQueueReader *));
for (i = 0; i < pcxt->nworkers; ++i)
for (i = 0; i < pcxt->nworkers_launched; ++i)
{
if (pcxt->worker[i].bgwhandle == NULL)
continue;
shm_mq_set_handle(node->pei->tqueue[i],
pcxt->worker[i].bgwhandle);
node->reader[node->nreaders++] =
CreateTupleQueueReader(node->pei->tqueue[i],
fslot->tts_tupleDescriptor);
got_any_worker = true;
}
}
/* No workers? Then never mind. */
if (!got_any_worker)
else
{
/* No workers? Then never mind. */
ExecShutdownGatherWorkers(node);
}
}
/* Run plan locally if no workers or not single-copy. */