我的查询时间超过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'
答案 0 :(得分:0)
我很难在我的数据库中创建类似的结构,但下面的建议很少。
答案 1 :(得分:-1)
1)首先删除distinct子句并将所有列放在group by中,这样它只能通过group by返回不同的值。 2)检查是否有任何缺失的索引 3)分享解释paln。