0

我這裏查詢時超過30分鐘。告訴我如何讓它更快?我應該如何優化1分鐘?如何使我的查詢速度更快

SELECT DISTINCT b.BLDGID AS 'CBRE Building Id', 
       e.CLIENTCODE AS 'DEXUS Building Id', 
       b.BLDGNAME AS 'Building Name', 
       cmgr.RMGRNAME AS 'Snr Manager AS', 
       cmgr.RMGREMAIL AS 'Snr Manager AS Email', 
       cmigr.IMGRNAME AS 'Manager AS', 
       cmigr.IMGREMAIL AS 'Manager AS Email', 
       ttj.JOBID AS 'TSR No', 
       ttj.JobType, 
       wws.JobActivity, 
       wrj.[Description] AS 'JobActivity Sub-Category', 
       ttj.JobDetail AS 'TSR Details', 
       wc.contname AS 'Tenant Contact', 
       wc.Name AS 'Tenant Company NAME', 
       wc.ContName AS 'Tenant Contact', 
       wc.Phone AS 'Tenant Phone', 
       wc.Mobile AS 'Tenant Mobile', 
       wc.Email AS 'Tenant Email', 
       TS.Q_Id, 
       TA.Answer 
FROM BLDG b 
JOIN dbo.ENTITY e ON e.ENTITYID = b.ENTITYID 
JOIN dbo.CBRERMGR cmgr ON cmgr.RMGRID = e.RMGRID 
JOIN dbo.CBREIMGR cmigr ON cmigr.USERID = cmgr.USERID 
JOIN WSM_AUNZ..wsm_Ref_Buildings wsmbldg ON wsmbldg.BLDGID = b.BLDGID 
JOIN WSM_AUNZ..TSP_TSR_Job ttj ON ttj.BuildingID = wsmbldg.BuildingId 
JOIN WSM_AUNZ..wsm_WorkOrderSchedule wws ON wws.BuildingID = wsmbldg.BuildingId 
JOIN WSM_AUNZ..wsm_Ref_JobActivityAction wrj ON wrj.JobActivityActionID = wws.JobActivityActionID 
JOIN WSM_AUNZ..wsm_contact wc ON wc.BuildingID = ttj.BuildingID 
JOIN WSM_AUNZ..wsm_TSRSurveyAnswer TA ON TA.JobId = ttj.JobID --AND WSM_AUNZ.dbo.wsm_TSRSurveyAnswer.clientId = wsmbldg.CLIENTID 
JOIN WSM_AUNZ..wsm_TSRSurvey TS ON TS.Q_Id = TA.Q_Id 
JOIN LOCA l ON e.LOCAID = l.LOCAID 
    AND l.LOCADESC LIKE 'DEX%' 
    AND b.INACTIVE <> 'Y' 
+4

請張貼執行計劃https://www.simple-talk.com/sql/performance/execution-plan-basics/ – StanislavL

回答

-1

1)首先刪除distinct子句並將所有列放在group中,以便它可以通過group by返回唯一不同的值。 2)檢查是否有缺失的索引 3)分享解釋paln。

0

就很難讓我創造我的數據庫結構相似,但一些建議S下方。

  • 寫「隨着(NOLOCK)」中的所有表名末尾(添加捧場也一樣)
  • 不停的寫像內部聯接,左連接關鍵詞的做法,
  • 需要檢查索引
  • 每天早上( https://msdn.microsoft.com/en-IN/library/ms187348.aspx
  • 適當的指數要求所有表的
  • 運行統計數據。
  • 在Where子句中添加條件,而不是象'DEX%'和b.INACTIVE那樣的連接AND'.LOCADESC'>'Y'' 讓我知道進一步做了多少改進,以便我們可以看得更遠。
+0

(1)不要把NOLOCK放在任何地方,它可以給你髒數據。 (2)實踐書面方式INNER JOIN,LEFT JOIN簡化版,它給你的表現真的好處在什麼樣的工作量 (3)更新每天早上統計? 你的答案是不是有資格作爲回答 –

+0

- 「隨着(無鎖)」得到了良好的性能在情況下,如果數據插入不連續。 –