From 2996987e70f5933900d28ae54107ad74107d0cff Mon Sep 17 00:00:00 2001 From: MartinMikita Date: Tue, 28 Mar 2017 16:27:34 +0200 Subject: [PATCH] Added few partial index to speed up creating materialized views in transportation merge_highways. --- layers/transportation/merge_highways.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/layers/transportation/merge_highways.sql b/layers/transportation/merge_highways.sql index 6525b202..1bfe9957 100644 --- a/layers/transportation/merge_highways.sql +++ b/layers/transportation/merge_highways.sql @@ -13,6 +13,16 @@ DROP TRIGGER IF EXISTS trigger_refresh ON transportation.updates; -- etldoc: osm_highway_linestring -> osm_transportation_merge_linestring + +-- Improve performance of the sql in transportation_name/network_type.sql +CREATE INDEX IF NOT EXISTS osm_highway_linestring_highway_idx + ON osm_highway_linestring(highway); + +-- Improve performance of the sql below +CREATE INDEX IF NOT EXISTS osm_highway_linestring_highway_partial_idx + ON osm_highway_linestring(highway) + WHERE highway IN ('motorway','trunk'); + CREATE MATERIALIZED VIEW osm_transportation_merge_linestring AS ( SELECT (ST_Dump(geometry)).geom AS geometry, @@ -34,6 +44,10 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring AS ( ) AS highway_union ); CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_geometry_idx ON osm_transportation_merge_linestring USING gist(geometry); +-- Improve performance of the sql below +CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_highway_partial_idx + ON osm_transportation_merge_linestring(highway) + WHERE highway IN ('motorway','trunk'); -- etldoc: osm_transportation_merge_linestring -> osm_transportation_merge_linestring_gen5 CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen5 AS ( @@ -42,6 +56,10 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen5 AS ( WHERE highway IN ('motorway','trunk') AND ST_Length(geometry) > 20000 ); CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen5_geometry_idx ON osm_transportation_merge_linestring_gen5 USING gist(geometry); +-- Improve performance of the sql below +CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen5_highway_partial_idx + ON osm_transportation_merge_linestring_gen5(highway) + WHERE highway IN ('motorway'); -- etldoc: osm_transportation_merge_linestring_gen5 -> osm_transportation_merge_linestring_gen6 CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen6 AS (