我们有一个包含超过 1TB 数据的 mariadb 表(故事),定期运行一个查询来获取最近添加的行以在其他地方建立索引。
innodb_version: 5.6.36-82.1
version : 10.1.26-MariaDB-0+deb9u1
Run Code Online (Sandbox Code Playgroud)
当查询优化器决定使用二级索引进行范围遍历(以 1000 为单位)时,查询工作正常
explain extended SELECT stories.item_guid
FROM `stories`
WHERE (updated_at >= '2018-09-21 15:00:00')
AND (updated_at <= '2018-09-22 05:30:00')
ORDER BY `stories`.`id` ASC
LIMIT 1000;
+------+-------------+---------+-------+-----------------------------+-----------------------------+---------+------+--------+----------+---------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+---------+-------+-----------------------------+-----------------------------+---------+------+--------+----------+---------------------------------------+
| 1 | SIMPLE | stories | range | index_stories_on_updated_at | index_stories_on_updated_at | 5 | NULL | 192912 | 100.00 …Run Code Online (Sandbox Code Playgroud)