]> git.openstreetmap.org Git - nominatim.git/commitdiff
disable prepared statements
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 28 Mar 2023 12:53:45 +0000 (14:53 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 28 Mar 2023 12:53:45 +0000 (14:53 +0200)
Prepared statements do not work well with the partial indexes that
Nominatim uses because all Python constants are replaced with
parameters. A query like:

  placex.select().where(placex.c.rank_address.between(4, 25)

gets translated into a prepared query with two parameters:

  SELECT * FROM placex WHERE rank_address BETWEEN %s and %s

And this does not work with a partial index of:

  CREATE INDEX on placex(geometry) WHERE rank_address between 4 and 25

nominatim/api/core.py

index 116a2625c76028a4e4d3de1d9358b82b509b3653..6d47d332371fffd1cbfae42deecfe695848e04ec 100644 (file)
@@ -53,13 +53,16 @@ class NominatimAPIAsync:
 
             dsn = self.config.get_database_params()
 
+            query = {k: v for k, v in dsn.items()
+                      if k not in ('user', 'password', 'dbname', 'host', 'port')}
+            query['prepared_statement_cache_size'] = '0'
+
             dburl = sa.engine.URL.create(
                        'postgresql+asyncpg',
                        database=dsn.get('dbname'),
                        username=dsn.get('user'), password=dsn.get('password'),
                        host=dsn.get('host'), port=int(dsn['port']) if 'port' in dsn else None,
-                       query={k: v for k, v in dsn.items()
-                              if k not in ('user', 'password', 'dbname', 'host', 'port')})
+                       query=query)
             engine = sa_asyncio.create_async_engine(
                              dburl, future=True,
                              connect_args={'server_settings': {