Nein, 70 Sekunden waren es nie - immer Millisekunden.
Ich habe eigentlich nur 2 für so eine Query relevante Indizes, osm_id und way:
tablename | indexname | indexdef
--------------+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dach_polygon | dach_polygon_landuse_idx | CREATE INDEX dach_polygon_landuse_idx ON public.dach_polygon USING btree (landuse) WHERE (landuse = ANY (ARRAY['residential'::text, 'industrial'::text, 'commercial'::text, 'retail'::text]))
dach_polygon | dach_polygon_osm_id_idx | CREATE INDEX dach_polygon_osm_id_idx ON public.dach_polygon USING btree (osm_id)
dach_polygon | dach_polygon_tags_idx | CREATE INDEX dach_polygon_tags_idx ON public.dach_polygon USING gin (tags)
dach_polygon | dach_polygon_way_idx | CREATE INDEX dach_polygon_way_idx ON public.dach_polygon USING gist (way)
(4 rows)
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.98..133212.43 rows=18682 width=194) (actual time=24.547..56.918 rows=2818 loops=1)
-> Index Scan using dach_polygon_osm_id_idx on dach_polygon p (cost=0.56..2.78 rows=1 width=194) (actual time=0.087..0.089 rows=1 loops=1)
Index Cond: (osm_id = '-3858975'::integer)
-> Index Scan using dach_polygon_way_idx on dach_polygon b (cost=0.42..133167.52 rows=4213 width=194) (actual time=0.377..32.565 rows=2818 loops=1)
Index Cond: (way && p.way)
Filter: ((building IS NOT NULL) AND st_intersects(p.way, way))
Rows Removed by Filter: 8590
Planning Time: 8.128 ms
JIT:
Functions: 9
Options: Inlining false, Optimization false, Expressions true, Deforming true
Timing: Generation 3.841 ms, Inlining 0.000 ms, Optimization 2.639 ms, Emission 21.133 ms, Total 27.612 ms
Execution Time: 92.880 ms
(13 rows)
Vorschlag: Lösche den Index planet_osm_polygon_3858975 und lege den neu an, aber ohne Einschränkung auf diese eine osm_id. Du möchtest ja wahrscheinlich nicht nur diese eine Abfrage machen.
Clustern nach “way”, wenn noch nicht ausgeführt, wird ziemlich sicher die Abfragezeit verringern, je langsamer der Storage ist, um so mehr. Bitte mal durchlesen vor Ausführung, wegen exklusivem Zugriff (wenn andere Jobs währenddessen laufen müssen). Clustern dauert ziemlich, ist aber wegen fehlender Tabellen-Updates bei dir ja nur ein Onetime-Job.
CLUSTER planet_osm_polygon USING planet_osm_polygon_way_idx;
Ansonsten sehe ich jetzt keine Auffälligkeiten, Indizes werden verwendet, keine Mehrfach-Loops, der Queryplan sieht gut aus, passt alles soweit. Es kann eigentlich nur an den langsamen HDDs liegen.