Skip to content

Commit

Permalink
Optimize signals table and related materialized views (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddewie authored Nov 16, 2024
1 parent 94db0b1 commit 217c066
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions import/docker-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ $PSQL --tuples-only -c "with bounds as (SELECT st_transform(st_setsrid(ST_Extent
echo "Import bounds: $(cat /data/import/bounds.json)"

echo "Database summary"
$PSQL -c "select table_name as table, pg_size_pretty(pg_total_relation_size(quote_ident(table_name))) as size from information_schema.tables where table_schema = 'public' order by table_name;"
$PSQL -c "select pg_size_pretty(sum(pg_total_relation_size(quote_ident(table_name)))) as total_size from information_schema.tables where table_schema = 'public';"
$PSQL -c "select concat(relname, ' (', relkind ,')') as name, pg_size_pretty(pg_table_size(oid)) as size from pg_class where relkind in ('m', 'r', 'i') and relname not like 'pg_%' order by pg_table_size(oid) desc;"
$PSQL -c "select pg_size_pretty(SUM(pg_table_size(oid))) as size from pg_class where relkind in ('m', 'r', 'i') and relname not like 'pg_%';"
2 changes: 2 additions & 0 deletions import/openrailwaymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ local signals = osm2pgsql.define_table({
name = 'signals',
ids = { type = 'node', id_column = 'osm_id' },
columns = signal_columns,
-- The queried table is signals_with_azimuth
cluster = 'no',
})

local boxes = osm2pgsql.define_table({
Expand Down
8 changes: 6 additions & 2 deletions import/sql/signals_with_azimuth.sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ CREATE OR REPLACE VIEW signals_with_azimuth_view AS
) as sl ON true
WHERE
(railway IN ('signal', 'buffer_stop') AND signal_direction IS NOT NULL)
OR railway IN ('derail', 'vacancy_detection');
OR railway IN ('derail', 'vacancy_detection');
-- Use the view directly such that the query in the view can be updated
CREATE MATERIALIZED VIEW IF NOT EXISTS signals_with_azimuth AS
SELECT
*
FROM
signals_with_azimuth_view;
signals_with_azimuth_view
WHERE
signal_feature IS NOT NULL
OR speed_feature IS NOT NULL
OR electrification_feature IS NOT NULL;
CREATE INDEX IF NOT EXISTS signals_with_azimuth_geom_index
ON signals_with_azimuth
Expand Down
2 changes: 1 addition & 1 deletion import/sql/tile_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ CREATE OR REPLACE VIEW speed_railway_signals AS
speed_feature_type as type,
azimuth,
(signal_direction = 'both') as direction_both
FROM signals_with_azimuth s
FROM signals_with_azimuth
WHERE railway = 'signal'
AND speed_feature IS NOT NULL
ORDER BY
Expand Down

0 comments on commit 217c066

Please sign in to comment.