sqlite3求优化sql语句性能

qizhi0119 2011-12-12 10:22:01
数据库中存在二个表,
sqlite> .sche application
CREATE TABLE `Application`(
`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`Handle` text unique not null,
`Name` text unique NOT NULL,--
`Category` int NOT NULL,--
`Subcategory` int NOT NULL,--
`Technology` int NOT NULL ,--
`Risk` int NOT NULL ,
`Protocol` text NOT NULL ,--
`Description` text default '',
`Icon` text default ''
);

sqlite> .sche appcode
CREATE TABLE `AppCode`(
`EnumType` int not null, --1 Category; 2 Subcategory; 3 Technology; 4 Risk;
`Type` int not null,
`ParentType` int NOT NULL,
`Name` text
);

其中appcode为application的关联表,
比如,application 的Category如果取字符串形式的值就需要去appcode表EnumType=1及appcode.Type=application.Category的appcode.Name的值。

其他的同理。


总记录约600条
现取某一条件的count(*),sql文如下:
select count(*) from Application A, AppCode C, AppCode S, AppCode T, AppCode R where A.Category = C.Type and C.EnumType = 1 and A.Subcategory = S.Type and S.EnumType = 2 and A.Technology = T.Type and T.EnumType = 3 and A.Risk = R.Type and R.EnumType = 4 ;

时间需要1秒半多,请问如何优化??谢谢。
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2011-12-12
  • 打赏
  • 举报
回复
AppCode 表上创建复合索引 (Type,EnumType)

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧