如何分析 Sqlite 查询执行情况?

发布于 2024-08-05 05:54:48 字数 87 浏览 7 评论 0原文

我有一个 Sqlite 数据库,我想检查索引是否正确。 MS SQL 分析器非常擅长分解查询执行和利用的索引。

Sqlite 有类似的工具吗?

I have a Sqlite database which I want to check the indexes are correct. MS SQL Analyser is great at breaking down the query execution and utilised indexes.

Is there a similar tool for Sqlite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-08-12 05:54:48

正如 outis 所说:

EXPLAIN QUERY PLAN SELECT * FROM FOO

如果像我一样,您只是使用它来确保达到索引(索引?),那么是否可以提供更具可读性的输出?

As outis said:

EXPLAIN QUERY PLAN SELECT * FROM FOO

Does the trick with a more readable output, if like me you're simply using it to ensure you're hitting your indexes (indices?)

反目相谮 2024-08-12 05:54:48

据我所知,没有漂亮的图形工具,但您寻找的所有信息都可以通过 EXPLAIN 关键字获得。

考虑这个数据库:

sqlite> create table users (name, email);
sqlite> create index user_names on users (name);

基于 email 的查询不会使用索引:

sqlite> explain select * from users where email='foo';
addropcodep1p2p3p4p5comment
0Trace00000
1String8010foo00
2Goto013000
3OpenRead020200
4倒回011000
501200
6Ne1102collseq(BINARY)6a
700400
801500
9ResultRow42000
10下一个05001
11Close00000
12Halt00000
13Transaction00000
14verifyCookie05000
15TableLock020users00
16Goto03000

而基于 name 的查询将使用 user_names 索引:

sqlite> explain select * from users where name='foo';
addr操作码p1p2p3p4p5comment
0Trace00000
1String8010foo00
2Goto018000
3OpenRead020200
4OpenRead130keyinfo(1 ,BINARY)00
5IsNull115000
6亲和性110bb00
7SeekGe1151100
8IdxGE1151101
9IdxRowid12000
10查找02000
1110300
201400
13ResultRow32000
14下一个18000
15关闭00000
16关闭10000
17停止00000
18事务00000
19verifyCookie05000
20TableLock020users00
21Goto03000

使用 EXPLAIN 确实需要掌握 SQLite 的虚拟机 VDBE:

http://www.sqlite.org/opcode.html

但这并不像看起来那么难,并且为您提供了有关查询的完整故事。

I know of no pretty graphical tools, but all of the information you seek is available from the EXPLAIN keyword.

Consider this database:

sqlite> create table users (name, email);
sqlite> create index user_names on users (name);

A query predicated on email will not use an index:

sqlite> explain select * from users where email='foo';
addropcodep1p2p3p4p5comment
0Trace00000
1String8010foo00
2Goto013000
3OpenRead020200
4Rewind011000
5Column01200
6Ne1102collseq(BINARY)6a
7Column00400
8Column01500
9ResultRow42000
10Next05001
11Close00000
12Halt00000
13Transaction00000
14VerifyCookie05000
15TableLock020users00
16Goto03000

Whereas a query predicated on name will use the user_names index:

sqlite> explain select * from users where name='foo';
addropcodep1p2p3p4p5comment
0Trace00000
1String8010foo00
2Goto018000
3OpenRead020200
4OpenRead130keyinfo(1,BINARY)00
5IsNull115000
6Affinity110bb00
7SeekGe1151100
8IdxGE1151101
9IdxRowid12000
10Seek02000
11Column10300
12Column01400
13ResultRow32000
14Next18000
15Close00000
16Close10000
17Halt00000
18Transaction00000
19VerifyCookie05000
20TableLock020users00
21Goto03000

Using EXPLAIN does require coming to grips with SQLite's virtual machine, VDBE:

http://www.sqlite.org/opcode.html

But this is not as hard as it looks, and gives you the complete story about your query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文