<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>I was hoping to
simplify some of my distance queries by creating a within_distance function
which looks like</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>CREATE OR REPLACE
FUNCTION within_distance(geom1 geometry, geom2 geometry, dist double
precision)<BR> RETURNS boolean AS<BR>$BODY$<BR>BEGIN<BR> return
(expand(geom1, dist) && geom2 AND distance(geom1, geom2) <= dist)
;<BR>END;$BODY$<BR> LANGUAGE 'plpgsql' IMMUTABLE;</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>Upon testing this I
noticed the following observations</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>SELECT l.pid,
l.the_geom<BR>FROM landparcels l , landparcels l2<BR>WHERE l2.pid = '1803570000'
and within_distance(l.the_geom, l2.the_geom, 1000) ;</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>runs in 1610ms and
returns 679 rows</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2>---------------------------------------------------------------------------</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>SELECT l.pid,
l.the_geom<BR>FROM landparcels l, landparcels l2<BR>WHERE l2.pid = '1803570000'
and (expand(l.the_geom, 1000) && l2.the_geom AND distance(l.the_geom,
l2.the_geom) <= 1000)</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>runs in 609 ms and
returns 679 rows</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2>--------------------------------------------------------------------------</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>SELECT l.pid,
l.the_geom<BR>FROM landparcels l, landparcels l2<BR>WHERE l2.pid = '1803570000'
and (distance(l.the_geom, l2.the_geom) <= 1000)</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>runs in 5437 ms and
returns 679 rows</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2>-----</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial size=2>I ran the test a
couple of times with similar results. So apparently as far as I can tell,
my function is probably using my gist indexes, but why is it 1/2 the speed of
the regular expand call?</FONT></SPAN></DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=039412520-09022007><FONT face=Arial
size=2></FONT></SPAN> </DIV></BODY></HTML>
<HTML><BODY><P><hr size=1></P><br>
<P><STRONG><br>
The substance of this message, including any attachments, may be<br>
confidential, legally privileged and/or exempt from disclosure<br>
pursuant to Massachusetts law. It is intended solely for the<br>
addressee. If you received this in error, please contact the sender<br>
and delete the material from any computer.<br>
</STRONG></P></BODY></HTML>