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_state;
CREATE TABLE IF NOT EXISTS place_state.osm_ids
(
osm_id bigint
osm_id bigint PRIMARY KEY
);
-- etldoc: ne_10m_admin_1_states_provinces -> osm_state_point
@@ -67,11 +67,7 @@ CREATE INDEX IF NOT EXISTS osm_state_point_rank_idx ON osm_state_point ("rank");
CREATE OR REPLACE FUNCTION place_state.store() RETURNS trigger AS
$$
BEGIN
IF (tg_op = 'DELETE') THEN
INSERT INTO place_state.osm_ids VALUES (OLD.osm_id);
ELSE
INSERT INTO place_state.osm_ids VALUES (NEW.osm_id);
END IF;
INSERT INTO place_state.osm_ids VALUES (NEW.osm_id) ON CONFLICT (osm_id) DO NOTHING;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
@@ -96,6 +92,11 @@ DECLARE
t TIMESTAMP WITH TIME ZONE := clock_timestamp();
BEGIN
RAISE LOG 'Refresh place_state rank';
-- Analyze tracking and source tables before performing update
ANALYZE place_state.osm_ids;
ANALYZE osm_state_point;
PERFORM update_osm_state_point(false);
-- noinspection SqlWithoutWhere
DELETE FROM place_state.osm_ids;
@@ -108,13 +109,13 @@ END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trigger_store
AFTER INSERT OR UPDATE OR DELETE
AFTER INSERT OR UPDATE
ON osm_state_point
FOR EACH ROW
EXECUTE PROCEDURE place_state.store();
CREATE TRIGGER trigger_flag
AFTER INSERT OR UPDATE OR DELETE
AFTER INSERT OR UPDATE
ON osm_state_point
FOR EACH STATEMENT
EXECUTE PROCEDURE place_state.flag();