In MySQL, I always consider:
.... WHER开发者_如何学PythonE type > 5
to be faster than:
... WHERE type != 4 AND type != 6 AND type != 10
That is, I believe it is faster to one 'larger than' or 'smaller than' statement than having several comparison (equal to's or not equal to's). However, I have absolutely no idea if this is a valid thought. Anybody any idea?
I think this is virtually the same, as long as you don't have 1000 conditions in the WHERE clause. When trying to optimize sql queries, focus more on the multi-table operations, joins etc. This is a minor thing. Don't focus on this too much. If you try too much to optimize you can complicate your database and code with almost no benefit.
Once I was in a situation when it was better to have a multiple conditions OR'ed in the WHERE clause than join another table - using multiple WHERE condition was much more efficient because I saved one join.
精彩评论