Hello
>>
>> I'm not understanding why it is sorting on disk if it would fit within
>> a work_mem segment - by a fairly wide margin. Is there something else
>> I can do to get that sort to happen in memory?
>>
Planner working with estimations. So there is some probability so
planner expected a larger result set and used a external sort.
Probably quick sort takes more memory too. Your statistic are probably
out of range - system expecting 0.5 mil rec and get 2 mil rec.
Regards
Pavel