Skip to content

YOURLS_UNIQUE_URLS slows down large instances #3793

@dgw

Description

@dgw

Code of Conduct

Submission validity

  • This is not a personal support request, that should be posted on discussions community.
  • I checked current issues and this request isn't a duplicate of an existing issue, opened or closed.

Self troubleshooting

Version

1.9.2

Description

As the table of shorturls grows into the millions of rows, if YOURLS_UNIQUE_URLS is enabled (the default), checking whether a new url value already exists in the table takes longer and longer.

Expectation

No response

Reproduction steps

No response

Context

This is a follow-up issue to #3791 in which a user traced slow performance when adding new links on their system to the SQL query run by yourls_long_url_exists(), and found that setting YOURLS_UNIQUE_URLS to false sped up adding new links.

As a first step, I identified three possibilities for making this check faster:

  1. Create an index on the url column
    The limitation of this option is that TEXT columns (which url is) must index on a prefix only. With a sufficiently long prefix, it should still improve performance. MySQL should find possible matches using the prefix index, then only perform a full comparison on the candidate rows.
    However, the user in question indicated that they have many, many similar URLs, and the prefix index wouldn't help if the prefix is shorter than the links' common portion.
  2. Add a FULLTEXT index on the url column and change the code to use MATCH(url) AGAINST(:url IN BINARY MODE) or similar
  3. Add an indexed url_hash column and use that for lookups instead

Options 2 and 3 both require code changes—with 3 being the most drastic. Creating a prefix index (option 1) is the simplest, and should improve performance in most cases with an appropriately-chosen prefix length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions