summary refs log tree commit diff
path: root/synapse/storage/schema
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-01-23 11:26:27 +0000
committerGitHub <noreply@github.com>2024-01-23 11:26:27 +0000
commit14c725f73b1e4da37566def0491670009d718539 (patch)
tree6ec594ef8162a4d1a465733f5a99fb18ac31bbea /synapse/storage/schema
parentAdd a `--generate-only` option to the Complement launcher. (#16828) (diff)
downloadsynapse-14c725f73b1e4da37566def0491670009d718539.tar.xz
Preparatory work for tweaking performance of auth chain lookups (#16833)
Diffstat (limited to 'synapse/storage/schema')
-rw-r--r--synapse/storage/schema/__init__.py2
-rw-r--r--synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres18
-rw-r--r--synapse/storage/schema/main/delta/84/02_auth_links_index.sql16
3 files changed, 35 insertions, 1 deletions
diff --git a/synapse/storage/schema/__init__.py b/synapse/storage/schema/__init__.py
index 132c781f51..ebdf6d95af 100644
--- a/synapse/storage/schema/__init__.py
+++ b/synapse/storage/schema/__init__.py
@@ -18,7 +18,7 @@
 #
 #
 
-SCHEMA_VERSION = 83  # remember to update the list below when updating
+SCHEMA_VERSION = 84  # remember to update the list below when updating
 """Represents the expectations made by the codebase about the database schema
 
 This should be incremented whenever the codebase changes its requirements on the
diff --git a/synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres b/synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres
new file mode 100644
index 0000000000..b0b41bd106
--- /dev/null
+++ b/synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres
@@ -0,0 +1,18 @@
+--
+-- This file is licensed under the Affero General Public License (AGPL) version 3.
+--
+-- Copyright (C) 2023 New Vector, Ltd
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as
+-- published by the Free Software Foundation, either version 3 of the
+-- License, or (at your option) any later version.
+--
+-- See the GNU Affero General Public License for more details:
+-- <https://www.gnu.org/licenses/agpl-3.0.html>.
+
+-- Force the statistics for these tables to show that the number of distinct
+-- chain IDs are proportional to the total rows, as postgres has trouble
+-- figuring that out by itself.
+ALTER TABLE event_auth_chain_links ALTER origin_chain_id SET (n_distinct = -0.5);
+ALTER TABLE event_auth_chain_links ALTER target_chain_id SET (n_distinct = -0.5);
diff --git a/synapse/storage/schema/main/delta/84/02_auth_links_index.sql b/synapse/storage/schema/main/delta/84/02_auth_links_index.sql
new file mode 100644
index 0000000000..6936e3d05b
--- /dev/null
+++ b/synapse/storage/schema/main/delta/84/02_auth_links_index.sql
@@ -0,0 +1,16 @@
+--
+-- This file is licensed under the Affero General Public License (AGPL) version 3.
+--
+-- Copyright (C) 2023 New Vector, Ltd
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as
+-- published by the Free Software Foundation, either version 3 of the
+-- License, or (at your option) any later version.
+--
+-- See the GNU Affero General Public License for more details:
+-- <https://www.gnu.org/licenses/agpl-3.0.html>.
+
+
+INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
+    (8402, 'event_auth_chain_links_origin_index', '{}');