On Fri, 6 Jun 2025 at 01:47, Ayush Vatsa <ayushvatsa1...@gmail.com> wrote: > A small follow-up question - Gather merge won't gather and merge the > output from child in sorted order, but will always need an explicit Sort > node beneath it to do so. Correct?
Incorrect. The input node to the Gather Merge needs to be sorted by something, and the output of the Gather Merge will be sorted by the same thing. Gather Merge handles putting the tuples that were gathered by parallel workers back into the order they're meant to be in. The Gather Merge's input node could be anything that provides sorted output. Index Scan, Merge Join, Nested Loop, Group Aggregate, etc. Have a look at [1] David [1] https://github.com/postgres/postgres/blob/master/src/test/regress/expected/select_parallel.out#L713