开发者

Is it faster in MySQL to have one filter or several for the same column?

开发者 https://www.devze.com 2023-03-22 06:13 出处:网络
In MySQL, I always consider: .... WHER开发者_如何学PythonE type > 5 to be faster than: ... WHERE type != 4 AND type != 6 AND type != 10

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消