Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove some redundant joins on event_edges.room_id
Browse files Browse the repository at this point in the history
We've long passed the point where it's possible to have the same event_id in
different tables, so these join conditions are redundant: we can just join on
event_id.

event_edges is of non-trivial size, and the room_id column is wasteful, so
let's stop reading from it. In future, we can stop writing to it, and then drop
it.
  • Loading branch information
richvdh committed Jul 26, 2018
1 parent 1b4d73f commit bd4b25f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
13 changes: 6 additions & 7 deletions synapse/storage/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def get_oldest_events_with_depth_in_room_txn(self, txn, room_id):
sql = (
"SELECT b.event_id, MAX(e.depth) FROM events as e"
" INNER JOIN event_edges as g"
" ON g.event_id = e.event_id AND g.room_id = e.room_id"
" ON g.event_id = e.event_id"
" INNER JOIN event_backward_extremities as b"
" ON g.prev_event_id = b.event_id AND g.room_id = b.room_id"
" ON g.prev_event_id = b.event_id"
" WHERE b.room_id = ? AND g.is_state is ?"
" GROUP BY b.event_id"
)
Expand Down Expand Up @@ -330,8 +330,7 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
"SELECT depth, prev_event_id FROM event_edges"
" INNER JOIN events"
" ON prev_event_id = events.event_id"
" AND event_edges.room_id = events.room_id"
" WHERE event_edges.room_id = ? AND event_edges.event_id = ?"
" WHERE event_edges.event_id = ?"
" AND event_edges.is_state = ?"
" LIMIT ?"
)
Expand Down Expand Up @@ -365,7 +364,7 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):

txn.execute(
query,
(room_id, event_id, False, limit - len(event_results))
(event_id, False, limit - len(event_results))
)

for row in txn:
Expand Down Expand Up @@ -402,7 +401,7 @@ def _get_missing_events(self, txn, room_id, earliest_events, latest_events,

query = (
"SELECT prev_event_id FROM event_edges "
"WHERE room_id = ? AND event_id = ? AND is_state = ? "
"WHERE event_id = ? AND is_state = ? "
"LIMIT ?"
)

Expand All @@ -411,7 +410,7 @@ def _get_missing_events(self, txn, room_id, earliest_events, latest_events,
for event_id in front:
txn.execute(
query,
(room_id, event_id, False, limit - len(event_results))
(event_id, False, limit - len(event_results))
)

for e_id, in txn:
Expand Down
1 change: 0 additions & 1 deletion synapse/storage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ def _calculate_new_extremeties(self, room_id, event_contexts, latest_event_ids):
iterable=list(new_latest_event_ids),
retcols=["prev_event_id"],
keyvalues={
"room_id": room_id,
"is_state": False,
},
desc="_calculate_new_extremeties",
Expand Down

0 comments on commit bd4b25f

Please sign in to comment.