From 523fcbbaa5797a84ad4d14267f299854aae9fdbf Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 23 Jan 2025 20:52:46 -0500 Subject: [PATCH] Create unique index for material view --- images/tiler-imposm/materialized_views.py | 26 +++++++++++------------ images/tiler-server/utils/exec.sh | 5 +++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/images/tiler-imposm/materialized_views.py b/images/tiler-imposm/materialized_views.py index da268a96..b58510d3 100644 --- a/images/tiler-imposm/materialized_views.py +++ b/images/tiler-imposm/materialized_views.py @@ -70,24 +70,23 @@ def get_columns_of_table(table_name: str) -> list: columns = [col.strip() for col in result.stdout.strip().split("\n") if col.strip()] return columns - def create_indexes_for_mview(mview_name: str, columns: list): """ - Creates indexes for 'osm_id' (B-Tree) and 'geometry' (GiST) in the specified materialized view, - only if those columns exist. + Creates indexes for the 'osm_id' (B-Tree) and 'geometry' (GiST) columns. """ - # Check if the columns exist + + # Ensure 'osm_id' exists in the columns list if "osm_id" in columns: - create_idx_osm = f"CREATE INDEX idx_{mview_name}_osm_id ON {mview_name} (osm_id);" - logger.info(f"Creating index for osm_id in {mview_name}") - execute_psql_query(create_idx_osm) + create_unique_idx = f"CREATE UNIQUE INDEX IF NOT EXISTS idx_{mview_name}_osm_id ON {mview_name} (osm_id);" + logger.info(f"Creating unique index for osm_id in {mview_name}") + execute_psql_query(create_unique_idx) + else: + logger.warning(f"'osm_id' column not found in {mview_name}, skipping unique index creation.") if "geometry" in columns: - create_idx_geom = ( - f"CREATE INDEX idx_{mview_name}_geom ON {mview_name} USING GIST (geometry);" - ) - logger.info(f"Creating index for geometry in {mview_name}") - execute_psql_query(create_idx_geom) + create_geom_idx = f"CREATE INDEX IF NOT EXISTS idx_{mview_name}_geom ON {mview_name} USING GIST (geometry);" + logger.info(f"Creating GiST index for geometry in {mview_name}") + execute_psql_query(create_geom_idx) def create_materialized_view( @@ -204,12 +203,11 @@ def refresh_all_materialized_views(config_dict: dict): mview_name = mt_view.get("view") if object_exists(mview_name): logger.info(f"Refreshing materialized view: {mview_name}") - query = f"REFRESH MATERIALIZED VIEW {mview_name};" + query = f"REFRESH MATERIALIZED VIEW CONCURRENTLY {mview_name};" execute_psql_query(query) else: logger.warning(f"Materialized view {mview_name} not found. Skipping refresh.") - # ------------------------------------------------------------------------------ # MAIN: LOADS CONFIG ONCE, CREATES/UPDATES VIEWS, THEN REFRESHES THEM IN A LOOP # ------------------------------------------------------------------------------ diff --git a/images/tiler-server/utils/exec.sh b/images/tiler-server/utils/exec.sh index 783d1cce..4f8ec99d 100755 --- a/images/tiler-server/utils/exec.sh +++ b/images/tiler-server/utils/exec.sh @@ -1,4 +1,5 @@ -python query_benchmarking.py \ +python3 query_benchmarking.py \ --toml ./../config/config.toml \ --bbox 1.3149614848125e+07,2.5046885425000004e+06,1.3775786983749997e+07,3.1308606781250015e+06,3857 \ - --zoom 6 \ No newline at end of file + --zoom 6 + \ No newline at end of file