Hi Micheal,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Thank you for reply.<br>
I am not sure about whether &quot;xxxxxx9999&quot; represents some thing special
in data or not. I have indexes on geometry and id coloumns, i vacuumed
and analyzed the tables. Here are the EXPLAIN ANALYSE results of
slowqery and faster one:<br>
<span style="color: rgb(153, 51, 0);">slow query:</span><br>
<br>
<span style="font-weight: bold;">explain ANALYZE (select count(*) from la_blocks as c join la_damage as d on c.stfid=<span style="color: rgb(255, 0, 0);">'220750501002999'</span> and d.the_geom&amp;&amp;c.the_geom and intersects(
d.the_geom,c.the_geom));</span><br style="font-weight: bold;">
<br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
QUERY PLAN</span><br style="font-weight: bold;">
<span style="font-weight: bold;">------------------------------------------------------------------------------------------------------------------------------------------------------</span><br style="font-weight: bold;">

<span style="font-weight: bold;">&nbsp;Aggregate&nbsp; (cost=9.06..9.07 rows=1 width=0) (actual time=973892.916..973892.917 rows=1 loops=1)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp; -&gt;&nbsp; Nested Loop&nbsp; (cost=0.00..9.05 rows=1 width=0) (actual time=973892.901..973892.901 rows=0 loops=1)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join Filter: intersects(&quot;inner&quot;.the_geom, &quot;outer&quot;.the_geom)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&gt;&nbsp; Index Scan using stfidx_la_blocks on la_blocks c&nbsp;
(cost=0.00..3.03 rows=1 width=585) (actual time=0.035..0.046 rows=1
loops=1)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Index Cond: ((stfid)::text = '220750501002999'::text)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&gt;&nbsp; Index Scan using geomidx_la_damage on la_damage d&nbsp;
(cost=0.00..6.01 rows=1 width=21) (actual time=2018.848..44473.260
rows=1139 loops=1)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Index Cond: (d.the_geom &amp;&amp; &quot;outer&quot;.the_geom)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Filter: (d.the_geom &amp;&amp; &quot;outer&quot;.the_geom)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">&nbsp;Total runtime: <span style="color: rgb(255, 0, 0);">973918.391</span> ms</span><br style="font-weight: bold;">
<span style="font-weight: bold;">(9 rows)</span><br>
<br>
<span style="color: rgb(153, 0, 0);">Faster Query<br>
<br>
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;explain ANALYZE (select count(*) from la_blocks as c join la_damage as d on c.stfid='<span style="color: rgb(255, 0, 0);">220750501002995</span>' and d.the_geom&amp;&amp;c.the_geom
 and intersects(d.the_geom,c.the_geom));</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
QUERY PLAN</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">----------------------------------------------------------------------------------------------------------------------------------------------</span><br style="color: rgb(0, 0, 0); font-weight: bold;">

<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;Aggregate&nbsp; (cost=9.06..9.07 rows=1 width=0) (actual time=26.307..26.307 rows=1 loops=1)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp; -&gt;&nbsp; Nested Loop&nbsp; (cost=0.00..9.05 rows=1 width=0) (actual time=26.299..26.299 rows=0 loops=1)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join Filter: intersects(&quot;inner&quot;.the_geom, &quot;outer&quot;.the_geom)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&gt;&nbsp; Index Scan using stfidx_la_blocks on la_blocks c&nbsp;
(cost=0.00..3.03 rows=1 width=585) (actual time=26.183..26.187 rows=1
loops=1)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Index Cond: ((stfid)::text = '220750501002995'::text)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&gt;&nbsp; Index Scan using geomidx_la_damage on la_damage d&nbsp;
(cost=0.00..6.01 rows=1 width=21) (actual time=0.102..0.102 rows=0
loops=1)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Index Cond: (d.the_geom &amp;&amp; &quot;outer&quot;.the_geom)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Filter: (d.the_geom &amp;&amp; &quot;outer&quot;.the_geom)</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">&nbsp;Total runtime: <span style="color: rgb(255, 0, 0);">26.386</span> ms</span><br style="color: rgb(0, 0, 0); font-weight: bold;">
<span style="color: rgb(0, 0, 0); font-weight: bold;">(9 rows)</span><br style="font-weight: bold;">
<br>
<span style="color: rgb(0, 0, 0);">Thanking you<br>
vamsee<br>
</span></span><br><br><div><span class="gmail_quote">On 10/30/06, <b class="gmail_sendername">Michael Fuhr</b> &lt;<a href="mailto:mike@fuhr.org">mike@fuhr.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Mon, Oct 30, 2006 at 09:00:29AM -0600, vamsee movva wrote:<br>&gt; &quot;select count(*) from locations l1,county l2 where l1.the_geom &amp;&amp;<br>&gt; l2.the_geom and intersects(l2.the_geom,l1.the_geom) and l2.countyid=
 some<br>&gt; particular ID&quot;<br>&gt;<br>&gt; It gave some results, but i am not sure whether the query is correct or not,<br>&gt; I have one more problem with this query, this query taking lot of time<br>&gt; when some
<br>&gt; particular ID ends with 9999(ex:220750501002999,xxxxxxx9999), do u have any<br>&gt; idea about this strange situation.<br><br>Are you sure 9999 is relevant or might it just be coincidence?&nbsp;&nbsp;Does<br>9999 represent anything special in the data?&nbsp;&nbsp;Do you have indexes
<br>on the geometry and ID columns?&nbsp;&nbsp;Have you vacuumed and analyzed the<br>tables?&nbsp;&nbsp;What does EXPLAIN ANALYZE show for a slow query and for a<br>faster one?<br><br>--<br>Michael Fuhr<br>_______________________________________________
<br>postgis-users mailing list<br><a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users
</a><br></blockquote></div><br>