中Innerjoin和where的效率差异
来源:互联网 发布:江汉大学网络缴费系统 编辑:程序博客网 时间:2024/05/16 16:56
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>天,手头上正在作的一个项目,在生成报表时,客户感觉太慢,于是,各处检查,看可否提示效率。界面上的都改进了,提升不大。如是在SQL语句上下功夫。(我这人比较懒,对简单的语句和查询都没有经过仔细优化的,一般只对姚使用leftjoin,outerjoin,groupby以及carsor的语句会仔细写并用理论考虑和检查---因为这种语句一般测试时如果发现错误,检查和调试很麻烦)先在网上Google搜索“Join与where效率”以及察看SQLServer帮助文档,希望能获得“捷径”些的优化思路。搜索的结果是,各大论坛,包括MSDN上很多人提出了这个问题,但回答是众说纷纭。总体上总结出来时说:对小数据量(<N万)的来说效率几乎无差异,更有说法说Innerjoin和where只是SQL标准不同,在查询分析器中SQLServer查询分析器是将where直接转换为Join后查询的。还是自己来做试验吧。如是有了如下比较结果(均在查询分析器中查询和计时):语句(1)declare@operatorNamenvarchar(50)set@operatorName='%'selectdistinctitem.*fromitem,customer_item,customer_operator,operatorwhereitem.itemcode=customer_item.itemCodeandcustomer_item.customerCode=customer_operator.customerCodeandcustomer_operator.operatorId=customer_operator.operatorIdandoperator.operatorNamelike@operatorNameanditem.deleted=0andcustomer_item.deleted=0andcustomer_operator.deleted=0查询结果,74行,共时间0:00:04语句(2)declare@operatorNamenvarchar(50)set@operatorName='%'selectdistinctitem.*fromitemInnerjoincustomer_itemonitem.itemcode=customer_item.itemCodeInnerjoincustomer_operatoroncustomer_item.customerCode=customer_operator.customerCodeInnerjoinoperatoroncustomer_operator.operatorId=operator.operatorIdwhereoperator.operatorNamelike@operatorNameanditem.deleted=0andcustomer_item.deleted=0andcustomer_operator.deleted=0共74行,时间0:00:01后检查发现语句(1)中有一个重复自查询条件:customer_operator.operatorId=customer_operator.operatorId将其叶加到语句2中,语句(3)declare@operatorNamenvarchar(50)set@operatorName='%'selectdistinctitem.*fromitemInnerjoincustomer_itemonitem.itemcode=customer_item.itemCodeInnerjoincustomer_operatoroncustomer_item.customerCode=customer_operator.customerCodeInnerjoinoperatoroncustomer_operator.operatorId=operator.operatorIdwhereoperator.operatorNamelike@operatorNameanditem.deleted=0andcustomer_item.deleted=0andcustomer_operator.deleted=0andcustomer_operator.operatorId=customer_operator.operatorId所用时间和结果都为74行,时间0:00:01。将语句(1)中的去掉该条件后成为语句(4)declare@operatorNamenvarchar(50)set@operatorName='%'selectdistinctitem.*fromitem,customer_item,customer_operator,operatorwhereitem.itemcode=customer_item.itemCodeandcustomer_item.customerCode=customer_operator.customerCode--andcustomer_operator.operatorId=customer_operator.operatorIdandoperator.operatorNamelike@operatorNameanditem.deleted=0andcustomer_item.deleted=0andcustomer_operator.deleted=0时间和上一页
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 中Innerjoin和where的效率差异
- SQL Server 中Inner join 和where的效率差异
- SQL Server 中Inner join 和where的效率差异
- SQL Server 中Inner join 和where的效率差异
- SQL Server 中Inner join 和where的效率差异
- SQL Server 中Inner join 和where的效率差异
- 优化mysql中where or和where in语句的效率
- mysql中left join on后面and和where条件查询的差异
- cin和scanf的效率差异
- C#中连接两个DataTable,相当于Sql的InnerJoin
- mysql left join的on和where的差异
- Oracle中Left join的on和where的效率差别
- inner join on条件和where条件的效率
- NIO和阻塞io的读写文件效率差异
- 测试new和克隆创建对象的效率差异
- 符合条件中用where 1=1影响效率以及having和where的区别
- where 1=1影响效率以及having和where的区别
- where 1=1影响效率以及having和where的区别
- 将MS2005SP2整合到安装文件
- SQLSERVER,ORACLE,MYSQL高效分页查询
- 软件开发专业技术名词的解释
- Oracle job 管理_gisland
- 嵌套游标
- 中Innerjoin和where的效率差异
- 2005-如何实作CLR存储过程来传回讯息
- 注意那些容易被忽略的SQL注入技巧
- 一个帖子的启示
- SQL2000中默认sa帐号改名和删除的最方法
- 系统之SA弱口令带来的安全隐患
- 三步堵死被SQL注入的隐患!
- www.51zzl.com
- 数据防护之打造安全.mdb