如何分析 Sqlite 查询执行? [英] How can I analyse a Sqlite query execution?

查看:45
本文介绍了如何分析 Sqlite 查询执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

Sqlite 有没有类似的工具?

Is there a similar tool for Sqlite?

推荐答案

我知道没有漂亮的图形工具,但是您可以通过 EXPLAIN 关键字获得所有信息.

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

考虑这个数据库:

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

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

A query predicated on email will not use an index:

sqlite> explain select * from users where email='foo';

<头>
地址操作码p1p2p3p4p5评论
0跟踪00000
1String801000
2转到013000
3打开读取020200
4倒带011000
501200
6Ne1102collseq(BINARY)6a
700400
801500
9结果行42000
10下一个05001
11关闭00000
12暂停00000
13交易00000
14验证Cookie05000
15表锁020用户00
16转到03000

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

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

sqlite> explain select * from users where name='foo';

<头>
地址操作码p1p2p3p4p5评论
0跟踪00000
1String801000
2转到018000
3打开读取020200
4打开读取130keyinfo(1,BINARY)00
5IsNull115000
6亲和力110bb00
7SeekGe1151100
8IdxGE1151101
9IdxRowid12000
10寻找02000
1110300
1201400
13结果行32000
14下一个18000
15关闭00000
16关闭10000
17暂停00000
18交易00000
19验证Cookie05000
20表锁020用户00
21转到03000

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

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.

这篇关于如何分析 Sqlite 查询执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆