* 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
44 lines
1.6 KiB
PL/PgSQL
44 lines
1.6 KiB
PL/PgSQL
|
|
-- etldoc: layer_aerodrome_label[shape=record fillcolor=lightpink, style="rounded,filled", label="layer_aerodrome_label | <z10_> z10+" ] ;
|
|
|
|
CREATE OR REPLACE FUNCTION layer_aerodrome_label(bbox geometry,
|
|
zoom_level integer)
|
|
RETURNS TABLE
|
|
(
|
|
osm_id bigint,
|
|
geometry geometry,
|
|
name text,
|
|
name_en text,
|
|
name_de text,
|
|
tags hstore,
|
|
class text,
|
|
iata text,
|
|
icao text,
|
|
ele int,
|
|
ele_ft int
|
|
)
|
|
AS
|
|
$$
|
|
SELECT
|
|
-- etldoc: osm_aerodrome_label_point -> layer_aerodrome_label:z10_
|
|
osm_id,
|
|
geometry,
|
|
name,
|
|
COALESCE(NULLIF(name_en, ''), name) AS name_en,
|
|
COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de,
|
|
tags,
|
|
CASE
|
|
%%FIELD_MAPPING: class %%
|
|
ELSE 'other'
|
|
END AS class,
|
|
NULLIF(iata, '') AS iata,
|
|
NULLIF(icao, '') AS icao,
|
|
substring(ele FROM E'^(-?\\d+)(\\D|$)')::int AS ele,
|
|
round(substring(ele FROM E'^(-?\\d+)(\\D|$)')::int * 3.2808399)::int AS ele_ft
|
|
FROM osm_aerodrome_label_point
|
|
WHERE geometry && bbox
|
|
AND zoom_level >= 10;
|
|
$$ LANGUAGE SQL STABLE
|
|
-- STRICT
|
|
PARALLEL SAFE;
|