Files
synapse/synapse
Paul Chobert 1bd2178a08 Add an index on lower(name) to users to speed up username availability checks (#20369)
Checking whether a username is available looks users up
case-insensitively, with `WHERE lower(name) = lower(?)`. But there is
currently no index on `lower(name)`, so each check scans the whole
table.

This backs registration, `GET /_synapse/admin/v1/username_available` and
`GET /_synapse/mas/is_localpart_available`, which Matrix Authentication
Service will call as the user types in its registration form
([Interactive feedback for username availability in the registration
form
(element-hq/matrix-authentication-service#5977)](https://github.com/element-hq/matrix-authentication-service/pull/5977)).

- Adds `users_lower_name` on `users (lower(name))`, built as a
background update, on both PostgreSQL and SQLite.
- matrix.org already has an index with this name and definition, created
by hand ([Postgres indexes differ on matrix.org
(matrix-org/synapse#11893)](https://github.com/matrix-org/synapse/issues/11893)).
The background update drops and rebuilds it concurrently rather than
adding a duplicate; lookups fall back to a table scan until the rebuild
finishes.

### Pull Request Checklist

* [x] Pull request is based on the develop branch
* [x] Pull request includes a [changelog
file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog).
The entry should:
- Be a short description of your change which makes sense to users.
"Fixed a bug that prevented receiving messages from other servers."
instead of "Moved X method from `EventStore` to `EventWorkerStore`.".
  - Use markdown where necessary, mostly for `code blocks`.
  - End with either a period (.) or an exclamation mark (!).
  - Start with a capital letter.
- Feel free to credit yourself, by adding a sentence "Contributed by
@github_username." or "Contributed by [Your Name]." to the end of the
entry.
* [x] [Code
style](https://element-hq.github.io/synapse/latest/code_style.html) is
correct (run the
[linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
2026-10-28 19:22:21 +01:00
..
2026-06-02 11:05:38 +01:00
2026-09-21 10:00:53 +01:00
2026-10-27 09:34:38 -05:00
…