Optimize redirect_fetch_rids_by_path

Created on 27 October 2015, over 9 years ago
Updated 20 May 2025, about 5 hours ago

The query in redirect_fetch_rids_by_path() cannot use and index to match the source, but this is extremely slow for sites with a large "redirect" table. Even with an index, a case-insensitive LIKE would be slow on non-MySQL databases.

Here is my suggested fix (which is portable to non-MySQL and still fast):

  1. Add an index that starts with "source." It can include other columns, but it needs to start with "source."
  2. Update redirect_path_update() -- and anywhere else that writes to the "source" column -- to coerce the source to lowercase.
  3. Create a schema update that coerces existing "source" column data to lowercase.
  4. Update redirect_fetch_rids_by_path() to coerce $source to lowercase before using it in the query. Drop the LIKE.

You could also coerce to uppercase. Either would work.

A quick fix, which would at least make things on MySQL with case-insensitive indexes (the Drupal+MySQL default) fast, would be to create an index on (source, language).

✨ Feature request
Status

Closed: outdated

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States david strauss San Francisco, CA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024