How can you check the access plan for a per-device time-ordered lookup?
EXPLAIN QUERY PLAN describes access strategy and can show an index search and a separate temporary sort when needed.
SQLite example and interpretation
An index on (device,t) groups a device's records in time order. The displayed plan is specific to the SQLite build and can change with statistics or version.
CREATE TABLE e(device TEXT,t INTEGER);
CREATE INDEX by_device ON e(device,t);
EXPLAIN QUERY PLAN SELECT t FROM e WHERE device='A' ORDER BY t;Result [[3, 0, 56, "SEARCH e USING COVERING INDEX by_device (device=?)"]]
中文
怎样验证按设备筛选、按时间排序是否使用了复合索引?
EXPLAIN QUERY PLAN 概述查询的访问策略,可显示搜索索引及是否另建临时排序结构。
SQLite 示例与适用条件
索引 (device,t) 先按设备收拢,再按时间排列。示例展示当前 SQLite 的计划,输出措辞会随版本和统计信息变化。
CREATE TABLE e(device TEXT,t INTEGER);
CREATE INDEX by_device ON e(device,t);
EXPLAIN QUERY PLAN SELECT t FROM e WHERE device='A' ORDER BY t;结果 [[3, 0, 56, "SEARCH e USING COVERING INDEX by_device (device=?)"]]