I'm having some trouble in optimizing some posgresql queries. For example, this one seams to be the slowest:
select st_astext(geom), 'all' as type
from (
select ST_Simplify(ST_Intersection(ST_MakePolygon(ST_GeomFromText(? ,4326)), st_transform(way, 4326)), ?) as geom
from planet_osm_polygon
where (sT_Intersects(ST_MakePolygon(ST_GeomFromText(?,4326)), st_transform(way,4326))=true)
and ('natural' IN ('water', 'pond') OR waterway IN ('basin', 'canal', 'mill_pond', 'pond', 'riverbank', 'stream'))
) AS subquery";
First thing i did was editing the conf file and changing buffer sizes, and i got few percent less in total time spent.
Next thing I did was creating new tables from existing tables and breaking multipolygons into polygons. That speeded up most of the querys from 70-90%.
However, the slowest 3 queries didnt speed up more than a few percent.
By examining the searches using EXPLAIN and ANALYZE, i realized that indexes are not used.
What is used is seqscan even if i disable it. As far as i know this means that i should make a new index.
In the table planet_osm_polygon i have two indexes:
CREATE INDEX planet_osm_polygon_index_poly
ON planet_osm_polygon_poly
USING gist (way);
CREATE INDEX planet_osm_polygon_poly_pkey
ON planet_osm_polygon_poly
USING btree (osm_id);
Any ideas how to speed up this query and why aren't the indexes being used?
This is very new to me, and if something i wrote doesn't make sense, just ignore it :)