[英]why does Sqlite not use the index for this ORDER BY?
I have this query: 我有这个查询:
SELECT * FROM Events e
INNER JOIN Telemetry ss ON ss.Id = e.TelemetryId
INNER JOIN Services s ON s.Id = ss.ServiceId
WHERE s.AssetId = @AssetId AND e.TimestampTicks >= @StartTime
ORDER BY e.TimestampTicks LIMIT 1000
and I have this index: 我有这个索引:
CREATE INDEX [IX_Events_TelemetryId_TimestampTicks] ON [Events] ([TelemetryId],[TimestampTicks])
However, the index is not used for the ORDER BY clause. 但是,索引不用于ORDER BY子句。 I get this query explanation: 我得到此查询说明:
0|0|2|SCAN TABLE Services AS s (~44 rows)
0|1|1|SEARCH TABLE Telemetry AS ss USING AUTOMATIC COVERING INDEX (ServiceId=?) (~5 rows)
0|2|0|SEARCH TABLE Events AS e USING INDEX IX_Events_TelemetryId_TimestampTicks (TelemetryId=? AND TimestampTicks>?) (~1816 rows)
0|0|0|USE TEMP B-TREE FOR ORDER BY
Why the B-TREE? 为什么选择B树? If I reverse the index, I actually get worse performance. 如果我反转索引,则实际上会得到较差的性能。 Here's that query plan: 这是查询计划:
0|0|0|SEARCH TABLE Events AS e USING INDEX IX_Events_TimestampTicks_TelemetryId (TimestampTicks>?) (~4031303 rows)
0|1|1|SEARCH TABLE Telemetry AS ss USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
0|2|2|SEARCH TABLE Services AS s USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
I don't know why that ordering disallows use of the TelemetryId. 我不知道为什么该顺序不允许使用TelemetryId。 I really need this query faster. 我真的需要这个查询更快。 Any help? 有什么帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.