Re: can't get rid of unnesesary SORT step in explain plan for hash join - Mailing list pgsql-sql

From Tom Lane
Subject Re: can't get rid of unnesesary SORT step in explain plan for hash join
Date
Msg-id 8987.989849829@sss.pgh.pa.us
Whole thread Raw
In response to can't get rid of unnesesary SORT step in explain plan for hash join  (Alexey Nalbat <alexey@price.ru>)
List pgsql-sql
Alexey Nalbat <alexey@price.ru> writes:
> While executing this query postgres at first creates hash on table
> "resellers", then get from index "products_mcr" for rows with
> "m_id=123" already ordered (!!!)  pairs "c_id,r_id", for each that
> pair it checks join condition using hash. If postgers behaves like
> this then the result of this hash join is already sorted, and extra
> "Sort" is not needed.

No, because the hash step might choose to divide its processing into
multiple "batches", thereby destroying the sort order.  The outer path's
ordering is preserved only in relatively small test cases...
        regards, tom lane


pgsql-sql by date:

Previous
From: John Scott
Date:
Subject: unwritable /tmp causes initdb to crash
Next
From: Srikanth Rao
Date:
Subject: Counting rows in a table