簡體   English   中英

查詢速度太慢,該如何優化?

[英]Query is too slow, how can I optimize it?

我有一個包含大量數據的數據庫,但查詢優化存在問題。 如何優化此查詢

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  |
+----+-------------+-------+-------+---------------+-------------+---------+------+---------+----------------------------------------------+
  1. 嘗試擺脫INET_ATON() ,例如,將一個具有IP地址數值的新列添加到acid_event表中

  2. 然后,如果結果集很大(例如成千上萬),則擺脫UNIX_TIMESTAMP(timestamp)*1000

  3. 如果這還不夠,修復指標。 這是一深入解釋索引的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM