From 116dfef6b360595e08a0aa971946d3f45abdedd0 Mon Sep 17 00:00:00 2001 From: Itz-Agasta Date: Thu, 9 Jul 2026 11:49:32 +0530 Subject: [PATCH] Index placex(class,type) for the SQLite category search SQLite has no ltree, so category search matches on class/type there and needs a matching composite index. --- src/nominatim_db/tools/convert_sqlite.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nominatim_db/tools/convert_sqlite.py b/src/nominatim_db/tools/convert_sqlite.py index e3dae900..9ac5ca31 100644 --- a/src/nominatim_db/tools/convert_sqlite.py +++ b/src/nominatim_db/tools/convert_sqlite.py @@ -185,6 +185,8 @@ class SqliteWriter: await self.create_index('search_name', 'place_id') await self.create_index('osmline', 'parent_place_id') await self.create_index('tiger', 'parent_place_id') + # SQLite has no ltree, so category search matches on class/type. + await self.create_index('placex', 'class_', 'type') await self.create_search_index() for t in self.dest.t.meta.tables: @@ -198,12 +200,13 @@ class SqliteWriter: await self.dest.execute(sa.select( sa.func.CreateSpatialIndex(getattr(self.dest.t, table).name, column))) - async def create_index(self, table_name: str, column: str) -> None: - """ Create a simple index on the given table and column. + async def create_index(self, table_name: str, *columns: str) -> None: + """ Create a simple index on the given table and columns. """ table = getattr(self.dest.t, table_name) + cols = [getattr(table.c, column) for column in columns] await self.dest.connection.run_sync( - sa.Index(f"idx_{table}_{column}", getattr(table.c, column)).create) + sa.Index(f"idx_{table}_{'_'.join(c.name for c in cols)}", *cols).create) async def create_search_index(self) -> None: """ Create the tables and indexes needed for word lookup. -- 2.47.3