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

From Kevin Grittner
Subject Re: ToDo: KNN Search should to support DISTINCT clasuse?
Date
Msg-id 20121025175706.306890@gmx.com
Whole thread Raw
In response to ToDo: KNN Search should to support DISTINCT clasuse?  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: ToDo: KNN Search should to support DISTINCT clasuse?  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Tom Lane wrote:
> "Kevin Grittner" <kgrittn@mail.com> writes:
> > Pavel Stehule wrote:
> >> 2012/10/22 Tom Lane <tgl@sss.pgh.pa.us>:
> >>> Perhaps it would be close enough to what you want to use DISTINCT ON:
> >>> contrib_regression=# explain select distinct on( t <-> 'foo') *,t <-> 'foo' from test_trgm order by t <-> 'foo'
limit10;
 
> 
> >> good tip - it's working
> 
> > If two or more values happen to be at exactly the same distance,
> > wouldn't you just get one of them?
> 
> Yeah, that is a hazard. I'm not sure whether <->'s results are
> sufficiently quantized to make that a big problem in practice.

It doesn't seem too far-fetched for trigram queries:

test=# select nm, nm <-> 'anders' from (values ('anderson'),('andersen'),('andersly')) x(nm);   nm    | ?column? 
----------+----------anderson |      0.4andersen |      0.4andersly |      0.4
(3 rows)

test=# select distinct on (nm <-> 'anders') nm, nm <-> 'anders' from (values ('anderson'),('andersen'),('andersly'))
x(nm)order by nm <-> 'anders' limit 3;   nm    | ?column? 
 
----------+----------anderson |      0.4
(1 row)

-Kevin



pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: Extensions Documentation
Next
From: Euler Taveira
Date:
Subject: Re: sql_implementation_info still contains old value