What is the difference in query with IN

I have two MySQL tables, Postand Account.

I use the NodeJSbackend API for my and it generates the following statement SQL:

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

code works, SLOW problem ! I tried using EXPLAINto check what happened, it does not use INDEX :

explaing0

But then I noticed that the proposal IN mixed with numbers and strings, so I'm me again 123on '123'and the EXPLAIN , it uses the INDEX at the moment?

explaing1

So my question is what happens when numbers and varchars mix inside IN ?

Thank you in advance

+4
2

MySQL-Documentation MySQL , :

( , ) , . , 1 , , "1", "1", "00001" '01.e1. .

, IN -Statement, .

+2

:

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;

Post(id) where. order by.

, Post(id) . - . in . , id . . , :

where p.id in (9, 10, 76, 77, 123) 

, . MySQL . , . MySQL . , Posts(id, author). .

0

Source: https://habr.com/ru/post/1615868/


All Articles