On 14 April 2012 14:34, Peter Geoghegan <pe...@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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers