Improved update performance of place layer (#1509)

Improved update performance of place layer
- Refactored IDs to be unique in the following tables
  - place_city.osm_ids
  - place_continent_point.osm_ids
  - place_country.osm_ids
  - place_island_point.osm_ids
  - place_island_polygon.osm_ids
  - place_state.osm_ids
- Added analyze statements before update queries and restricted updates to INSERT and UPDATE operations during execution of the following functions
  - place_city.refresh
  - place_continent_point.refresh
  - place_country.refresh
  - place_island_point.refresh
  - place_island_polygon.refresh
  - place_state.refresh
This commit is contained in:
benedikt-brandtner-bikemap
2023-03-22 14:00:10 +01:00
committed by GitHub
parent 1126e30d0d
commit 3caa11aee9
6 changed files with 54 additions and 48 deletions

View File

@@ -6,7 +6,7 @@ CREATE SCHEMA IF NOT EXISTS place_country;
CREATE TABLE IF NOT EXISTS place_country.osm_ids
(
osm_id bigint
osm_id bigint PRIMARY KEY
);
-- etldoc: ne_10m_admin_0_countries -> osm_country_point
@@ -105,11 +105,7 @@ CREATE INDEX IF NOT EXISTS osm_country_point_rank_idx ON osm_country_point ("ran
CREATE OR REPLACE FUNCTION place_country.store() RETURNS trigger AS
$$
BEGIN
IF (tg_op = 'DELETE') THEN
INSERT INTO place_country.osm_ids VALUES (OLD.osm_id);
ELSE
INSERT INTO place_country.osm_ids VALUES (NEW.osm_id);
END IF;
INSERT INTO place_country.osm_ids VALUES (NEW.osm_id) ON CONFLICT (osm_id) DO NOTHING;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
@@ -134,6 +130,11 @@ DECLARE
t TIMESTAMP WITH TIME ZONE := clock_timestamp();
BEGIN
RAISE LOG 'Refresh place_country rank';
-- Analyze tracking and source tables before performing update
ANALYZE place_country.osm_ids;
ANALYZE osm_country_point;
PERFORM update_osm_country_point(false);
-- noinspection SqlWithoutWhere
DELETE FROM place_country.osm_ids;
@@ -146,13 +147,13 @@ END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trigger_store
AFTER INSERT OR UPDATE OR DELETE
AFTER INSERT OR UPDATE
ON osm_country_point
FOR EACH ROW
EXECUTE PROCEDURE place_country.store();
CREATE TRIGGER trigger_flag
AFTER INSERT OR UPDATE OR DELETE
AFTER INSERT OR UPDATE
ON osm_country_point
FOR EACH STATEMENT
EXECUTE PROCEDURE place_country.flag();