bashtanov(at)imap(dot)cc writes:
> Please have a look at the two bottom nodes of the plan. Function scan
> produces 1000 rows, then they are sorted and turn into 3201 rows! How could
> this happen?
The discrepancy is easily explained because the sort is the righthand
child of a merge join. Merge join will rewind and rescan its right
child every time the left child produces duplicate keys, so that the
appropriate right-child rows get joined to all the similarly-keyed
rows from the left child. And you do have duplicate outputs coming
from that left child ...
IOW, it's just a measurement artifact arising from re-fetching the
same rows repeatedly. I think there's a warning about this in the
docs.
regards, tom lane