Remove suboptimal path_alias__status index from path_alias table

Created on 24 July 2023, 11 months ago
Updated 24 April 2024, about 2 months ago

Problem/Motivation

This is split from πŸ› Issue with the generated query by path module Needs work . The query executed by \Drupal\path_alias\AliasRepository::preloadPathAlias uses the default path_alias__status index when using MySQL 5.7 instead of the much faster path_alias__path_langcode_id_status index used by MySQL 8.0 and MariaDB 10.10. In some scenarios, removing the path_alias__status index reduced the query execution time from 3.028s to 0.027s.

Steps to reproduce

Obtain the SQL query:

  1. Install Drupal with standard profile and log in as admin
  2. Enable xdebug and place a breakpoint at the end of \Drupal\path_alias\AliasRepository::preloadPathAlias
  3. Create an article node with URL alias "/admin/test"
  4. Using the debug console, obtain the SQL query
SELECT path, alias
FROM path_alias
WHERE (status = "1") AND ((path LIKE "/node/1" ESCAPE '\\') OR (path LIKE "/node/1/edit" ESCAPE '\\') OR (path LIKE "/node/1/delete" ESCAPE '\\')) AND (langcode IN ("en", "und"))
ORDER BY langcode ASC, id ASC

Run EXPLAIN FORMAT=JSON on the query:

{
  "query_block": {
    "select_id": 1,
    "read_sorted_file": {
      "filesort": {
        "sort_key": "path_alias.langcode, path_alias.`id`",
        "table": {
          "table_name": "path_alias",
          "access_type": "ref",
          "possible_keys": [
            "path_alias__status",
            "path_alias__path_langcode_id_status"
          ],
          "key": "path_alias__status",
          "key_length": "1",
          "used_key_parts": ["status"],
          "ref": ["const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "path_alias.`status` <=> '1' and (path_alias.path like '/node/1' escape '\\' or path_alias.path like '/node/1/edit' escape '\\' or path_alias.path like '/node/1/delete' escape '\\') and path_alias.langcode in ('en','und')"
        }
      }
    }
  }
}

Notice the path_alias__status key was used.

Proposed resolution

  • Remove the automatically created index in \Drupal\path_alias\PathAliasStorageSchema::getEntitySchema
  • Drop the existing index via an update hook.

Remaining tasks

Review, commit

User interface changes

N/A

API changes

N/A

Data model changes

The path_alias__status index has been removed.

Release notes snippet

N/A

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
PathΒ  β†’

Last updated 8 days ago

  • Maintained by
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024