I have two MySQL tables, Post
, and Account
.
I use NodeJS
for my backend API, and it generates the following SQL
statement:
select `p`.`id` as `post_id`
from `Post` as `p`
left join `Account` as `a`
on `a`.`id` = `p`.`author`
where `p`.`id` in ('9', '10', '76', '77', 123)
order by `p`.`id` asc
the code works, the problem it's SLOW! I tried to use EXPLAIN
to check what happened, it doesn't use INDEX:
But, then I notice that the IN clause is mixed with number and string, so I change 123
to '123'
and EXPLAIN again, it uses INDEX now:
So, my question is what happens when numbers and varchars are mixed inside an IN?
Thanks in advance