The previous query would:
- Map room IDs to snapshot NIDs
- UNNEST(events) on all those state snapshots
- Compare if the type/state_key match the filter
This was very slow under the following circumstances:
- The rooms have lots of members (e.g Matrix HQ)
- The required_state has no filter on m.room.member
This is what Element X does.
To improve this, we now have _two_ columns per state snapshot:
- membership_events : only the m.room.member events
- events : everything else
Now if a query comes in which doesn't need m.room.member events, we just need
to look in the everything-else bucket of events which is significantly smaller.
This reduces these queries to about 50ms, from 500ms.