reorganise layout of location_postcode table

Also renames the table as this will make it easier to migrate.
This commit is contained in:
Sarah Hoffmann
2025-12-23 12:13:19 +01:00
parent 7ef3f99fa4
commit 89821d01e0
14 changed files with 69 additions and 53 deletions

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2024 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
SQLAlchemy definitions for all tables used by the frontend.
@@ -67,15 +67,16 @@ class SearchTables:
sa.Column('isaddress', sa.Boolean))
self.postcode = sa.Table(
'location_postcode', meta,
'location_postcodes', meta,
sa.Column('place_id', sa.BigInteger),
sa.Column('parent_place_id', sa.BigInteger),
sa.Column('osm_id', sa.BigInteger),
sa.Column('rank_search', sa.SmallInteger),
sa.Column('rank_address', sa.SmallInteger),
sa.Column('indexed_status', sa.SmallInteger),
sa.Column('indexed_date', sa.DateTime),
sa.Column('country_code', sa.String(2)),
sa.Column('postcode', sa.Text),
sa.Column('centroid', Geometry),
sa.Column('geometry', Geometry))
self.osmline = sa.Table(

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2024 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Main work horse for indexing (computing addresses) the database.
@@ -154,7 +154,7 @@ class Indexer:
return total
async def index_postcodes(self) -> int:
"""Index the entries of the location_postcode table.
"""Index the entries of the location_postcodes table.
"""
LOG.warning("Starting indexing postcodes using %s threads", self.num_threads)

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2024 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Mix-ins that provide the actual commands for the indexer for various indexing
@@ -143,22 +143,22 @@ class InterpolationRunner:
class PostcodeRunner(Runner):
""" Provides the SQL commands for indexing the location_postcode table.
""" Provides the SQL commands for indexing the location_postcodes table.
"""
def name(self) -> str:
return "postcodes (location_postcode)"
return "postcodes (location_postcodes)"
def sql_count_objects(self) -> Query:
return 'SELECT count(*) FROM location_postcode WHERE indexed_status > 0'
return 'SELECT count(*) FROM location_postcodes WHERE indexed_status > 0'
def sql_get_objects(self) -> Query:
return """SELECT place_id FROM location_postcode
return """SELECT place_id FROM location_postcodes
WHERE indexed_status > 0
ORDER BY country_code, postcode"""
def index_places_query(self, batch_size: int) -> Query:
return pysql.SQL("""UPDATE location_postcode SET indexed_status = 0
return pysql.SQL("""UPDATE location_postcodes SET indexed_status = 0
WHERE place_id IN ({})""")\
.format(pysql.SQL(',').join((pysql.Placeholder() for _ in range(batch_size))))

View File

@@ -71,7 +71,7 @@ class AbstractAnalyzer(ABC):
@abstractmethod
def update_postcodes_from_db(self) -> None:
""" Update the tokenizer's postcode tokens from the current content
of the `location_postcode` table.
of the `location_postcodes` table.
"""
@abstractmethod

View File

@@ -113,8 +113,8 @@ def _get_indexes(conn: Connection) -> List[str]:
'idx_placex_geometry_placenode',
'idx_osmline_parent_place_id',
'idx_osmline_parent_osm_id',
'idx_postcode_id',
'idx_postcode_postcode'
'idx_location_postcodes_id',
'idx_location_postcodes_postcode'
]
# These won't exist if --reverse-only import was used

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2024 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for setting up and importing a new Nominatim database.
@@ -183,7 +183,7 @@ def truncate_data_tables(conn: Connection) -> None:
cur.execute('TRUNCATE location_area_country')
cur.execute('TRUNCATE location_property_tiger')
cur.execute('TRUNCATE location_property_osmline')
cur.execute('TRUNCATE location_postcode')
cur.execute('TRUNCATE location_postcodes')
if table_exists(conn, 'search_name'):
cur.execute('TRUNCATE search_name')
cur.execute('DROP SEQUENCE IF EXISTS seq_place')