From c11d1d78e90c1c7338ad9e67ae2c457773452aa5 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 19 Jan 2020 14:06:48 +0100 Subject: [PATCH] add prepared statement --- nominatim/nominatim.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nominatim/nominatim.py b/nominatim/nominatim.py index 610e3de2..023b4b23 100644 --- a/nominatim/nominatim.py +++ b/nominatim/nominatim.py @@ -50,6 +50,10 @@ class IndexingThread(object): self.cursor = self.conn.cursor() self.perform("SET lc_messages TO 'C'") self.wait() + self.perform(InterpolationRunner.prepare()) + self.wait() + self.perform(RankRunner.prepare()) + self.wait() self.current_query = None @@ -74,7 +78,7 @@ class IndexingThread(object): raise RuntimeError("Postgres exception has no error code") if e.pgcode == '40P01': log.info("Deadlock detected, retry.") - self.cursor.execute(sql) + self.cursor.execute(self.sql) else: raise @@ -177,6 +181,12 @@ class RankRunner(object): def name(self): return "rank {}".format(self.rank) + @classmethod + def prepare(cls): + return """PREPARE rnk_index AS + UPDATE placex + SET indexed_status = 0 WHERE place_id = $1""" + def sql_index_sectors(self): return """SELECT geometry_sector, count(*) FROM placex WHERE rank_search = {} and indexed_status > 0 @@ -194,7 +204,7 @@ class RankRunner(object): ORDER BY geometry_sector""" def sql_index_place(self): - return "UPDATE placex SET indexed_status = 0 WHERE place_id = %s" + return "EXECUTE rnk_index(%s)" class InterpolationRunner(object): @@ -202,6 +212,12 @@ class InterpolationRunner(object): def name(self): return "interpolation lines (location_property_osmline)" + @classmethod + def prepare(cls): + return """PREPARE ipl_index AS + UPDATE location_property_osmline + SET indexed_status = 0 WHERE place_id = $1""" + def sql_index_sectors(self): return """SELECT geometry_sector, count(*) FROM location_property_osmline WHERE indexed_status > 0 @@ -219,8 +235,7 @@ class InterpolationRunner(object): ORDER BY geometry_sector""" def sql_index_place(self): - return """UPDATE location_property_osmline - SET indexed_status = 0 WHERE place_id = %s""" + return "EXECUTE ipl_index(%s)" def nominatim_arg_parser(): -- 2.39.5