Re: some aspects of our qsort might not be ideal - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: some aspects of our qsort might not be ideal
Date
Msg-id CAH2-Wz==W5vvXkUcRsM7Uo3tGOTBN_wqd1wbx3ivskUsVZJ2HQ@mail.gmail.com
Whole thread Raw
In response to Re: some aspects of our qsort might not be ideal  (Matthias van de Meent <boekewurm+postgres@gmail.com>)
Responses Re: some aspects of our qsort might not be ideal
List pgsql-hackers
On Thu, Jun 23, 2022 at 7:51 AM Matthias van de Meent
<boekewurm+postgres@gmail.com> wrote:
> I think that mostly has to do with reliability / stability of ORDER BY
> in combination with LIMIT and OFFSET, even though right now we cannot
> fully guarantee such stability due to unstable results from underlying
> plan nodes.

The current qsort isn't stable. While quicksort is never stable, our
particular implementation has fairly significant optimizations that
strongly rely on not using a stable sort. In particular, the B&M
optimizations for duplicate elements.

These optimizations make things like datum tuplesorts for
'SELECT(DISTINCT mycol) ...' style queries on low cardinality columns
extremely fast. We're not really sorting so much as bucketing. This is
based on Dijkstra's Dutch national flag problem.

-- 
Peter Geoghegan



pgsql-hackers by date:

Previous
From: Matthias van de Meent
Date:
Subject: Re: some aspects of our qsort might not be ideal
Next
From: Matthias van de Meent
Date:
Subject: Re: some aspects of our qsort might not be ideal