1

过滤后加入或加入后过滤之间哪个性能更好?例子

...
INNER JOIN
  (select * from dbo.tblCMEvalEmail 
   where dbo.tblCMEvalEmail.EmailSentDate BETWEEN '2013-05-16 00:00:00'
                                              AND '2013-06-01 23:59:59')
     as TCMEvalEmail  ON dbo.tblTSAEmail.TSAEmail = TCMEvalEmail.EmailSenderEmail
INNER JOIN 
  (select * from dbo.tblCMEvalEmailInfo 
   where dbo.tblCMEvalEmailInfo.EmailCMFacingDate BETWEEN '2013-05-16 00:00:00'
                                                      AND '2013-06-01 23:59:59')
     as TEmailInfo ON TCMEvalEmail.EmailID = TEmailInfo.EmailID

或者

INNER JOIN dbo.tblCMEvalEmail
   ON dbo.tblTSAEmail.TSAEmail = dbo.tblCMEvalEmail.EmailSenderEmail 
INNER JOIN dbo.tblCMEvalEmailInfo
   ON dbo.tblCMEvalEmail.EmailID = dbo.tblCMEvalEmailInfo.EmailID 
WHERE 
  dbo.tblCMEvalEmail.EmailSentDate BETWEEN '2013-05-16 00:00:00'
                                       AND '2013-06-01 23:59:59' 
  AND dbo.tblCMEvalEmailInfo.EmailCMFacingDate BETWEEN '2013-05-16 00:00:00'
                                                   AND '2013-06-01 23:59:59'
4

1 回答 1

0

这取决于场景和您拥有的数据。经验法则是获取最少的所需数据并进一步过滤。根据数据,有时 JOIN 后跟 filer 可能会更好,但在不同的数据集上,反之亦然。因此,您需要通过运行查询和测量性能来确定哪一个对您的帮助更大。

于 2013-06-02T09:44:43.750 回答