Re: qsort, once again - Mailing list pgsql-hackers

From Jonah H. Harris
Subject Re: qsort, once again
Date
Msg-id 36e682920603161232r15d26bf5ld9c16b0fe653528e@mail.gmail.com
Whole thread Raw
In response to Re: qsort, once again  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: qsort, once again
List pgsql-hackers
On 3/16/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
So we still have a problem of software archaeology: who added the
insertion sort switch to the NetBSD version, and on what grounds?


AFAICS, the insertion sort was added in BSD 4.4-lite and was inherited by NetBSD in CVS version 1.1.1.2.

The previous version in NetBSD (before 4.4-lite) also included an insertion sort with the comment:

/*
* Knuth, Vol. 3, page 116, Algorithm Q, step b, argues that a single pass
* of straight insertion sort after partitioning is complete is better than
* sorting each small partition as it is created. This isn't correct in this
* implementation because comparisons require at least one (and often two)
* function calls and are likely to be the dominating expense of the sort.
* Doing a final insertion sort does more comparisons than are necessary
* because it compares the "edges" and medians of the partitions which are
* known to be already sorted.
*
* This is also the reasoning behind selecting a small THRESH value (see
* Knuth, page 122, equation 26), since the quicksort algorithm does less
* comparisons than the insertion sort.
*/


--
Jonah H. Harris, Database Internals Architect
EnterpriseDB Corporation
732.331.1324

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Separate BLCKSZ for data and logging
Next
From: Simon Riggs
Date:
Subject: Re: Separate BLCKSZ for data and logging