There are over 2 millions record in the table.
I want to count how many errors (with checked) in the table and how many has been checked.
I do two queries:
SELECT count(*) as CountError FROM table WHERE checked = 1 AND error != ''
–
SELECT count(*) as Checked FROM table WHERE checked = 1
The performance is really slow, it take about 5 mins to get the result. How to improve this?
I have already have index on status field for the UPDATE performance.
If I index on checked field – then UPDATE performance will be effected which I do not want that.
UPDATE happen more than SELECT.
The table are Innob
You can try if making both counts in the same query is faster:
However, the difference will probably not be much to talk about. If you really want a difference then you need to add an index. Consider what the impact really would mean, and make an actual test to get a feel for what the impact could really be. If the update gets 10% slower and the select gets 100000% faster, then it might still be worth it.