]> git.openstreetmap.org Git - nominatim.git/commitdiff
add prepared statement
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 19 Jan 2020 13:06:48 +0000 (14:06 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 24 Jan 2020 21:06:30 +0000 (22:06 +0100)
nominatim/nominatim.py

index 610e3de207c7542862c53d8b36c4023614855c7b..023b4b23b9ff2fa6614e29ad6130cbd82269c5b8 100644 (file)
@@ -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():