短版的问题.
有时,通常在一秒钟内运行的查询(使用索引)需要一分钟甚至更长时间才能执行.EXPLAIN显示没有进行全表扫描.数据库很大(2 Gb,4.5百万条记录)并且是专门使用的.再次重新运行相同的查询很快.直到某个特殊时刻......
长版本的问题.
我在SQLITE上有一个日志数据库:
CREATE TABLE log( id integer primary key autoincrement,
msg text,
created_at int,
kind text,
computer text,
process text,
who text
);
CREATE INDEX idxlog_created_at ON log(created_at);
CREATE INDEX idxlog_kind_computer_id ON log(kind,computer,id);
CREATE INDEX idxlog_kind_computer_process_id ON log(kind,computer,process,id);
CREATE INDEX idxlog_kind_computer_process_who_id ON log(kind,computer,process,who,id);
CREATE INDEX idxlog_kind_id ON log(kind,id);
Run Code Online (Sandbox Code Playgroud)
kind ===>'debug','error','warn','info'
计算机===>计算机名称
进程===>进程名称
===>组件名称(发送消息进行记录)
索引创建是为了确保快速响应对日志的任何可能查询.id列包含在索引中以确保快速ORDER BY.
Sqlite:3.7.7.1
平台:Windows XP
语言:Delphi通过sqlite3.dll(来自sqlite.org)
Pragma(在这个特定的连接上):
PRAGMA encoding = "UTF-8";
PRAGMA foreign_keys = ON;
PRAGMA synchronous = NORMAL;
PRAGMA …Run Code Online (Sandbox Code Playgroud)