I have a table with a field "active". Active is an indexed tinyint(4), but only contains a value of 1 or 0. I know... not great design, but I inherited this system to maintain.
If it helps, this table has 175277 records.
When I run:
SELECT * FROM table WHERE active = 1;
it takes 0.497 seconds.
but when I run
SELECT * FROM table WHERE active <> 0;
(active has to equal 1 cause thats the only possible other value.)
It only takes 0.095 seconds.
I was doing some query optimization and noticed this and was wondering why?
Solved!
As suggested above, I used EXPLAIN
to see what the query is doing and it turned out the engine decided to use a different key for each query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.