Problem/Motivation
Alias lookups in a workspace are slow on sites with many aliases. In WorkspacesAliasRepository::getBaseQuery(), the query selects from path_alias, and the revision ID to join is computed for each row with COALESCE(), so the whole table is read before the alias or path are checked.
Tested on a site with 32,774 aliases on MySQL 8.0:
| Method | Before | After |
|---|---|---|
lookupByAlias() |
43.5 ms | 0.04 ms |
lookupBySystemPath() |
85.1 ms | 0.03 ms |
preloadPathAlias(), 3 paths |
56.4 ms | 0.05 ms |
Proposed resolution
Select from path_alias_revision, join path_alias on the ID, and choose the revision in the WHERE clause.
PostgreSQL and SQLite get 20% to 50% faster lookups.
Remaining tasks
Review.
Query plans
EXPLAIN of lookupBySystemPath() on MySQL (wa is workspace_association).
Before:

After:

| Comment | File | Size | Author |
|---|---|---|---|
| before.png | 47.36 KB | amateescu | |
| after.png | 46 KB | amateescu |
Issue fork drupal-3641665
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3641665-alias-lookups-in-workspaces
changes, plain diff MR !17956
Comments
Comment #3
amateescu commentedComment #4
smustgrave commentedQuery looks correct. Not sure we can add test coverage here but maybe we should open a follow up to add a workspaces performance test.
Comment #6
catchThis would probably have shown up if we had both a workspaces performance test and also #3585125: Add EXPLAIN support to performance tests. Tagging for follow-up to add a workspaces performance test.
Committed/pushed to main and cherry-picked back through to 11.5.x, thanks!
Made one tweak to a comment prior to commit.
Comment #12
amateescu commentedOpened the followup: #3642744: Add performance tests for Workspaces