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

Поиск
Список
Период
Сортировка
От Mark Lewis
Тема Re: qsort again (was Re: [PERFORM] Strange Create Index
Дата
Msg-id 1140128256.9076.254.camel@archimedes
обсуждение исходный текст
Ответ на Re: qsort again (was Re: [PERFORM] Strange Create Index  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: qsort again (was Re: [PERFORM] Strange Create Index  (Markus Schaber <schabi@logix-tt.com>)
Re: qsort again (was Re: [PERFORM] Strange Create Index  (Martijn van Oosterhout <kleptog@svana.org>)
Re: qsort again (was Re: [PERFORM] Strange Create Index  (Scott Lamb <slamb@slamb.org>)
Список pgsql-hackers
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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: In Japan with Josh Berkus
Следующее
От: Markus Schaber
Дата:
Сообщение: Re: qsort again (was Re: [PERFORM] Strange Create Index