pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark kirkwood <markir@slingshot.co.nz>
To: Ryan Littrell <ryan@heliosinc.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: performance issue with distance function
Date: Sun, 29 Jul 2001 16:30:13 +1200
Message-ID: <01072916301301.01095@spikey.slithery.org> (raw)

Hi Ryan,

There is a bit of a strange way around the distance overhead issue :

Create another table with structure like 
(lat1,long1,zip1,lat2,long2,zip2,distance)

and precalculate the distance for each possibility. This means n*(n-1) rows 
if you have n location rows. You would then include this table in your query 
and use distance like you wanted to initially ( should work fast provided you 
index it on lat1,long1,distance)

The calculation overhead of distance is then removed from your query ( at the 
expense of some disk space ). The insert of each new location requires n 
calculations of distance - you could perform this in the background I guess !

regards

Mark




view thread (3+ messages)

Message-ID: <01072916301301.01095@spikey.slithery.org>
Permalink:  ../01072916301301.01095@spikey.slithery.org/
Also on:    postgresql.org/message-id/01072916301301.01095@spikey.slithery.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: markir@slingshot.co.nz, ryan@heliosinc.net
  Subject: Re: performance issue with distance function
  In-Reply-To: <01072916301301.01095@spikey.slithery.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox