This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Clean up schema for event_edges
#12893
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eaa47cf
Remove redundant references to `event_edges.room_id`
richvdh 4bc172f
Clean up the event_edges table
richvdh 9c70e88
Stop populateing `event_edges.room_id` and `is_state`
richvdh d885adc
changelog
richvdh aa3a170
Add a comment
richvdh b301385
remove spurious newlines
richvdh 62861e6
Merge remote-tracking branch 'origin/develop' into rav/clean_up_event…
richvdh c074c49
bump SCHEMA_COMPAT_VERSION
richvdh f7607e9
Merge branch 'develop' into rav/clean_up_event_edges
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Simplify the database schema for `event_edges`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,10 +214,10 @@ def _purge_history_txn( | |
|
||
# Delete all remote non-state events | ||
for table in ( | ||
"event_edges", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to clean this before |
||
"events", | ||
"event_json", | ||
"event_auth", | ||
"event_edges", | ||
"event_forward_extremities", | ||
"event_relations", | ||
"event_search", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
synapse/storage/schema/main/delta/71/01rebuild_event_edges.sql.postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* Copyright 2022 The Matrix.org Foundation C.I.C | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
-- We're going to stop populating event_edges.room_id and event_edges.is_state, | ||
-- which means we now need to give them defaults. | ||
|
||
-- We also drop the exising unique constraint which spans all four columns. Franky | ||
-- it's not doing much, and there are other indexes on event_id and prev_event_id. | ||
-- Later on we introduce a proper unique constraint on (event_id, prev_event_id). | ||
-- | ||
-- We also add a foreign key constraint (which will be enforced for new rows), but | ||
-- don't yet validate it for existing rows (since that's slow, and we haven't yet | ||
-- checked that all the rows are valid) | ||
|
||
ALTER TABLE event_edges | ||
ALTER room_id DROP NOT NULL, | ||
ALTER is_state SET DEFAULT FALSE, | ||
DROP CONSTRAINT IF EXISTS event_edges_event_id_prev_event_id_room_id_is_state_key, | ||
ADD CONSTRAINT event_edges_event_id_fkey FOREIGN KEY (event_id) REFERENCES events(event_id) NOT VALID; | ||
|
||
-- In the background, we drop any rows with is_state=True. These may have been | ||
-- added a long time ago, but they are no longer used. | ||
-- | ||
-- We also drop rows that do not correspond to entries in `events`, and finally | ||
-- validate the foreign key. | ||
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES | ||
(7101, 'event_edges_drop_invalid_rows', '{}'); | ||
|
||
-- We'll then create a new unique index on (event_id, prev_event_id). | ||
INSERT INTO background_updates (ordering, update_name, progress_json, depends_on) VALUES | ||
(7101, 'event_edges_replace_index', '{}', 'event_edges_drop_invalid_rows'); |
47 changes: 47 additions & 0 deletions
47
synapse/storage/schema/main/delta/71/01rebuild_event_edges.sql.sqlite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Copyright 2022 The Matrix.org Foundation C.I.C | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
-- We're going to stop populating event_edges.room_id and event_edges.is_state, | ||
-- which means we now need to give them defaults. | ||
-- | ||
-- We also take the opportunity to: | ||
-- - drop any rows with is_state=True (these were populated a long time ago, but | ||
-- are no longer used.) | ||
-- - drop any rows which do not correspond to entries in `events` | ||
-- - tighten the unique index so that it applies just to (event_id, prev_event_id) | ||
-- - drop the "ev_edges_id" index, which is redundant to the above. | ||
-- - add a foreign key constraint from event_id to `events` | ||
|
||
CREATE TABLE new_event_edges ( | ||
event_id TEXT NOT NULL, | ||
prev_event_id TEXT NOT NULL, | ||
room_id TEXT NULL, | ||
is_state BOOL NOT NULL DEFAULT 0, | ||
FOREIGN KEY(event_id) REFERENCES events(event_id) | ||
); | ||
|
||
INSERT INTO new_event_edges | ||
SELECT ee.event_id, ee.prev_event_id, ee.room_id, ee.is_state | ||
FROM event_edges ee JOIN events ev USING (event_id) | ||
WHERE NOT ee.is_state; | ||
|
||
DROP TABLE event_edges; | ||
|
||
ALTER TABLE new_event_edges RENAME TO event_edges; | ||
|
||
CREATE UNIQUE INDEX event_edges_event_id_prev_event_id_idx | ||
ON event_edges (event_id, prev_event_id); | ||
|
||
CREATE INDEX ev_edges_prev_id ON event_edges (prev_event_id); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.