Re: qsort, once again

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org>, "Jerry Sievers" <jerry(at)jerrysievers(dot)com>
Subject: Re: qsort, once again
Date: 2006-03-16 20:19:03
Message-ID: D425483C2C5C9F49B5B7A41F8944154757D67E@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have seen a lot of dumb "fixes" to sort routines.

In a commercial sort function I saw some time ago, the check for a
condition that causes qsort to go quadratic was removed. There was a
comment there that said the engineer "didn't see any improvement in
performance". Of course, the check was not there to improve performance
but to prevent disaster.

Obviously, he failed to check some very important data sets. If a sort
routine cannot handle (among other things):
1. Already sorted
2. Almost sorted
3. Reverse sorted
4. Organ pipe ( the inspiration for "Engineering a Sort Function" )
5. Small number of distinct values

Then it will cause problems in real-life use.

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Thursday, March 16, 2006 12:09 PM
> To: Dann Corbit
> Cc: Jonah H. Harris; pgsql-hackers(at)postgresql(dot)org; Jerry Sievers
> Subject: Re: [HACKERS] qsort, once again
>
> "Dann Corbit" <DCorbit(at)connx(dot)com> writes:
> > I sent him a copy
>
> Thanks. This is really interesting: the switch to insertion sort on
> perfect pivot is simply not there in Bentley & McIlroy's paper. So
> it was added later, and evidently not tested as carefully as it should
> have been. At this point I'm more than half tempted to take it out
> entirely.
>
> So we still have a problem of software archaeology: who added the
> insertion sort switch to the NetBSD version, and on what grounds?
>
> regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-03-16 20:21:52 Re: Separate BLCKSZ for data and logging
Previous Message Tom Lane 2006-03-16 20:09:10 Re: qsort, once again