求亲爱的公主病资源全集免费百度云资源

2015年1月 Oracle大版内专家分月排行榜第一2014年12月 Oracle大版内专家分月排行榜第一2014年11月 Oracle大版内专家分月排行榜第一2014年10月 Oracle大版内专家分月排行榜第一2014年9月 Oracle大版内专家分月排行榜第一2014年8月 Oracle大版内专家分月排行榜第一
2015年5月 Oracle大版内专家分月排行榜第二2015年3月 Oracle大版内专家分月排行榜第二2015年2月 Oracle大版内专家分月排行榜第二
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。2008年 总版技术专家分年内排行榜第二
2010年 总版技术专家分年内排行榜第四2009年 总版技术专家分年内排行榜第五2007年 总版技术专家分年内排行榜第六
2007年11月 VB大版内专家分月排行榜第一
2007年10月 VB大版内专家分月排行榜第二
2008年11月 MS-SQL Server大版内专家分月排行榜第三2008年10月 MS-SQL Server大版内专家分月排行榜第三2006年7月 MS-SQL Server大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。1070人阅读
SQL HQL语句(21)
我在做数据库查询的时候,发现了一个奇怪的问题,在使用like关键字的时候,速度其慢,效率极低。不明白是什么原因,请大家讲解一下,为什么like慢,而其他的两个快。3个查询不同的地方用红色做了标识。
我数据表中的数据量如下FDAEnterprise 数据513条,TYHJL里面的数据为22516条。
我有如下一个查询语句:查询所花费的时间是13秒。
& select top 15&&
ame,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress,count(*) as NoteNum&&
from TYHJL join FDAEnterprise on&&
TYHJL.cEnterpriseCode=FDAEnterprise.cEnterpriseCode &&
ame like '%大药房%'&
yh_xq&=''&&
Yh_datetime & ''&&
Yh_datetime &''
& group by&&
ame ,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress &&
& order by&&
FDAEnterprise.cEnterpriseCode
后来经过修改,改为如下语句,查询所花时间大概是0.25秒
select top 15&&
ame,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress,count(*) as NoteNum&&
from TYHJL join FDAEnterprise on&&
TYHJL.cEnterpriseCode=FDAEnterprise.cEnterpriseCode &&
(select cName from FDAEnterprise where TYHJL.cEnterpriseCode=FDAEnterprise.cEnterpriseCode)like '%大药房%'&
yh_xq&=''&&
Yh_datetime & ''&&
Yh_datetime &''
group by&&
ame ,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress &&
order by&&
FDAEnterprise.cEnterpriseCode
最后我又进行了修改,改为如下的语句,查询耗时大概0.14秒
select top 15&&
ame,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress,count(*) as NoteNum&&
from TYHJL join FDAEnterprise on&&
TYHJL.cEnterpriseCode=FDAEnterprise.cEnterpriseCode &&
charindex('大药房',ame)&&0&
yh_xq&=''&&
Yh_datetime & ''&&
Yh_datetime &''
ame ,FDAEnterprise.cEnterpriseCode,FDAEnterprise.cAddress &&
order by&&
FDAEnterprise.cEnterpriseCode
第一种like的内容如果前后都使用了%的话,是无法使用索引的,这应该是慢的主要原因
第二种先select了一次,相当于用hash索引的方式过滤了一遍,结果集小了很多
第三种使用了文本索引,所以速度比较快
在sql语句里,&like&,&not in&,&not exists&这几个是比较慢的,原因在于它们的实现机制。例如,如果我们在一个“字符串”里找查“另一个字符串”,而且这个字符串有通配符(%),不管是用顺序查找还是二分查找,效率都不见得太高。like比较符,如果用的是like &大药房%&,这种方式会用索引扫描,但如果是 like &%大药房%&,这种方式会用表扫描,该字段上的索引不起作用,速度会非常慢,如果你的记录很多,该字段很大的话。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:4354491次
积分:42060
积分:42060
排名:第69名
原创:211篇
转载:2252篇
评论:462条
(29)(96)(177)(114)(86)(40)(43)(73)(15)(10)(17)(12)(6)(20)(27)(54)(71)(97)(74)(32)(2)(24)(21)(62)(60)(36)(23)(27)(46)(34)(76)(63)(121)(142)(74)(54)(120)(77)(42)(4)(12)(19)(1)(9)(15)(19)(18)(16)(31)(79)(68)

我要回帖

更多关于 亲爱的公主病资源全集 的文章

 

随机推荐