Alexey Nalbat <alexey@price.ru> writes:
> So, my question is: how can I get rid of this unnesesary "Sort" step
> in the execution plan for hash join?
You can't, because it's not unnecessary. Hash join doesn't promise
to produce its outputs in any particular order. But the Unique
filter needs to see its inputs in order by the fields being made
unique.
regards, tom lane