Hackers,
attached patch implementing ordering inside GIN index. This is third patch of GIN improvements, see previous two:
http://www.postgresql.org/message-id/CAPpHfduxv-iL7aedwPW0W5fXrWGAKfxijWM63_hZujaCRxnmFQ@mail.gmail.comhttp://www.postgresql.org/message-id/CAPpHfdvftaJq7www381naLw1=4u0h+qpXgWvNhcEB9HMVywbGg@mail.gmail.comThis patch introduces new interface method of GIN which takes same arguments as consistent but returns float8.
float8 gin_ordering(bool check[], StrategyNumber n, Datum query, int32 nkeys, Pointer extra_data[], bool *recheck, Datum queryKeys[], bool nullFlags[], Datum addInfo[], bool addInfoIsNull[])
This patch implements gingettuple method which can return ordering data using KNN infrastructure. Also it introduces >< operator for fts which support ordering in GIN index. Some example:
postgres=# explain analyze select * from dblp_titles2 where tsvector @@ to_tsquery('english', 'statistics') order by tsvector >< to_tsquery('english', 'statistics') limit 10;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=12.00..48.22 rows=10 width=136) (actual time=6.999..7.120 rows=10 loops=1)
-> Index Scan using dblp_titles2_idx on dblp_titles2 (cost=12.00..43003.03 rows=11868 width=136) (actual time=6.996..7.115 rows=10 loops=1)
Index Cond: (tsvector @@ '''statist'''::tsquery)
Order By: (tsvector >< '''statist'''::tsquery)
Total runtime: 7.556 ms
(5 rows)
------With best regards,
Alexander Korotkov.