我有一个包含大量数据的数据库,我的查询优化有问题。 如何优化此查询
explain SELECT distinct UNIX_TIMESTAMP(timestamp)*1000 as timestamp,count(ip_src) as counter from acid_event a,saher.network n where inet_aton(n.net)!=a.ip_src group by timestamp;
+----+-------------+-------+-------+---------------+-------------+--------- +------+---------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+-------------+---------+------+---------+----------------------------------------------+
| 1 | SIMPLE | n | index | NULL | fsi | 27 | NULL | 2691027 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | a | index | NULL | timestamp_2 | 13 | NULL | 6770718 | Using where; Using index; Using join buffer |
+----+-------------+-------+-------+---------------+-------------+---------+------+---------+----------------------------------------------+
答案 0 :(得分:0)
尝试通过以下方式摆脱INET_ATON()
在acid_event
表
然后,如果结果集很大(例如数千),请摆脱UNIX_TIMESTAMP(timestamp)*1000
如果这还不够,请修复索引。这是一个book,可以深入解释索引。