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

57/rooms_version_column_3.sql taking ages on upgrade #7144

Closed
@turt2live

Description

@turt2live

Currently my server is stuck on Applying engine-specific schema 57/rooms_version_column_3.sql.postgres and has been for about 30 minutes now. It's an unavoidable update, but would have been nice to know that there's a significant update to the database so I can expect that it'll be a while before the server starts up on its own.

It looks like this particular update is just a really expensive nested loop:

synapse=# select count(*) from rooms;
 count
--------
 528770
(1 row)

synapse=# select count(*) from rooms where room_version is null;
 count
-------
  4071
(1 row)

synapse=# explain UPDATE rooms SET room_version=(
    SELECT COALESCE(json::json->'content'->>'room_version','1')
    FROM state_events se INNER JOIN event_json ej USING (event_id)
    WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
    LIMIT 1
) WHERE rooms.room_version IS NULL;
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 Update on rooms  (cost=0.00..7581986912.20 rows=4248 width=55)
   ->  Seq Scan on rooms  (cost=0.00..7581986912.20 rows=4248 width=55)
         Filter: (room_version IS NULL)
         SubPlan 1
           ->  Limit  (cost=0.70..1784833.81 rows=1 width=1107)
                 ->  Nested Loop  (cost=0.70..1784833.81 rows=1 width=1107)
                       ->  Seq Scan on state_events se  (cost=0.00..1784825.08 rows=1 width=35)
                             Filter: ((room_id = rooms.room_id) AND (type = 'm.room.create'::text) AND (state_key = ''::text))
                       ->  Index Scan using event_json_event_id_key on event_json ej  (cost=0.70..8.71 rows=1 width=1140)
                             Index Cond: (event_id = se.event_id)
(10 rows)

The other reason for mentioning large database updates would be to let admins run them ahead of time where possible, knowing that they're completely on their own and could ruin everything. This shouldn't be an advertised feature of bolding some text in the changelog though.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions