]> git.openstreetmap.org Git - nominatim.git/commitdiff
avoid index on rank_address in near search
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 22 Nov 2023 16:33:17 +0000 (17:33 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 22 Nov 2023 16:33:17 +0000 (17:33 +0100)
nominatim/api/search/db_searches.py

index 97c4292e56710ea22fe3d10fd48e9dc6bb8d04c5..62e9a450288ab15fd0df270b94bc343e9d440b4a 100644 (file)
@@ -24,6 +24,13 @@ from nominatim.db.sqlalchemy_types import Geometry
 #pylint: disable=singleton-comparison,not-callable
 #pylint: disable=too-many-branches,too-many-arguments,too-many-locals,too-many-statements
 
+def no_index(expr: SaColumn) -> SaColumn:
+    """ Wrap the given expression, so that the query planner will
+        refrain from using the expression for index lookup.
+    """
+    return sa.func.coalesce(sa.null(), expr) # pylint: disable=not-callable
+
+
 def _details_to_bind_params(details: SearchDetails) -> Dict[str, Any]:
     """ Create a dictionary from search parameters that can be used
         as bind parameter for SQL execute.
@@ -295,7 +302,7 @@ class NearSearch(AbstractSearch):
                                        else_ = tgeom.c.centroid.ST_Expand(0.05))))\
                      .order_by(tgeom.c.centroid.ST_Distance(table.c.centroid))
 
-        sql = sql.where(t.c.rank_address.between(MIN_RANK_PARAM, MAX_RANK_PARAM))
+        sql = sql.where(no_index(t.c.rank_address).between(MIN_RANK_PARAM, MAX_RANK_PARAM))
         if details.countries:
             sql = sql.where(t.c.country_code.in_(COUNTRIES_PARAM))
         if details.excluded: