I have two tables, a performer table and a redirect table. The performer table has a column called slug. The redirect table has a column called source.
Both the source and slug columns have unique key indexes.
An example of a slug column data is something like:
this-is-a-slug
An example of a source column data is something like:
this-is-a-slug.s12345
I want an efficient query that gives me all the rows in redirect that have a source column that starts with a slug and the ".s" characters, followed by a number digits.
I tried this:
select source from redirect
join performer on
source regexp concat('^', slug, '.s[0-9]+$');
It was extremely slow. So I decided to be less restrictive and tried this:
select source from redirect
join performer on
source like concat(slug, ".s%");
It was still slow.
Is there a way I can do this efficiently?