Re: application of KNN code to US zipcode searches?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: application of KNN code to US zipcode searches?
Дата
Msg-id 13093.1297970237@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: application of KNN code to US zipcode searches?  (Mark Stosberg <mark@summersault.com>)
Ответы Re: application of KNN code to US zipcode searches?
Список pgsql-performance
Mark Stosberg <mark@summersault.com> writes:
> - The query planner didn't like it when the "ORDER BY" referred to a
>   column value instead of a static value, even when I believe it should
>   know that the column value never changes. See this pseudo-query where
>   we look-up the coordinates for 90210 once:

>   EXPLAIN ANALYZE
>   SELECT pets.pet_id,
>       zipcodes.lon_lat <-> center.lon_lat AS radius
>       FROM (SELECT lon_lat FROM zipcodes WHERE zipcode = '90210') AS
> center, pets
>       JOIN shelters USING (shelter_id)
>       JOIN zipcodes USING (zipcode)
>        ORDER BY postal_codes.lon_lat <-> center.lon_lat limit 1000;

As phrased, that's a join condition, so there's no way that an index on
a single table can possibly satisfy it.  You could probably convert it
to a sub-select though:

       ORDER BY postal_codes.lon_lat <-> (SELECT lon_lat FROM zipcodes WHERE zipcode = '90210') limit 1000;

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: application of KNN code to US zipcode searches?
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: application of KNN code to US zipcode searches?