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:

CommentFileSizeAuthor
before.png47.36 KBamateescu
after.png46 KBamateescu

Issue fork drupal-3641665

Command icon 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:

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Query looks correct. Not sure we can add test coverage here but maybe we should open a follow up to add a workspaces performance test.

catch made their first commit to this issue’s fork.

catch’s picture

Version: main » 11.5.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

This 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed eb6eb9be on 11.5.x
    fix: #3641665 Alias lookups in a workspace scan the whole path_alias...

  • catch committed c80911d5 on 11.x
    fix: #3641665 Alias lookups in a workspace scan the whole path_alias...

  • catch committed fae147ca on 12.0.x
    fix: #3641665 Alias lookups in a workspace scan the whole path_alias...

  • catch committed 8e7ea703 on main
    fix: #3641665 Alias lookups in a workspace scan the whole path_alias...
amateescu’s picture