对于包含两个非空列的表:id (primary)
和date (indexed)
,我在mysql-slow日志中获得以下条目。最大索引(列2)
# Query_time: 16.316747 Lock_time: 0.000049 Rows_sent: 1 Rows_examined: 616021
SET timestamp=1451837371;
select max(date) from mytable where id<896173;
我对此查询运行EXPLAIN
,这就是结果。
id = 1
select_type = SIMPLE
table = mytable
type = range
possible_keys = PRIMARY
key = PRIMARY
key_len = 4
ref = NULL
rows = 337499
Extra = Using where
我尝试过编辑date
索引到id
列添加到它。但是,检查的行数仍然很高。我能做些什么来减少这个数字?
您有按日期,ID或ID,日期索引。以及id <896173多少行? – scaisEdge
我有按日期,编号索引。有616021行ID <896173。 – mossaab