select count(*) as aggregate from `call_records` where (`CallType` = 'dialout' and `CalledNo` = '12345678910');
How to optimize this query? The premise is that the index cannot be created, because there are already several indexes in this table, which may cause the table to be locked.
Is it hot data? If not, just make a script to run regularly and save the statistical count into another statistical table.
For hot data, see if the index you built before can be turned into a combined index. Because the B-tree starts from the left, if you build an (a, b, c), a and a, b and a, b, and c can be used. Used, the query function at the code layer pays attention to the field order.
Re-optimize the index. There are too many single indexes, so try to build a joint index. If this statistics does not require real-time performance, use md5 (sql statement) as the key, use the result as the value, and store it in the cache (redis).