CTEs always materialise so inline the union zoom level views ⚠️

This commit is contained in:
lukasmartinelli
2016-10-08 21:27:28 +02:00
parent d53ca84a36
commit 63985fca1e
9 changed files with 52 additions and 60 deletions

View File

@@ -8,16 +8,15 @@ CREATE OR REPLACE VIEW building_z14 AS (
CREATE OR REPLACE FUNCTION layer_building(bbox geometry, zoom_level int)
RETURNS TABLE(geom geometry, osm_id bigint, render_height float) AS $$
WITH zoom_levels AS (
SELECT way, osm_id,
least(greatest(3, COALESCE(height, levels*3.66,5)),400)^.7 AS render_height
FROM (
SELECT osm_id, ST_Simplify(way, 10) AS way, height, levels FROM building_z13
WHERE zoom_level = 13
UNION ALL
SELECT * FROM building_z14
WHERE zoom_level >= 14
)
SELECT way, osm_id,
least(greatest(3, COALESCE(height, levels*3.66,5)),400)^.7 AS render_height
FROM zoom_levels
) AS zoom_levels
WHERE way && bbox
ORDER BY render_height, ST_YMin(way) DESC;
$$ LANGUAGE SQL IMMUTABLE;