]> granicus.if.org Git - postgresql/commitdiff
Ensure gatherstate->nextreader is properly initialized.
authorRobert Haas <rhaas@postgresql.org>
Mon, 5 Dec 2016 20:54:28 +0000 (15:54 -0500)
committerRobert Haas <rhaas@postgresql.org>
Mon, 5 Dec 2016 20:54:28 +0000 (15:54 -0500)
The previously code worked OK as long as a Gather node was never
rescanned, or if it was rescanned, as long as it got at least as
many workers on rescan as it had originally.  But if the number
of workers ever decreased on a rescan, then it could crash.

Andreas Seltenreich

src/backend/executor/nodeGather.c

index 880ca623974699ebf9ddb4777da0852dead18456..2bdf22318268e7d3f5212736db76757164da4ad4 100644 (file)
@@ -173,6 +173,7 @@ ExecGather(GatherState *node)
                        if (pcxt->nworkers_launched > 0)
                        {
                                node->nreaders = 0;
+                               node->nextreader = 0;
                                node->reader =
                                        palloc(pcxt->nworkers_launched * sizeof(TupleQueueReader *));
 
@@ -335,6 +336,7 @@ gather_readnext(GatherState *gatherstate)
                CHECK_FOR_INTERRUPTS();
 
                /* Attempt to read a tuple, but don't block if none is available. */
+               Assert(gatherstate->nextreader < gatherstate->nreaders);
                reader = gatherstate->reader[gatherstate->nextreader];
                tup = TupleQueueReaderNext(reader, true, &readerdone);