sql - Does the order of conditions in a WHERE clause affect MySQL performance? -


Say I have a long, expensive query, which is searching for a large number of rows, packed with conditions has been done. I have a special situation, such as a company id, which will limit the number of rows that should be searched very well, it limits it from hundreds to thousands to dozens.

Is this a MySQL demonstration that I do this:

  Select customers from WHERE (First name as: Foo or last name like: foo or like phone: foo ) And (like the first name: like bar or last name: bar or phone such as: bar) and company =: ug  

or this:

  SELECT * From customers WHERE company =: UG and (as the first name: foo or lastname such as: foo or phone: foo) and (like the first name: like bar or last name: like bar or phone: bar)  

No, order should not make big difference. When these lines are found, then it should be found which lines correspond to the position, the entire position (all the sub-positions connected through boolean logic) is examined for each row.

Some intelligent DB engines will try to guess the situation can be assessed rapidly (for example, things that do not use underlying functions) and those first, more complex (estimated ) Assessment of the elements are evaluated later. It has been determined by some DB engine, not SQL


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -