Yuri Astrakhan 2b95d1cffa
Fix & optimize incorrect function declarations (#918)
* All functions that access database must be declared as `STABLE`, not `IMMUTABLE` -- because database can change at any moment, e.g. during an update
* there are a few functions that could be made `STRICT` -- passing `NULL` as a parameter will always result in a `NULL`, but for some reason that causes a significant decrease in perf.
* tagged one function as parallel safe

NOTE: somehow `ST_AsMVT()` method of tile generation is showing 70-90% slowdown with this patch. I am not sure of why this is happening. If the reason is the `IMMUTABLE` -> `STABLE` change, we may have to dig deeper into PG optimization
2020-06-17 12:15:26 -04:00

62 lines
2.2 KiB
PL/PgSQL

-- etldoc: layer_aeroway[shape=record fillcolor=lightpink, style="rounded,filled",
-- etldoc: label="layer_aeroway |<z10> z10|<z11> z11|<z12> z12|<z13> z13|<z14_> z14+" ];
CREATE OR REPLACE FUNCTION layer_aeroway(bbox geometry, zoom_level int)
RETURNS TABLE
(
geometry geometry,
class text,
ref text
)
AS
$$
SELECT geometry, aeroway AS class, ref
FROM (
-- etldoc: osm_aeroway_linestring_gen3 -> layer_aeroway:z10
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen3
WHERE zoom_level = 10
UNION ALL
-- etldoc: osm_aeroway_linestring_gen2 -> layer_aeroway:z11
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen2
WHERE zoom_level = 11
UNION ALL
-- etldoc: osm_aeroway_linestring_gen1 -> layer_aeroway:z12
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen1
WHERE zoom_level = 12
UNION ALL
-- etldoc: osm_aeroway_linestring -> layer_aeroway:z13
-- etldoc: osm_aeroway_linestring -> layer_aeroway:z14_
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring
WHERE zoom_level >= 13
UNION ALL
-- etldoc: osm_aeroway_polygon_gen3 -> layer_aeroway:z10
-- etldoc: osm_aeroway_polygon_gen3 -> layer_aeroway:z11
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen3
WHERE zoom_level BETWEEN 10 AND 11
UNION ALL
-- etldoc: osm_aeroway_polygon_gen2 -> layer_aeroway:z12
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen2
WHERE zoom_level = 12
UNION ALL
-- etldoc: osm_aeroway_polygon_gen1 -> layer_aeroway:z13
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen1
WHERE zoom_level = 13
UNION ALL
-- etldoc: osm_aeroway_polygon -> layer_aeroway:z14_
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon
WHERE zoom_level >= 14
) AS zoom_levels
WHERE geometry && bbox;
$$ LANGUAGE SQL STABLE
-- STRICT
PARALLEL SAFE;