From: Sarah Hoffmann Date: Mon, 29 Jan 2024 15:52:14 +0000 (+0100) Subject: avoid LookupAny with address and too many name tokens X-Git-Tag: v4.4.0~21 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/33c0f249b1a9bc716bcb89078c4a766766cbe94f?hp=--cc avoid LookupAny with address and too many name tokens The index for nameaddress_vector has grown so large that PostgreSQL will resort to a sequential scan if there are too many items in the LookupAny list. --- 33c0f249b1a9bc716bcb89078c4a766766cbe94f diff --git a/nominatim/api/search/db_search_builder.py b/nominatim/api/search/db_search_builder.py index 3d5796c5..f2b653f2 100644 --- a/nominatim/api/search/db_search_builder.py +++ b/nominatim/api/search/db_search_builder.py @@ -176,11 +176,12 @@ class SearchBuilder: sdata.lookups.append(dbf.FieldLookup('nameaddress_vector', list(partials), lookups.LookupAll)) else: + addr_fulls = [t.token for t + in self.query.get_tokens(address[0], TokenType.WORD)] + if len(addr_fulls) > 5: + return sdata.lookups.append( - dbf.FieldLookup('nameaddress_vector', - [t.token for t - in self.query.get_tokens(address[0], TokenType.WORD)], - lookups.LookupAny)) + dbf.FieldLookup('nameaddress_vector', addr_fulls, lookups.LookupAny)) sdata.housenumbers = dbf.WeightedStrings([], []) yield dbs.PlaceSearch(0.05, sdata, expected_count)