日期:2014-05-19  浏览次数:20585 次

[请教] 查询效率问题 (当查询条件in和and 同时存在的时候查询效率为啥巨低?),非常感谢

1.SELECT   *   FROM   ....
  WHERE   NAME   IN   ( 'NAME1 ')

2.SELECT   *   FROM   ....
  WHERE   AGET=   3

3.SELECT   *   FROM   ....
  WHERE   NAME   IN   ( 'NAME1 ')   AND   AGET=   3  


1和2的效率差不多多.但3却需要1的40倍时间来查询,为什么会这样????

真实语句如下:  

SELECT           dbo.USER_INFO.USER_NAME,   dbo.SCR_FORM.SCR_FORM_ID,   dbo.SCR_FORM.SCR_FORM_CODE,   dbo.SCR_FORM.PRJ_CONTRACT_CD,      
                                            dbo.SCR_FORM.SC_TYPE,   dbo.SCR_FORM.SC_FRAME,   dbo.SCR_FORM.OS_VENDOR_CODE,   dbo.SCR_FORM.OS_TEAM_CODE,      
                                            dbo.SCR_FORM.SUBMIT_DATE,   dbo.SCR_FORM.STATUS,   dbo.SCR_FORM.SUBMITTER_USER_CD,   dbo.SCR_FORM.BGM_USER_CD,      
                                            dbo.SCR_FORM.CPM_USER_CD,   dbo.SCR_FORM.CPD_USER_CD,   dbo.SCR_FORM.OS_USER_CD,   dbo.OS_VENDOR.FULL_NAME   AS   VENDORNAME,      
                                            dbo.OS_TEAM.FULL_NAME   AS   TEAMNAME,   dbo.PROJECT.PROJECT_NAME,   dbo.PROJECT.PARTY_ID    
FROM                   dbo.SCR_FORM   INNER   JOIN    
                                            dbo.PROJECT   ON   dbo.SCR_FORM.PRJ_CONTRACT_CD   =   dbo.PROJECT.PROJECT_CD   LEFT   OUTER   JOIN    
                                            dbo.USER_INFO   ON   dbo.SCR_FORM.SUBMITTER_USER_CD   =   dbo.USER_INFO.USER_CD   LEFT   OUTER   JOIN    
                                            dbo.OS_TEAM   ON   dbo.SCR_FORM.OS_TEAM_CODE   =   dbo.OS_TEAM.OS_TEAM_CODE   LEFT   OUTER   JOIN    
                                            dbo.OS_VENDOR   ON   dbo.SCR_FORM.OS_VENDOR_CODE   =   dbo.OS_VENDOR.OS_VENDOR_CODE    
    --下面是in条件
where   SCR_FORM.SCR_FORM_CODE   in  
(SELECT                            
  distinct   SC_ITEM.SCR_FORM_CODE
  FROM           dbo.SC_ITEM  
INNER   JOIN
dbo.EI_ORDER_ITEM       on   EI_ORDER_ITEM.T