Re: PoC: Partial sort

Alexander Korotkov <aekorotkov@gmail.com>

From: Alexander Korotkov <aekorotkov@gmail.com>
To: Marti Raudsepp <marti@juffo.org>
Cc: Robert Haas <robertmhaas@gmail.com>, Andreas Karlsson <andreas@proxel.se>, David Rowley <dgrowleyml@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Andres Freund <andres@2ndquadrant.com>, Martijn van Oosterhout <kleptog@svana.org>
Date: 2014-02-20T07:37:30Z
Lists: pgsql-hackers
On Thu, Feb 13, 2014 at 1:54 AM, Marti Raudsepp <marti@juffo.org> wrote:

> I think the 1st patch now has a bug in initial_cost_mergejoin; you
> still pass the "presorted_keys" argument to cost_sort, making it
> calculate a partial sort cost, but generated plans never use partial
> sort. I think 0 should be passed instead. Patch attached, needs to be
> applied on top of partial-sort-basic-1 and then reverse-applied on
> partial-sort-merge-1.
>

It doesn't look so for me. Merge join doesn't find partial sort especially.
But if path with some presorted pathkeys will be accidentally selected then
partial sort will be used. See create_mergejoin_plan function. So, I think
this cost_sort call is relevant to create_mergejoin_plan. If we don't want
partial sort to be used in such rare cases then we should revert it from
both places. However, I doubt that it does any overhead, so we can leave it
as is.

------
With best regards,
Alexander Korotkov.

Commits

  1. Implement Incremental Sort

  2. Improve memory management for external sorts.