Which is more performative: "WHERE id IN (?, ?, ...)" or "WHERE id = ? OR id = ? (...)"

Asked

Viewed 306 times

0

I am not an expert in Mysql, but I am studying and lately I am trying to improve some codes of my programs and I came across this situation. I wonder if there are differences between the querys below:

  • SELECT id, nome, email, endereco FROM usuarios WHERE id = 10 OR id = 11 OR id = 12;
  • SELECT id, nome, email, endereco FROM usuarios WHERE id IN (10, 11, 12);

It is obvious that the readability increases significantly and the size of the query decreases, reducing the size of the text for sending the request. But, in addition, is there any performance gain on the server side in the processing of this data? Mysql works the same way in both cases or one may be faster than the other?

  • 3

    Have you asked Mysql for the execution plan? Me think that there will only be a difference in the time of the bank consultation and the parse, but the network time should be (however tiny) less irrelevant than the parse of the extra characters. I am writing here only from intuition, I have no formal basis

  • @Jeffersonquesado Well, I tried to visualize something by the Mysql EXPLAIN command, but the return in both cases was the same. I still don’t understand about implementation plan, as I ask for Mysql this information?

  • I speak "êxtra" and you speak "éxtra" ;-) https://dev.mysql.com/doc/workbench/en/wb-performance-explain.html

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.