gist indexes for distance calculations

Поиск
Список
Период
Сортировка
От Marcelo Zabani
Тема gist indexes for distance calculations
Дата
Msg-id AANLkTikvpQS+1q3HBrVCgCjRF+2-LPGzmVHQO+EJk3QG@mail.gmail.com
обсуждение исходный текст
Ответы Re: gist indexes for distance calculations  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: gist indexes for distance calculations  (Jesper Krogh <jesper@krogh.cc>)
Re: gist indexes for distance calculations  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-performance
Hi everyone. I have a question, and it's well beyond me to even speculate about the inner workings of postgresql on this.

I have a "places" table, and a "coordinates" column, of type POINT.

If I want to find every place within, for example, a distance of 1 unit from an arbitrary point, I'll do:

CREATE INDEX ON places USING gist (circle(coordinates, 1));

And then I'll fetch the desired rows like this:

SELECT * FROM places WHERE circle(coordinates, 1) @> circle('(a,b)', 0);
(where (a,b) is an arbitrary point)

I'd like to know how this index works, though, as it seems to me the only way to have this kind of index to work is to calculate the distance of every point in a square of sides 2*1=2 units centered on (a, b).

So, am I wrong to think it works like that? If it does work like that, could I have instead two columns of type FLOAT (xcoordinate and ycoordinate) and create traditional b-tree indexes on both of these, and then do something like:

SELECT * FROM places WHERE xcoordinate >= (a-1) AND xcoordinate <= (a+1) AND ycoordinate >= (b-1) AND ycoordinate <= (b+1) And SQRT(POW(a-xcoordinate,2)+POW(b-ycoordinate,2))<=1;

If you can also pinpoint me to where I can find this sort of information (index utilization and planning, performance tuning), I'd be very grateful.
Thank you already,
Marcelo Zabani.

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

Предыдущее
От: Willy-Bas Loos
Дата:
Сообщение: Re: turn off caching for performance test
Следующее
От: Tom Lane
Дата:
Сообщение: Re: gist indexes for distance calculations