Re: "People near me" query

From: Harald Fuchs <hf118(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: "People near me" query
Date: 2004-03-19 12:36:59
Message-ID: puu10lhv2s.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <405AC5D7(dot)1090906(at)zara(dot)6(dot)isreserved(dot)com>,
David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com> writes:

> Imagine an Orkut-like site. Suppose we have 'person' table of 100k
> people. About 75% of these people fill in their location
> (City/State/Country) information. We also have a 'city' table
> containing list of cities with their state & country and each city's
> latitude/longitude. Assume all people's location is registered in the
> 'city' table.

> How does one design a database to be able to process "Show me people
> that live no farther than 250 miles from where I live" quickly? I can
> do "Show me people that live within (A-X to A+X) latitude and (B-X to
> B+X) longitude" though. (Where A and B is the latitude and longitude
> [of the person], and X is some numeric value.

On a flat surface, this gives you a square where the corners are too
far away, but it's a nice way to weed all the records definitely
outside of the circle. For the remaining records, you could use sqrt
(dx**2 + dy**2) in your application.

Things get worse if you want to take the spherical nature of the
surface into account, but are you sure you need that?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message pgsql-general@list.coretech.ro 2004-03-19 12:38:52 trigger statement
Previous Message Al Cohen 2004-03-19 12:29:11 High Reliability without High Availability?