diff --git a/backend/field_update b/backend/field_update index 22e04050..7561d771 100644 --- a/backend/field_update +++ b/backend/field_update @@ -112,7 +112,6 @@ class Database: # catch exception for invalid SQL statement try: - self.cursor.execute(query) self.conn.commit() # print(query) @@ -180,7 +179,6 @@ class Raw: ): """Function that updates column of table""" if insert_type.lower() == "array": - select_query = f"""WITH t1 AS ( SELECT @@ -194,10 +192,10 @@ class Raw: t2 AS ( SELECT t1.osm_id, - array_agg(cg.{source_column}) AS aa_fids + COALESCE(array_agg(cg.{source_column}),ARRAY[0]::integer[]) AS aa_fids FROM t1 - INNER JOIN + LEFT JOIN {source_table} cg ON ST_Intersects(t1.geom, cg.{source_geom}) GROUP BY t1.osm_id @@ -223,13 +221,13 @@ class Raw: update {target_table} as wp SET - {target_column} = ( + {target_column} = COALESCE(( select cu.{source_column} from {source_table} cu where ST_Intersects(tf.{target_geom},cu.{source_geom}) LIMIT 1 - )::int + )::int,0::int) from table_filtered tf where wp.osm_id = tf.osm_id""" diff --git a/backend/replication b/backend/replication index cb253341..40da1a5a 100644 --- a/backend/replication +++ b/backend/replication @@ -534,7 +534,7 @@ def update_country(conn, timestamp, table_name, c_id=None, boundary=None): update_query = f"""update {table_name} as w set - country = array(( + country = COALESCE(array(( select b.id from @@ -542,7 +542,7 @@ def update_country(conn, timestamp, table_name, c_id=None, boundary=None): where ST_Intersects( ST_Centroid(w.geom) , b.geometry) - )) + )),ARRAY[0]::integer[]) where "timestamp" >= '{timestamp}'""" cur.execute(update_query) LOG.info( diff --git a/backend/sql/post_indexes.sql b/backend/sql/post_indexes.sql index dc52e530..4448f117 100644 --- a/backend/sql/post_indexes.sql +++ b/backend/sql/post_indexes.sql @@ -37,7 +37,21 @@ CREATE INDEX IF NOT EXISTS ways_poly_geom_idx ON public.ways_poly USING gist (g CREATE INDEX IF NOT EXISTS relations_geom_idx ON public.relations USING gist (geom); CREATE INDEX IF NOT EXISTS relations_country_idx ON public.relations USING gin (country gin__int_ops); +CREATE INDEX IF NOT EXISTS relations_tags_idx ON public.relations USING gin (tags); +-- External Indexes + +-- CREATE INDEX IF NOT EXISTS nodes_uid_idx ON public.nodes USING btree (uid); +-- CREATE INDEX IF NOT EXISTS nodes_changeset_idx ON public.nodes USING btree (changeset); + +-- CREATE INDEX IF NOT EXISTS ways_line_uid_idx ON public.ways_line USING btree (uid); +-- CREATE INDEX IF NOT EXISTS ways_line_changeset_idx ON public.ways_line USING btree (changeset); + +-- CREATE INDEX IF NOT EXISTS ways_poly_uid_idx ON public.ways_poly USING btree (uid); +-- CREATE INDEX IF NOT EXISTS ways_poly_changeset_idx ON public.ways_poly USING btree (changeset); + +-- CREATE INDEX IF NOT EXISTS relations_uid_idx ON public.relations USING btree (uid); +-- CREATE INDEX IF NOT EXISTS relations_changeset_idx ON public.relations USING btree (changeset); -- clustering nodes CLUSTER nodes USING nodes_geom_idx; @@ -45,6 +59,9 @@ CLUSTER nodes USING nodes_geom_idx; CLUSTER ways_line USING ways_line_geom_idx; -- clustering ways_poly CLUSTER ways_poly USING ways_poly_geom_idx; +-- clustering relations +CLUSTER relations USING relations_geom_idx; + -- VACUUM the table to reclaim disk space @@ -58,3 +75,5 @@ ANALYZE nodes; ANALYZE ways_line; ANALYZE ways_poly; ANALYZE relations; + + diff --git a/backend/sql/pre_indexes.sql b/backend/sql/pre_indexes.sql index 85fecb1f..39d7b1fd 100644 --- a/backend/sql/pre_indexes.sql +++ b/backend/sql/pre_indexes.sql @@ -18,18 +18,6 @@ -- # 1100 13th Street NW Suite 800 Washington, D.C. 20005 -- # --- CREATE INDEX IF NOT EXISTS nodes_uid_idx ON public.nodes USING btree (uid); --- CREATE INDEX IF NOT EXISTS nodes_changeset_idx ON public.nodes USING btree (changeset); - --- CREATE INDEX IF NOT EXISTS ways_line_uid_idx ON public.ways_line USING btree (uid); --- CREATE INDEX IF NOT EXISTS ways_line_changeset_idx ON public.ways_line USING btree (changeset); - --- CREATE INDEX IF NOT EXISTS ways_poly_uid_idx ON public.ways_poly USING btree (uid); --- CREATE INDEX IF NOT EXISTS ways_poly_changeset_idx ON public.ways_poly USING btree (changeset); - --- CREATE INDEX IF NOT EXISTS relations_uid_idx ON public.relations USING btree (uid); --- CREATE INDEX IF NOT EXISTS relations_changeset_idx ON public.relations USING btree (changeset); - CREATE EXTENSION IF NOT EXISTS btree_gist; CREATE EXTENSION IF NOT EXISTS postgis; @@ -53,8 +41,6 @@ CREATE INDEX IF NOT EXISTS ways_line_timestamp_idx ON public.ways_line USING btr CREATE INDEX IF NOT EXISTS ways_poly_timestamp_idx ON public.ways_poly USING btree ("timestamp"); -CREATE INDEX IF NOT EXISTS relations_tags_idx ON public.relations USING gin (tags); - CREATE INDEX IF NOT EXISTS relations_timestamp_idx ON public.relations USING btree ("timestamp"); diff --git a/src/query_builder/builder.py b/src/query_builder/builder.py index 056c840b..005f81fd 100644 --- a/src/query_builder/builder.py +++ b/src/query_builder/builder.py @@ -37,7 +37,7 @@ def get_grid_id_query(geometry_dump): def get_country_id_query(geom_dump): base_query = f"""select - b.id::int as fid + COALESCE(b.id::int, 0) as fid from countries b where