summary refs log tree commit diff
path: root/synapse/storage/database.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2021-04-08 13:45:19 +0100
committerRichard van der Hoff <richard@matrix.org>2021-04-08 16:42:32 +0100
commit3ada9b42640137d908fa2db64e78f3f79d11dd3a (patch)
treef27106f38f792717c64eb1b885fbed49f5a6ae30 /synapse/storage/database.py
parentRequire py36 and Postgres 9.6 (diff)
downloadsynapse-3ada9b42640137d908fa2db64e78f3f79d11dd3a.tar.xz
Drop support for sqlite<3.22 as well
Diffstat (limited to 'synapse/storage/database.py')
-rw-r--r--synapse/storage/database.py62
1 files changed, 7 insertions, 55 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py
index 94590e7b45..a2f016a7ef 100644
--- a/synapse/storage/database.py
+++ b/synapse/storage/database.py
@@ -2060,68 +2060,20 @@ KV = TypeVar("KV")
 
 
 def make_tuple_comparison_clause(
-    database_engine: BaseDatabaseEngine, keys: List[Tuple[str, KV]]
+    _database_engine: BaseDatabaseEngine, keys: List[Tuple[str, KV]]
 ) -> Tuple[str, List[KV]]:
     """Returns a tuple comparison SQL clause
 
-    Depending what the SQL engine supports, builds a SQL clause that looks like either
-    "(a, b) > (?, ?)", or "(a > ?) OR (a == ? AND b > ?)".
+    Builds a SQL clause that looks like "(a, b) > (?, ?)"
 
     Args:
-        database_engine
+        _database_engine
         keys: A set of (column, value) pairs to be compared.
 
     Returns:
         A tuple of SQL query and the args
     """
-    if database_engine.supports_tuple_comparison:
-        return (
-            "(%s) > (%s)" % (",".join(k[0] for k in keys), ",".join("?" for _ in keys)),
-            [k[1] for k in keys],
-        )
-
-    # we want to build a clause
-    #    (a > ?) OR
-    #    (a == ? AND b > ?) OR
-    #    (a == ? AND b == ? AND c > ?)
-    #    ...
-    #    (a == ? AND b == ? AND ... AND z > ?)
-    #
-    # or, equivalently:
-    #
-    #  (a > ? OR (a == ? AND
-    #    (b > ? OR (b == ? AND
-    #      ...
-    #        (y > ? OR (y == ? AND
-    #          z > ?
-    #        ))
-    #      ...
-    #    ))
-    #  ))
-    #
-    # which itself is equivalent to (and apparently easier for the query optimiser):
-    #
-    #  (a >= ? AND (a > ? OR
-    #    (b >= ? AND (b > ? OR
-    #      ...
-    #        (y >= ? AND (y > ? OR
-    #          z > ?
-    #        ))
-    #      ...
-    #    ))
-    #  ))
-    #
-    #
-
-    clause = ""
-    args = []  # type: List[KV]
-    for k, v in keys[:-1]:
-        clause = clause + "(%s >= ? AND (%s > ? OR " % (k, k)
-        args.extend([v, v])
-
-    (k, v) = keys[-1]
-    clause += "%s > ?" % (k,)
-    args.append(v)
-
-    clause += "))" * (len(keys) - 1)
-    return clause, args
+    return (
+        "(%s) > (%s)" % (",".join(k[0] for k in keys), ",".join("?" for _ in keys)),
+        [k[1] for k in keys],
+    )