<div dir="ltr">Thanks for your answer,<div><br></div><div>The first one by Stephen worked really well,</div><div><br></div><div>Just changing from</div><div><br></div><div><span style="font-family:'courier new',monospace;font-size:13.333333969116211px">SELECT "regions".* FROM "regions" WHERE (regions.service_area && <b>ST_GeographyFromText</b>('SRID=</span><span style="font-family:'courier new',monospace;font-size:13.333333969116211px">4326;POINT(7.04756999999995 51.17042)')) ORDER BY admin_area_level DESC, fare_quality DESC, is_operation_region DESC LIMIT 1</span><br>
</div><div><span style="font-family:'courier new',monospace;font-size:13.333333969116211px"><br></span></div><div><span style="font-size:13.333333969116211px"><font face="arial, helvetica, sans-serif">to </font></span></div>
<div><br></div><div><font face="courier new, monospace"><span style="font-size:13.333333969116211px">SELECT "regions".* FROM "regions" WHERE (regions.service_area && <b>ST_GeometryFromText</b>('SRID=</span><u style="font-size:13.333333969116211px"></u><span style="font-size:13.333333969116211px">4326</span><span style="font-size:13.333333969116211px">;POINT(7.04756999999995 51.17042)')) ORDER BY admin_area_level DESC, fare_quality DESC, is_operation_region DESC LIMIT 1</span></font></div>
<div><span style="font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><span style="font-size:13.333333969116211px;font-family:arial,sans-serif">solved the problem, now is very fast,</span></div>
<div><span style="font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><span style="font-size:13.333333969116211px;font-family:arial,sans-serif">Thanks!</span></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On 15 July 2013 17:37, Sandro Santilli <span dir="ltr"><<a href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Add a spatial index on service_area too, then run ANALYZE.<br>
<br>
Use EXPLAIN ANALYZE <your_query> next time, if needed.<br>
<br>
--strk;<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, Jul 15, 2013 at 05:30:57PM +0200, Daniel, de la Cuesta Navarrete wrote:<br>
> Hi,<br>
><br>
> I have a table with a geometry column and around 3000 rows.<br>
><br>
> The table has a geospatial index in the geometry column (service_area):<br>
><br>
> CREATE INDEX regions_index ON regions USING GIST ( service_area );<br>
><br>
> I am doing the following query:<br>
><br>
> SELECT "regions".* FROM "regions" WHERE (regions.service_area &&<br>
> ST_GeographyFromText('SRID=4326;POINT(7.04756999999995 51.17042)')) ORDER<br>
> BY admin_area_level DESC, fare_quality DESC, is_operation_region DESC LIMIT<br>
> 1<br>
><br>
> It is taking around 8-9 seconds to perform this query but the problem is<br>
> that it is not taking the geospatial index, if a do EXPLAIN of the query I<br>
> get:<br>
><br>
><br>
> Limit (cost=138.23..138.24 rows=1 width=130769)<br>
> -> Sort (cost=138.23..138.24 rows=1 width=130769)<br>
><br>
> Sort Key: admin_area_level, fare_quality, is_operation_region<br>
> -> Seq Scan on regions (cost=0.00..138.22 rows=1 width=130769)<br>
><br>
> Filter: ((service_area)::geography &&<br>
> '0101000020E6100000FF14A930B6301C40CB4A9352D0954940'::geography)<br>
><br>
> Is it possible to improve the performance of this query? Why is not taking<br>
> the geospatial index?<br>
><br>
><br>
> PostgreSQL 9.1.4 on i686-pc-linux-gnu, compiled by gcc (Ubuntu<br>
> 4.4.3-4ubuntu5.1) 4.4.3, 32-bit POSTGIS=\"1.5.3\" GEOS=\"3.3.1-CAPI-1.7.1\"<br>
> PROJ=\"Rel. 4.7.1, 23 September 2009\" LIBXML=\"2.7.6\" USE_STATS"<br>
><br>
> Best<br>
> D<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br></div>