Re: Memory usage during sorting - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: Memory usage during sorting
Date
Msg-id CAEYLb_XMuYTYy1huzJ3A1u31AJ5eN5Ro9ySP804M7j_N4bWQeA@mail.gmail.com
Whole thread Raw
In response to Re: Memory usage during sorting  (Peter Geoghegan <peter@2ndquadrant.com>)
Responses Re: Memory usage during sorting  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
On 14 April 2012 14:34, Peter Geoghegan <peter@2ndquadrant.com> wrote:
> FWIW, I started playing with adding timsort to Postgres last night:
>
> https://github.com/Peter2ndQuadrant/postgres/tree/timsort

I've fixed this feature-branch so that every qsort_arg call site
(including the tuplesort specialisations thereof) call timsort_arg
instead. All but 4 regression tests pass, but they don't really count
as failures, since they're down to an assumption in the tests that the
order certain tuples appear should be the same as our current
quicksort implementation returns them, even though, in these
problematic cases, that is partially dictated by implementation - our
quicksort isn't stable, but timsort is. I think that the original
tests are faulty, but I understand that they're only expected to
provide smoke testing.

I did have to fix one bug in the implementation that I found, which
was an assumption that comparators would only return one of {-1, 0,
1}. The C standard requires only that they return negative, zero or
positive values, as required. I also polished the code a bit, and
added more comments.

I haven't actually quantified the benefits yet, and have no numbers to
show just yet, but I suspect it will prove to be a fairly compelling
win in certain situations.

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services


pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: 9.3 Pre-proposal: Range Merge Join
Next
From: Simon Riggs
Date:
Subject: Re: 9.3 Pre-proposal: Range Merge Join