我试图使用索引的src_ip像这样一个表来执行一个简单的选择查询:优化慢,索引选择MySQL查询
SELECT * FROM netflow_nov2 WHERE src_IP
= 3111950672;
但是,即使在4或5个小时后也不能完成。我需要的反应是在几秒钟的范围内。我想知道如何优化它,所以情况就是如此。
另请注意,使用内置的SQL命令将源IP转换为整数。
有关该表的其他信息: 该表包含从nfdump解析的netflow数据。我正在使用该表来获取有关特定IP地址的信息。换句话说,基本上只有像上面这样的查询才会被使用。
这里是由SHOW TABLE STATUS此表中给出的相关信息:
Rows: 4,205,602,143 (4 billion)
Data Length: 426,564,911,104 (426 GB)
Index Length: 57,283,706,880 (57 GB)
有关系统的信息: 硬盘:〜2TB,采用接近最大 RAM:64GB
my.cnf文件: 见要点:https://gist.github.com/ashtonwebster/e0af038101e1b42ca7e3
表结构:
mysql> DESCRIBE netflow_nov2;
+-----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+-------+
| date | datetime | YES | MUL | NULL | |
| duration | float | YES | | NULL | |
| protocol | varchar(16) | YES | | NULL | |
| src_IP | int(10) unsigned | YES | MUL | NULL | |
| src_port | int(2) | YES | | NULL | |
| dest_IP | int(10) unsigned | YES | MUL | NULL | |
| dest_port | int(2) | YES | | NULL | |
| flags | varchar(8) | YES | | NULL | |
| Tos | int(4) | YES | | NULL | |
| packets | int(8) | YES | | NULL | |
| bytes | int(8) | YES | | NULL | |
| pps | int(8) | YES | | NULL | |
| bps | int(8) | YES | | NULL | |
| Bpp | int(8) | YES | | NULL | |
| Flows | int(8) | YES | | NULL | |
+-----------+------------------+------+-----+---------+-------+
15 rows in set (0.02 sec)
我有关于索引和解释结果的其他信息,但是简要地说: - 索引是b-树,并且有索引日期,src_ip和dest_ip,但只有src_ip将被真正使用 - 基于解释的输出时,src_ip索引被用于在顶部
提到特定查询mysqltuner的输出: 看到要旨:https://gist.github.com/ashtonwebster/cbfd98ee1799a7f6b323
SHOW CREATE TABLE输出:
| netflow_nov2 | CREATE TABLE `netflow_nov2` (
`date` datetime DEFAULT NULL,
`duration` float DEFAULT NULL,
`protocol` varchar(16) DEFAULT NULL,
`src_IP` int(10) unsigned DEFAULT NULL,
`src_port` int(2) DEFAULT NULL,
`dest_IP` int(10) unsigned DEFAULT NULL,
`dest_port` int(2) DEFAULT NULL,
`flags` varchar(8) DEFAULT NULL,
`Tos` int(4) DEFAULT NULL,
`packets` int(8) DEFAULT NULL,
`bytes` int(8) DEFAULT NULL,
`pps` int(8) DEFAULT NULL,
`bps` int(8) DEFAULT NULL,
`Bpp` int(8) DEFAULT NULL,
`Flows` int(8) DEFAULT NULL,
KEY `src_IP` (`src_IP`),
KEY `dest_IP` (`dest_IP`),
KEY `date` (`date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
在此先感谢
你可以添加 SHOW CREATE TABLE'netflow_nov2' 结果 –
你对src_IP领域或与一些其他领域的成份指数指数? –
@DmitryBezik show create table已包含在问题的底部。正如你所看到的,src_ip确实有一个索引。还有,SHOW INDEXES OUTPUT:https://www.dropbox.com/s/iyh6335c0uconh8/Screen%20Shot%202015-01-10%20at%2011.02.37%20AM.png?dl=0 – SPLASHT0N