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

Fix query performance for /sync#12745

Merged
DMRobertson merged 2 commits into
release-v1.59from
erikj/fix_query
May 16, 2022
Merged

Fix query performance for /sync#12745
DMRobertson merged 2 commits into
release-v1.59from
erikj/fix_query

Conversation

@erikjohnston
Copy link
Copy Markdown
Member

Broke in #12729.

@erikjohnston
Copy link
Copy Markdown
Member Author

Old query plan:

                                                                QUERY PLAN                                                                
------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=10249770.65..10249770.66 rows=1 width=54)
   ->  Sort  (cost=10249770.65..10249770.66 rows=1 width=54)
         Sort Key: events.stream_ordering DESC
         ->  Hash Left Join  (cost=169036.84..10249770.64 rows=1 width=54)
               Hash Cond: (events.event_id = rejections.event_id)
               Filter: (rejections.reason IS NULL)
               ->  Bitmap Heap Scan on events  (cost=164761.43..10230672.09 rows=5646913 width=54)
                     Recheck Cond: ((room_id = '....'::text) AND (stream_ordering <= '2945535006'::bigint))
                     Filter: (NOT outlier)
                     ->  Bitmap Index Scan on events_room_stream2  (cost=0.00..163349.70 rows=5671300 width=0)
                           Index Cond: ((room_id = '...'::text) AND (stream_ordering <= '2945535006'::bigint))
               ->  Hash  (cost=2757.96..2757.96 rows=121396 width=52)
                     ->  Seq Scan on rejections  (cost=0.00..2757.96 rows=121396 width=52)
(13 rows)

new query plan:

 Limit  (cost=1.12..4.82 rows=1 width=54)
   ->  Nested Loop Anti Join  (cost=1.12..20857359.91 rows=5646697 width=54)
         ->  Index Scan Backward using events_room_stream2 on events  (cost=0.70..11327215.26 rows=5646916 width=54)
               Index Cond: ((room_id = '...'::text) AND (stream_ordering <= '2945535006'::bigint))
               Filter: (NOT outlier)
         ->  Index Only Scan using rejections_event_id_key on rejections  (cost=0.42..1.69 rows=1 width=41)
               Index Cond: (event_id = events.event_id)

@erikjohnston erikjohnston marked this pull request as ready for review May 16, 2022 14:49
@erikjohnston erikjohnston requested a review from a team as a code owner May 16, 2022 14:49
@DMRobertson DMRobertson changed the base branch from develop to release-v1.59 May 16, 2022 14:49
@DMRobertson
Copy link
Copy Markdown
Contributor

retargeted to release branch

@DMRobertson
Copy link
Copy Markdown
Contributor

This was tested on matrix.org and made a huge improvement.

@DMRobertson DMRobertson merged commit 4ea5460 into release-v1.59 May 16, 2022
@DMRobertson DMRobertson deleted the erikj/fix_query branch May 16, 2022 15:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants