Fix parallel sort, broken by the balanced merge patch.
authorHeikki Linnakangas <[email protected]>
Mon, 18 Oct 2021 17:42:10 +0000 (20:42 +0300)
committerHeikki Linnakangas <[email protected]>
Mon, 18 Oct 2021 17:42:10 +0000 (20:42 +0300)
The code for initializing the tapes on each merge iteration was skipped
in a parallel worker. I put the !WORKER(state) check in wrong place while
rebasing the patch.

That caused failures in the index build in 'multiple-row-versions'
isolation test, in multiple buildfarm members. On my laptop it was easier
to reproduce by building an index on a larger table, so that you got a
parallel sort more reliably.

src/backend/utils/sort/tuplesort.c

index 0c5c574cbd3d1e4ef6379befc3d28c4c89151cd7..9e93908c6576d8698a614e46b6a0a880580093a1 100644 (file)
@@ -2923,7 +2923,7 @@ mergeruns(Tuplesortstate *state)
                 * Rewind all the output tapes, and make them inputs for the next
                 * pass.
                 */
-               if (state->nInputRuns == 0 && !WORKER(state))
+               if (state->nInputRuns == 0)
                {
                        int64           input_buffer_size;
 
@@ -2975,7 +2975,8 @@ mergeruns(Tuplesortstate *state)
                         * sorted tape, we can stop at this point and do the final merge
                         * on-the-fly.
                         */
-                       if (!state->randomAccess && state->nInputRuns <= state->nInputTapes)
+                       if (!state->randomAccess && state->nInputRuns <= state->nInputTapes
+                               && !WORKER(state))
                        {
                                /* Tell logtape.c we won't be writing anymore */
                                LogicalTapeSetForgetFreeSpace(state->tapeset);