Difference between innodb and myisam concerning counting
Please notice that counting with WHERE
is not slower with InnoDB than it would be with MyISAM. Only a very bare
SELECT COUNT(*) FROM table
can be computed faster with MyISAM as this number is stored in MyISAMs table metadata.
If you have a query with WHERE
constraint for example:
SELECT COUNT(*) FROM table WHERE active_calls = 1
the query needs to access the table data in both storage engines and there should be no notable performance difference between MyISAM and InnoDB.
Concerning your specific problem
Please see that your query does not use any proper index. This is not because InnoDB "prefers" a full table scan, but because there exists no proper index.
You have a combined index (campaign_id, active_calls)
, but active_calls
is the second part of the index. As long as the first part is not used in the query, MySQL has no easy access to the second part.
What you want for this simple count query is another index (active_calls)
only on this one column. It should run fast then.