<div dir="ltr"><div><div><div><div><div>For this particular case,<br>using st_srid(geom) means that the planner have to compute this value for each line .<br></div><div>(the planner has no way to know that srid is the same for every geometry in the column, this might not be the case)<br></div>You can't use it .<br>for instance, you could simply use plpgsql to get the srid, and create your querry directly with the number<br></div><div>(your querry looks like it is fabricated programmatically anyway)<br></div><div>You could also look for this srid value in the geometry_columns view, but it would be less safe. <br><br></div><div>lastly you coudl had an index on your geom table casted to srid 0, this way you could systematically cast your wkt to srid 0. I would call it a pretty bad idea unless you have lot's of differnt srid and you will have to translate for other usages anyway<br><br></div><div>Example : <br>CREATE INDEX ON my_table USING GIST( st_translate(geom,0) )<span class="im"></span><br><span class="im">SELECT "id",encode(ST_AsEWKB("geom"),'base64') as "geometry"<br>
FROM my_table<br>
WHERE st_translate(geom,0) &&<br></span>
ST_GeomFromText('POLYGON ((892267.1937422 6148208.34251139, 
892500.497129949 6148208.34251139, 892500.497129949 6148009.40012468, 
892267.1937422 6148009.40012468, 892267.1937422 6148208.34251139))',0)<br>
<br></div></div></div>Cheers,<br></div>Rémi-C<br></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-16 17:43 GMT+01:00 Rémi Cura <span dir="ltr"><<a href="mailto:remi.cura@gmail.com" target="_blank">remi.cura@gmail.com</a>></span>:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hey,<br></div>no index can come from 2 problems :<br></div>  - your querry can't use the index<br></div>  - your querry could use the index but the planner thinks it's faster to do sequential scan.<br><br></div>You can discriminate between the 2 avoiding explicitly sequential scan :<br>`SET enable_seqscan TO FALSE`<br></div><div>(don't forget to turn it back one afterward)<br></div><div>if you are still not using index, your querry can't use it at all, thus there is a problem of definition.<tt><br></tt></div><div>Cheers,<br>Rémi-C<tt><br></tt></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2014-12-16 17:23 GMT+01:00 Andy Colson <span dir="ltr"><<a href="mailto:andy@squeakycode.net" target="_blank">andy@squeakycode.net</a>></span>:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On 12/16/2014 9:18 AM, Casper Børgesen (CABO) wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
This seems like one of the most asked questions in the PostgreSQL world,<br>
but I guess I haven’t understood all the answers yet:<br>
<br>
Why won’t my SELECT query use the INDEX I have created for it?<br>
<br>
I have a table with about 18mio rows.<br>
<br>
My SELECT statement looks like this:<br>
<br>
SELECT "id",encode(ST_AsEWKB("geom"),<u></u>'base64') as "geometry"<br>
<br>
FROM my_table<br>
<br>
WHERE geom &&<br>
<br>
ST_GeomFromText('POLYGON ((892267.1937422 6148208.34251139,<br>
892500.497129949 6148208.34251139, 892500.497129949 6148009.40012468,<br>
892267.1937422 6148009.40012468, 892267.1937422 6148208.34251139))',<br>
ST_SRID("geom"))<br>
<br>
The EXPLAIN ANALYZE of the above statement returned this:<br>
<br>
"Seq Scan on my_table  (cost=0.00..4329124.83 rows=1731 width=1700)<br>
(actual time=194785.745..1553525.244 rows=138 loops=1)"<br>
<br>
"  Filter: (geom && st_geomfromtext('POLYGON ((892267.1937422<br>
6148208.34251139, 892500.497129949 6148208.34251139, 892500.497129949<br>
6148009.40012468, 892267.1937422 6148009.40012468, 892267.1937422<br>
6148208.34251139))'::text, st_srid(geom)))"<br>
<br>
"  Rows Removed by Filter: 17311187"<br>
<br>
"Total runtime: 1553525.352 ms"<br>
<br>
The POLYGON described above is located at the outer edge of the 17mio<br>
geometries and the extent is pretty small.<br>
<br>
I have executed a VACUUM ANALYZE to clean up the statistics, which<br>
didn’t seem to improve the results.<br>
<br>
My INDEX has been created like this:<br>
<br>
CREATE INDEX my_table_geom_idx<br>
<br>
   ON my_table<br>
<br>
   USING gist<br>
<br>
   (geom);<br>
<br>
Upon reading up on this issue I have changed the following in my<br>
postgresql.conf:<br>
<br>
random_page_cost = 2.0<br>
<br>
shared_buffers = 512MB<br>
<br>
work_mem = 8MB<br>
<br>
maintenance_work_mem = 256MB<br>
<br>
effective_cache_size = 8GB<br>
<br>
The HARDWARE is a Windows 2012R2 with 12GB ram and SAS HDDs. PostgreSQL<br>
9.3 x64 and PostGIS 2.1.1.<br>
<br>
Can any ask me the right questions so I can solve my INDEX problem?<br>
<br>
<br>
<br></div></div>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">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-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
<br>
</blockquote>
<br>
<br>
I doubt changing postgresql.conf options will have any affect.<br>
<br>
Its the st_srid(geom) call that's a problem.<br>
<br>
Remove it, or specify the integer value.  The function call messes it up.<br>
<br>
This should work:<br>
<br>
<br>
explain analyze<span><br>
SELECT "id",encode(ST_AsEWKB("geom"),<u></u>'base64') as "geometry"<br>
FROM my_table<br>
WHERE geom &&<br></span>
ST_GeomFromText('POLYGON ((892267.1937422 6148208.34251139, 892500.497129949 6148208.34251139, 892500.497129949 6148009.40012468, 892267.1937422 6148009.40012468, 892267.1937422 6148208.34251139))')<br>
<br>
<br>
-Andy<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">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-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
</blockquote></div></div>
</div></div></blockquote></div></div>