diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2021-04-08 19:29:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-08 19:29:03 +0100 |
commit | 64f4f506c5ac2595b670fd37255dd1be485e6018 (patch) | |
tree | e5578a06584477e553b8e0eea11c3aa1f40dc2b5 /synapse/storage/database.py | |
parent | Merge pull request #9769 from matrix-org/rav/fix_bionic (diff) | |
parent | Merge remote-tracking branch 'origin/develop' into rav/drop_py35 (diff) | |
download | synapse-64f4f506c5ac2595b670fd37255dd1be485e6018.tar.xz |
Merge pull request #9766 from matrix-org/rav/drop_py35
Require py36, Postgres 9.6, and sqlite 3.22
Diffstat (limited to 'synapse/storage/database.py')
-rw-r--r-- | synapse/storage/database.py | 63 |
1 files changed, 6 insertions, 57 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 94590e7b45..b302cd5786 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -2059,69 +2059,18 @@ def make_in_list_sql_clause( KV = TypeVar("KV") -def make_tuple_comparison_clause( - database_engine: BaseDatabaseEngine, keys: List[Tuple[str, KV]] -) -> Tuple[str, List[KV]]: +def make_tuple_comparison_clause(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 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], + ) |