ToDo: KNN Search should to support DISTINCT clasuse? - Mailing list pgsql-hackers

From Pavel Stehule
Subject ToDo: KNN Search should to support DISTINCT clasuse?
Date
Msg-id CAFj8pRAzY4duEw-NzMyst3arBLX0YEyHYmS1ET+K0yu0SWHO_A@mail.gmail.com
Whole thread Raw
Responses Re: ToDo: KNN Search should to support DISTINCT clasuse?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello

I should to search distinct values based on similarity

postgres=# explain select  nazobce, nazobce <-> 'Benešov' from obce
order by nazobce <-> 'Benešov' limit 10
;                                       QUERY PLAN
-------------------------------------------------------------------------------------------Limit  (cost=0.00..0.86
rows=10width=10)  ->  Index Scan using obce_nazobce_idx on obce  (cost=0.00..1433.14 
rows=16644 width=10)        Order By: (nazobce <-> 'Benešov'::text)
(3 rows)

Time: 0.576 ms

but using DISTINCT breaks KNN searching optimization

postgres=# explain select distinct nazobce, nazobce <-> 'Benešov' from
obce order by nazobce <-> 'Benešov' limit 10
;                                QUERY PLAN
-----------------------------------------------------------------------------Limit  (cost=600.45..600.47 rows=10
width=10) ->  Sort  (cost=600.45..613.80 rows=5341 width=10)        Sort Key: ((nazobce <-> 'Benešov'::text))        ->
HashAggregate  (cost=418.27..485.03 rows=5341 width=10)              ->  Seq Scan on obce  (cost=0.00..335.05
rows=16644width=10) 
(5 rows)

Regards

Pavel Stehule



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Deprecating RULES
Next
From: Robert Haas
Date:
Subject: Re: [v9.3] Row-Level Security