好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

SQLite Explain(解释)

在 SQLite 语句之前,可以使用 "EXPLAIN" 关键字或 "EXPLAIN QUERY PLAN" 短语,用于描述表的细节。

如果省略了 EXPLAIN 关键字或短语,任何的修改都会引起 SQLite 语句的查询行为,并返回有关 SQLite 语句如何操作的信息。

来自 EXPLAIN 和 EXPLAIN QUERY PLAN 的输出只用于交互式分析和排除故障。

输出格式的细节可能会随着 SQLite 版本的不同而有所变化。

应用程序不应该使用 EXPLAIN 或 EXPLAIN QUERY PLAN,因为其确切的行为是可变的且只有部分会被记录。

语法

EXPLAIN  的语法如下:

 EXPLAIN [SQLite Query] 

EXPLAIN QUERY PLAN  的语法如下:

 EXPLAIN  QUERY PLAN [SQLite Query] 

实例

假设 COMPANY 表有以下记录:

 ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0 

现在,让我们检查 SELECT 语句中的  Explain  使用:

 sqlite> EXPLAIN SELECT *  FROM COMPANY  WHERE Salary &gt= 20000; 

这将产生以下结果:

 addr        opcode      p1          p2          p3
----------  ----------  ----------  ----------  ----------
0           Goto        0           19
1           Integer     0           0
2           OpenRead    0           8
3           SetNumColu  0           5
4           Rewind      0           17
5           Column      0           4
6           RealAffini  0           0
7           Integer     20000       0
8           Lt          357         16          collseq(BI
9           Rowid       0           0
10          Column      0           1
11          Column      0           2
12          Column      0           3
13          Column      0           4
14          RealAffini  0           0
15          Callback    5           0
16          Next        0           5
17          Close       0           0
18          Halt        0           0
19          Transactio  0           0
20          VerifyCook  0           38
21          Goto        0           1
22          Noop        0           0 

现在,让我们检查 SELECT 语句中的  Explain Query Plan  使用:

 SQLite> EXPLAIN QUERY PLAN SELECT * FROM COMPANY WHERE Salary &gt= 20000;
order       from        detail
----------  ----------  -------------
0           0           TABLE COMPANY 

查看更多关于SQLite Explain(解释)的详细内容...

  阅读:20次

上一篇

下一篇

第1节:SQLite Alter实例讲解    第2节:SQLite AND和OR 实例应用    第3节:SQLite drop table 删除表    第4节:SQLite Delete实例应用    第5节:SQLite Distinct 实例    第6节:SQLite Explain(解释)    第7节:SQLite Glob 语法与实例    第8节:SQLite Like 实例讲解    第9节:SQLite Insert into 插入数据    第10节:SQLite Group By 实例    第11节:SQLite Limit 应用    第12节:SQLite Indexed By    第13节:SQLite Joins实例    第14节:SQLite Group By Having 实例    第15节:SQLite 简介    第16节:SQLite 教程    第17节:SQLite Update 实例    第18节:SQLite Where 实例讲解    第19节:SQLite 表达式    第20节:SQLite 创建表create table    第21节:SQLite 如何安装    第22节:SQLite Select 查询语句    第23节:SQLite Order By 应用分析    第24节:SQLite 触发器实例详解    第25节:SQLite 别名    第26节:SQLite NULL 详解    第27节:SQLite Unions 实例    第28节:SQLite Pragma 讲解    第29节:SQLite 常用函数大全    第30节:SQLite Vacuum    第31节:SQLite 运算符大全    第32节:SQLite 数据库分离    第33节:SQLite 附加数据库    第34节:SQLite 创建数据库    第35节:SQLite 数据类型    第36节:SQLite 语法大全    第37节:SQLite 命令    第38节:SQLite 索引 Index 实例详解    第39节:SQLite 子查询实例讲解    第40节:SQLite 事务 Transaction实例介绍    第41节:SQLite 视图(View)实例详解    第42节:SQLite 类似Truncate Table语句    第43节:SQLite 约束实例详解    第44节:SQLite 自动递增    第45节:SQLite 防注入    第46节:SQLite 日期与时间