I update JOIN
ed tables as
UPDATE table1 a
JOIN table2 b
ON a.col1 LIKE CONCAT('%', '.', b.col2)
SET a.foreign_id=b.foreign_id
but LIKE
is very slow for JOIN
. Is there another way based on faster substring functions to make the JOIN
?
join;MySQLupdate
I update JOIN
ed tables as
UPDATE table1 a
JOIN table2 b
ON a.col1 LIKE CONCAT('%', '.', b.col2)
SET a.foreign_id=b.foreign_id
but LIKE
is very slow for JOIN
. Is there another way based on faster substring functions to make the JOIN
?
Best Answer
The leading wildcard in the like, not the function, is preventing the use of the table1.col1 index (assuming it is indexed).
For an indexed approach, the values can be store reversed...
Of course, this comes with the downside that the column will need to be reversed for display...
Here is a similar denormalized approach with the reversed value redundantly stored in the same table...
A normalized approach would be another table of unique table1.col1 values as stored and reversed...