Sql-Server

我應該對這個 NO JOIN PREDICATE 警告感到震驚嗎?

  • February 5, 2022

我正在對性能不佳的儲存過程的點點滴滴進行故障排除。該過程的這一部分引發了 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)。

這是該計劃的圖片:

計劃

我只是因為這篇博文才問這個問題,我想確保以後不會再回來咬我。

因為我們知道,l.id = '732820'然後ls.id = l.idSQL Server 派生出ls.id = '732820'

IE

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 比其他方法更早地過濾掉行。

引用自:https://dba.stackexchange.com/questions/34193