Sort functions with specialized comparators

Поиск
Список
Период
Сортировка
От Andrey M. Borodin
Тема Sort functions with specialized comparators
Дата
Msg-id 098A3E67-E4A6-4086-9C66-B1EAEB1DFE1C@yandex-team.ru
обсуждение исходный текст
Ответы Re: Sort functions with specialized comparators  (Ranier Vilela <ranier.vf@gmail.com>)
Re: Sort functions with specialized comparators  (Stepan Neretin <sncfmgg@gmail.com>)
Список pgsql-hackers
Hi!

In a thread about sorting comparators[0] Andres noted that we have infrastructure to help compiler optimize sorting.
PFAattached PoC implementation. I've checked that it indeed works on the benchmark from that thread. 

postgres=# CREATE TABLE arrays_to_sort AS
   SELECT array_shuffle(a) arr
   FROM
       (SELECT ARRAY(SELECT generate_series(1, 1000000)) a),
       generate_series(1, 10);

postgres=# SELECT (sort(arr))[1] FROM arrays_to_sort; -- original
Time: 990.199 ms
postgres=# SELECT (sort(arr))[1] FROM arrays_to_sort; -- patched
Time: 696.156 ms

The benefit seems to be on the order of magnitude with 30% speedup.

There's plenty of sorting by TransactionId, BlockNumber, OffsetNumber, Oid etc. But this sorting routines never show up
inperf top or something like that. 

Seems like in most cases we do not spend much time in sorting. But specialization does not cost us much too, only some
CPUcycles of a compiler. I think we can further improve speedup by converting inline comparator to value extractor:
morecompilers will see what is actually going on. But I have no proofs for this reasoning. 

What do you think?


Best regards, Andrey Borodin.

[0]
https://www.postgresql.org/message-id/flat/20240209184014.sobshkcsfjix6u4r%40awork3.anarazel.de#fc23df2cf314bef35095b632380b4a59

Вложения

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

Предыдущее
От: Michał Kłeczek
Дата:
Сообщение: Re: allow sorted builds for btree_gist
Следующее
От: Alexander Lakhin
Дата:
Сообщение: Re: Streaming read-ready sequential scan code