From: Ron <rjpeace@earthlink.net>
To: Florian Weimer <fw@deneb.enyo.de>
To: pgsql-performance@postgresql.org
To: pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] qsort again
Date: Thu, 16 Feb 2006 08:38:45 -0500
Message-ID: <7.0.1.0.2.20060216082618.03ad7e48@earthlink.net> (raw)
In-Reply-To: <873bijsdvb.fsf@mid.deneb.enyo.de>
References: <43F38867.6010701@gpdnet.co.uk>
<19510.1140036968@sss.pgh.pa.us>
<19779.1140038874@sss.pgh.pa.us>
<43F39E53.1020009@gpdnet.co.uk>
<20781.1140046109@sss.pgh.pa.us>
<1140055972.31672.42.camel@localhost.localdomain>
<873bijsdvb.fsf@mid.deneb.enyo.de>
At 07:10 AM 2/16/2006, Florian Weimer wrote:
>* Neil Conway:
>
> > On Wed, 2006-02-15 at 18:28 -0500, Tom Lane wrote:
> >> It seems clear that our qsort.c is doing a pretty awful job of picking
> >> qsort pivots, while glibc is mostly managing not to make that mistake.
> >> I haven't looked at the glibc code yet to see what they are doing
> >> differently.
> >
> > glibc qsort is actually merge sort, so I'm not surprised it avoids this
> > problem.
>
>qsort also performs twice as many key comparisons as the theoretical
>minimum.
The theoretical minimum number of comparisons for a general purpose
comparison based sort is O(lgN!).
QuickSort uses 2NlnN ~= 1.38NlgN or ~1.38x the optimum without tuning
(see Knuth, Sedgewick, Corman, ... etc)
OTOH, QuickSort uses ~2x as many =moves= as the theoretical minimum
unless tuned, and moves are more expensive than compares in modern systems.
See my other posts for QuickSort tuning methods that attempt to
directly address both issues.
Ron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: rjpeace@earthlink.net, fw@deneb.enyo.de, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] qsort again
In-Reply-To: <7.0.1.0.2.20060216082618.03ad7e48@earthlink.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox