此NO JOIN PREDICATE警告应该让我感到震惊吗?


20

我正在对性能不佳的存储过程的细节进行故障排除。该过程的这一部分将引发NO JOIN PREDICATE警告

select
    method = 
        case methoddescription 
            when 'blah' then 'Ethylene Oxide'
            when NULL then 'N/A'
            else methoddescription
        end,
    testmethod = 
        case methoddescription 
            when 'blah' then 'Biological Indicators'
            when NULL then 'N/A'
            else 'Dosimeter Reports'
        end,
    result = 
        case when l.res is null or l.res <> 1 then 'Failed'
        else 'Passed'
        end,
    datecomplete = COALESCE(CONVERT(varchar(10), NULL, 101),'N/A')
from db2.dbo.view ls
    join db1.dbo.table l
        on ls.id = l.id
    where item = '19003'
        and l.id = '732820'

视图([ls])调用远程服务器(计划右侧的远程查询%41)。

这是计划的图像:

计划

我只问这个问题是因为这篇博文,我想确保以后不会再咬我。

Answers:


24

因为我们知道,l.id = '732820'ls.id = l.idSQL Server将衍生出ls.id = '732820'

FROM   db2.dbo.VIEW ls
       JOIN db1.dbo.table l
         ON ls.id = l.id
WHERE  l.id = '732820' 

是相同的

  ( /*...*/ FROM   db2.dbo.VIEW ls WHERE id = '732820'  )
   CROSS JOIN 
  ( /*...*/  FROM   db1.dbo.table l WHERE id = '732820'  )

此重写不会影响性能

这种推导是一件好事。它允许SQL Server筛选出行,比其他方式早。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.