Re: qsort again (was Re: [PERFORM] Strange Create Index

From: Mark Lewis <mark(dot)lewis(at)mir3(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>, Markus Schaber <schabi(at)logix-tt(dot)com>, pgsql-performance(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: qsort again (was Re: [PERFORM] Strange Create Index
Date: 2006-02-16 22:17:36
Message-ID: 1140128256.9076.254.camel@archimedes
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

On Thu, 2006-02-16 at 12:15 -0500, Tom Lane wrote:
> Once or twice we've kicked around the idea of having some
> datatype-specific sorting code paths alongside the general-purpose one,
> but I can't honestly see this as being workable from a code maintenance
> standpoint.
>
> regards, tom lane

It seems that instead of maintaining a different sorting code path for
each data type, you could get away with one generic path and one
(hopefully faster) path if you allowed data types to optionally support
a 'sortKey' interface by providing a function f which maps inputs to 32-
bit int outputs, such that the following two properties hold:

f(a)>=f(b) iff a>=b
if a==b then f(a)==f(b)

So if a data type supports the sortKey interface you could perform the
sort on f(value) and only refer back to the actual element comparison
functions when two sortKeys have the same value.

Data types which could probably provide a useful function for f would be
int2, int4, oid, and possibly int8 and text (at least for SQL_ASCII).

Depending on the overhead, you might not even need to maintain 2
independent search code paths, since you could always use f(x)=0 as the
default sortKey function which would degenerate to the exact same sort
behavior in use today.

-- Mark Lewis

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Markus Schaber 2006-02-16 22:33:48 Re: qsort again (was Re: [PERFORM] Strange Create Index
Previous Message Bruce Momjian 2006-02-16 22:14:09 In Japan with Josh Berkus

Browse pgsql-performance by date

  From Date Subject
Next Message Markus Schaber 2006-02-16 22:33:48 Re: qsort again (was Re: [PERFORM] Strange Create Index
Previous Message Adnan DURSUN 2006-02-16 22:14:56 Re: Why does not perform index combination