synapse-product/changelog.d
Dagfinn Ilmari Mannsåker df8a3cef6b
Improve performance of _get_state_groups_from_groups_txn (#7567)
The query keeps showing up in my slow query log.

This changes the plan under the top-level Sort node from

```
    WindowAgg  (cost=280335.88..292963.15 rows=561212 width=80) (actual time=138.651..160.562 rows=27112 loops=1)
      ->  Sort  (cost=280335.88..281738.91 rows=561212 width=84) (actual time=138.597..140.622 rows=27112 loops=1)
            Sort Key: state_groups_state.type, state_groups_state.state_key, state_groups_state.state_group
            Sort Method: quicksort  Memory: 4581kB
            ->  Nested Loop  (cost=2.83..226745.22 rows=561212 width=84) (actual time=21.548..47.657 rows=27112 loops=1)
                  ->  HashAggregate  (cost=2.27..3.28 rows=101 width=8) (actual time=21.526..21.535 rows=20 loops=1)
                        Group Key: state.state_group
                        ->  CTE Scan on state  (cost=0.00..2.02 rows=101 width=8) (actual time=21.280..21.493 rows=20 loops=1)
                  ->  Index Scan using state_groups_state_type_idx on state_groups_state  (cost=0.56..2189.40 rows=5557 width=84) (actual time=0.005..0.991 rows=1356 loops=20)
                        Index Cond: (state_group = state.state_group)
```

to

```
    Nested Loop  (cost=2.83..226745.22 rows=561212 width=84) (actual time=24.194..52.834 rows=27112 loops=1)
      ->  HashAggregate  (cost=2.27..3.28 rows=101 width=8) (actual time=24.130..24.138 rows=20 loops=1)
            Group Key: state.state_group
            ->  CTE Scan on state  (cost=0.00..2.02 rows=101 width=8) (actual time=23.887..24.113 rows=20 loops=1)
      ->  Index Scan using state_groups_state_type_idx on state_groups_state  (cost=0.56..2189.40 rows=5557 width=84) (actual time=0.016..1.159 rows=1356 loops=20)
            Index Cond: (state_group = state.state_group)
```

This cuts the execution time from ~190ms to ~130ms, i.e. a reduction
of ~30%.

The full plans are visualised at https://explain.depesz.com/s/WpbT and
https://explain.depesz.com/s/KlEk

Signed-off-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
2020-06-01 15:23:43 +01:00
..
.gitignore Correct attrs package name in requirements (#3492) 2018-07-07 10:46:59 +10:00
7385.feature allow emails to be passed through SAML (#7385) 2020-05-27 17:40:08 +01:00
7561.misc Convert identity handler to async/await. (#7561) 2020-05-26 13:46:22 -04:00
7567.misc Improve performance of _get_state_groups_from_groups_txn (#7567) 2020-06-01 15:23:43 +01:00
7575.bugfix Fix incorrect placeholder syntax in database prepartion code (#7575) 2020-05-27 16:26:59 +01:00
7584.misc Newsfile 2020-05-27 19:35:03 +01:00
7587.doc Update OpenBSD installation instructions (#7587) 2020-05-30 17:08:07 +01:00
7591.misc Add entry to set dependency against psql service (#7591) 2020-05-28 16:02:41 +01:00
7597.bugfix Make inflight background metrics more efficient. (#7597) 2020-05-29 13:25:32 +01:00
7599.bugfix Fix 'FederationGroupsRoomsServlet' API when group has room server is not in. (#7599) 2020-05-29 17:49:47 +01:00
7600.misc Convert groups local and server to async/await. (#7600) 2020-06-01 07:28:43 -04:00
7607.bugfix Use upsert when inserting read receipts (#7607) 2020-06-01 10:53:06 +01:00
7609.bugfix Don't fail all of an iteration of the device list retry loop on error (#7609) 2020-06-01 12:55:14 +02:00