我有一个表t1和两个索引:
create index if not exists timeindex on t1(time, "Bytes Received")
create index if not exists filenameindex on t1(filename)
Run Code Online (Sandbox Code Playgroud)
下一个查询执行得足够快:
select "Bytes Received" from t1 where time>="11:19:31.18" and time <= "11:19:36.18"
Run Code Online (Sandbox Code Playgroud)
但是当我向WHERE语句添加一个附加条件时,查询会大大减慢
select "Bytes Received"
from t1
where time>="11:19:31.18" and time <= "11:19:36.18"
and filename = "SE12.log"
Run Code Online (Sandbox Code Playgroud)
我试图创建一个新索引,t1(time, "Bytes Received", filename)但执行速度没有改变.
我应该如何更改表中的索引以加快查询速度?
使用BETWEEN和以下索引:
CREATE INDEX IF NOT EXISTS fntimeindex ON t1(filename ASC, time ASC);
SELECT "Bytes Received"
FROM t1 INDEXED BY fntimeindex
WHERE filename = 'SE12.log'
AND time BETWEEN '11:19:31.18' AND '11:19:36.18';
Run Code Online (Sandbox Code Playgroud)
另请注意,SQL字符串用简单的引号括起来(双引号用于表,模式和列名).
| 归档时间: |
|
| 查看次数: |
4067 次 |
| 最近记录: |