<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
Markus,<br>
<br>
I already tried the first one (inner select) before my first mail and
it gave me the same results as explained previously.<br>
<br>
The second one give me also comparable results (2282 results in ~4562
ms)...<br>
Here is the EXPLAIN ANALYSE results :<br>
<br>
Aggregate  (cost=5433.45..5433.45 rows=1 width=0) (actual
time=4363.741..4363.742 rows=1 loops=1)<br>
   ->  Nested Loop  (cost=0.00..5430.83 rows=1045 width=0) (actual
time=36.689..4359.320 rows=2282 loops=1)<br>
         ->  Index Scan using cntry_name_idx on country 
(cost=0.00..805.94 rows=209 width=32) (actual time=0.043..0.288 rows=1
loops=1)<br>
               Index Cond: ((cntry_name)::text = 'France'::text)<br>
         ->  Index Scan using world_1000000_geom_idx on
world_1000000  (cost=0.00..22.07 rows=5width=113) (actual
time=36.637..4352.006 rows=2282 loops=1)<br>
               Index Cond: (world_1000000.the_geom &&
"outer".geometry_country)<br>
 Total runtime: 4363.835 ms<br>
(7 rows)<br>
<br>
Seems to be very close from previous query.<br>
<br>
I've also create a btree index on cntry_name but the results are the
same (which sounds logical since the country table just contains 200
rows)<br>
<br>
Jerome<br>
<br>
<br>
Markus Schaber a écrit :
<blockquote cite="mid434E8D58.5000301@logix-tt.com" type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta name="Generator" content="MS Exchange Server version 6.5.7226.0">
  <title>Re: [postgis-users] Strange Performance issue</title>
<!-- Converted from text/plain format -->
  <p><font size="2">Hi, Jerome,</font>
  </p>
  <p><font size="2">Jerome Gasperi wrote:</font>
  </p>
  <p><font size="2">> Here is the EXPLAIN ANALYSE of the query :</font>
  <br>
  <font size="2">> </font>
  <br>
  <font size="2">> Aggregate  (cost=5433.45..5433.45 rows=1 width=0)
(actual</font>
  <br>
  <font size="2">> time=4373.253..4373.254 rows=1 loops=1)</font>
  <br>
  <font size="2">>    ->  Nested Loop  (cost=0.00..5430.83
rows=1045 width=0) (actual</font>
  <br>
  <font size="2">> time=42.830..4368.146 rows=2282 loops=1)</font>
  <br>
  <font size="2">>          ->  Index Scan using cntry_name_idx
on country </font>
  <br>
  <font size="2">> (cost=0.00..805.94 rows=209 width=32) (actual
time=0.049..0.324 rows=1</font>
  <br>
  <font size="2">> loops=1)</font>
  <br>
  <font size="2">>                Index Cond: ((cntry_name)::text =
'France'::text)</font>
  <br>
  <font size="2">>          ->  Index Scan using
world_1000000_geom_idx on world_1000000 </font>
  <br>
  <font size="2">> (cost=0.00..22.07 rows=5width=113) (actual
time=42.772..4360.901</font>
  <br>
  <font size="2">> rows=2282 loops=1)</font>
  <br>
  <font size="2">>                Index Cond:
(world_1000000.the_geom &&</font>
  <br>
  <font size="2">> "outer".geometry_country)</font>
  <br>
  <font size="2">>  Total runtime: 4373.360 ms</font>
  </p>
  <p><font size="2">Okay, I see, it seems that it does a FULL JOIN on
both tables, and then</font>
  <br>
  <font size="2">drop the columns that don't match your country
selection.</font>
  </p>
  <p><font size="2">Could you try the following two:</font>
  </p>
  <p><font size="2">SELECT count(*) FROM world_1000000</font>
  <br>
  <font size="2">      WHERE the_geom &&</font>
  <br>
  <font size="2">            (SELECT contry.geometry_country</font>
  <br>
  <font size="2">             FROM country</font>
  <br>
  <font size="2">             WHERE country.cntry_name='France');</font>
  </p>
  <p><font size="2">SELECT count(*) FROM world_1000000 JOIN country</font>
  <br>
  <font size="2">      ON the_geom && country.geometry_country</font>
  <br>
  <font size="2">      WHERE country.cntry_name='France';</font>
  </p>
  <p><font size="2">(The first one will only work if there's only a
single match on country.)</font>
  </p>
  <p><font size="2">HTH,</font>
  <br>
  <font size="2">Markus</font>
  <br>
  <font size="2">_______________________________________________</font>
  <br>
  <font size="2">postgis-users mailing list</font>
  <br>
  <font size="2"><a class="moz-txt-link-abbreviated" href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a></font>
  <br>
  <font size="2"><a
 href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a></font>
  </p>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
Jerome GASPERI
DCT/PS/TIS - BPi 1218
CENTRE NATIONAL D'ETUDES SPATIALES
18, Av Ed BELIN
31401 TOULOUSE Cedex 4
 
tel : 05 61 28 25 23
fax : 05 61 27 31 67
</pre>
</body>
</html>