The other day I had a case with an awful performance of a rather simple join. It was a join on tb1.vid = CONCAT('prefix-', tb2.id) with tb1.vid - indexed varchar(100) and tb2.id - int(11) column. No matter what I did - forced it to use key, forced a different join order, it did not want to use tb1.vid index for it. And no surprise it was way too slow, the number of rows analyzed was really huge:
PLAIN TEXT SQL:
- mysql> EXPLAIN
- -> SELECT
- -> tb1.*
- -> FROM tb2
- -> STRAIGHT_JOIN tb1
- -> WHERE
- -> (
- -> tb1.vid LIKE 'prefix-%' AND
- -> tb1.vid = CONCAT('prefix-', tb2.ID) AND …