Any of these is optimal for SELECT in Question:
INDEX(rtype, identifier, timestamp) INDEX(identifier, rtype, timestamp)
The principle is to first put all the "= constants" of the WHERE part, and then add one more thing (the "range" over the timestamp ). More cooking tips .
There is no need to put this in a subquery - this will slow down by creating an unnecessary tmp table.
Why did it suddenly slow down? The likely reason is caching. Immediately after adding a new index, less things were cached in RAM, and all SELECTs hit the disk a lot.
Let me double check the query plan. Specify EXPLAIN SELECT ... It should be one line long, indicating that it uses an index with three columns and does not say "intersect", "temporary" or "filesort".
If something else is wrong, please indicate what to explain, plus SHOW CREATE TABLE (this is more descriptive than DESCRIBE .)
Another thing to do: disable the query cache. Add / change these parameters in my.cnf and restart the server:
query_cache_type = OFF query_cache_size = 0
How does INSERTs ? One row at a time? If they can be "dosed", even several dozen at a time, this will greatly help.
Since you are commenting on the CPU, it looks like you have a request related to the CPU, not an I / O binding. Do SHOW FULL PROCESSLIST; - do you see some kind of request with a big "time"? Is that something you haven't talked about yet?
Please run
SHOW VARIABLES LIKE 'max_connections'; SHOW GLOBAL STATUS LIKE 'Max_used_connections';
(Values ββmay lead to a discussion of thunder herds.)