在我们的应用程序中,我们在网页上显示来自 MySQL 的记录。像在大多数此类应用程序中一样,我们使用分页。所以查询看起来像这样:
select * from sms_message 
where account_group_name = 'scott' 
and received_on > '2012-10-11' and 
received_on < '2012-11-30' 
order by received_on desc 
limit 200 offset 3000000;
此查询需要 104 秒。如果我只将偏移量更改为低或完全删除它,则只需半秒。这是为什么?
只有一个复合索引,它是 account_group_name、received_on 和另外两列。表是 InnoDB。
更新:
解释回报:
1   SIMPLE  sms_message ref all_filters_index   all_filters_index   258 const   2190030 Using where
all_filters_index 是上面提到的 4 列过滤器。