Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 查询优化-建议?_Performance_Sql Server 2008_Query Optimization - Fatal编程技术网

Performance 查询优化-建议?

Performance 查询优化-建议?,performance,sql-server-2008,query-optimization,Performance,Sql Server 2008,Query Optimization,我希望有人能帮助我理解这个XML展示计划,以便进行长时间运行的查询。这个查询来自软件供应商开发的Crystal报表,运行速度非常慢,我试图将其转换为SSRS报表,同时加快查询速度 这里有一个指向文件拖放器上托管的-文件的链接 下面是实际查询本身: Select Distinct CD.desclong [Center], CD.CenterType, Sub.Description [SubCenter], Org.Description [OrgCenter], CO.CodeID [Cent

我希望有人能帮助我理解这个XML展示计划,以便进行长时间运行的查询。这个查询来自软件供应商开发的Crystal报表,运行速度非常慢,我试图将其转换为SSRS报表,同时加快查询速度

这里有一个指向文件拖放器上托管的-文件的链接

下面是实际查询本身:

Select Distinct
CD.desclong [Center],
CD.CenterType,
Sub.Description [SubCenter],
Org.Description [OrgCenter],
CO.CodeID [CenterC],
Sub.CodeID [SubCenterC],
Org.CodeID [OrgCenterC],
Reg.Description [Region],
Reg.CodeID [RegionC],
Rec.CodeID [RecID], 
Rec.Description [RecName],
Rec.NickName [RecNickName],
Acct.AccountID [AcctCharCode],
DM.DriveID,
DM.ExternalID [DriveExtID],
DM.FromDateTime [DriveDate],
dbo.getShiftProductProjectionList(DSD.shiftid)  [ProductProjections], 
dbo.getShiftProcedureProjectionList(DSD.shiftid)  [ProcedureProjections], 
dbo.getShiftMobileList(DSD.shiftid, '1,2,3') [MobileSetups],
LD.LocationName [LocationName],

Case DM.OwnerType
   When 1 Then FSM.DisplayName
   When 0 Then Acct.InternalName 
End [OwnerName], Acct.ExternalID [AcctExtID], SM.ExternalID [SiteExtID],

Stat.StatusText [DriveStatus],
DSD.ShiftID,
DSD.ShiftStart,
DSD.ShiftEnd,
DT.EarlyShiftStart,
DT.LateShiftEnd,
Changes.*,
dbo.getOriginalProcedureProjection(Changes.dsprocshiftid, Changes.dsprocprocedureid) [OriginalProjection], 
(Select Top 1 DescMed From Production.[dbo].QuickCodes where CodeValue = 'ACTEXTIDTAG') [ActExtIDTag],
(Select Top 1 DescMed From Production.[dbo].QuickCodes where CodeValue = 'SITEEXTIDTAG') [SiteExtIDTag],
(Select Top 1 DescMed From Production.[dbo].QuickCodes where CodeValue = 'DRVEXTIDTAG') [DrvExtIDTag],

Case When (Changes.TableName = 'DriveShiftProcedureDetail') Then (Select Top 1 projectionid From driveshiftproceduredetail where uniquekey = Changes.owneruniquekey) else null end as ProjectionID

From
Production.[dbo].rpt_DriveMaster DM
Join Production.[dbo].rpt_DriveShiftDetail DSD on DSD.DriveID = DM.DriveID
Join Production.[dbo].CriticalDriveChanges Changes on (Changes.SourceDriveID = DM.DriveID and Changes.SourceShiftID = DSD.ShiftID and
    Production.[dbo].returnDateTime(year(Changes.ChangeWhen),month(Changes.ChangeWhen),day(Changes.ChangeWhen)) between '01/04/2015' and '01/04/2015')

And
    (
        (
        (Changes.TableName='DriveShiftProcedureDetail' and Changes.ColumnName='projection')
        or 
        (Changes.TableName='DriveShiftDetail' and (Changes.ColumnName='ShiftStart' or Changes.ColumnName='ShiftEnd'))
        or 
        (Changes.TableName='DriveShiftDetail' and Changes.ColumnName='StaffRequested')
        or 
        (Changes.TableName='DriveShiftDetail' and Changes.changetype='Delete')
        or 
        (Changes.TableName='DriveMaster' and Changes.ColumnName='StatusID' and Changes.NewValue='5')
        or 
        (Changes.TableName='DriveMaster' and Changes.ColumnName='FromDateTime')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='Lead')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='TravelTo')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='Setup')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='Breakdown')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='TravelFrom')
        or
        (Changes.TableName='DriveShiftRoleTimeDetail' and Changes.ColumnName='WrapUp')
    )
        and
        (Changes.ChangeWho<>'RMADMIN')
)

Join Production.[dbo].rpt_DriveStatusDef Stat on Stat.StatusID = DM.StatusID
Join Production.[dbo].DriveTimes DT on DT.DriveID = DM.DriveID
Left Outer Join Production.[dbo].rpt_CenterDetail CD on CD.CenterID = DM.centerid
Left Outer Join Production.[dbo].IDViewRegion Reg on CD.Region = Reg.CodeID
Left Outer Join Production.[dbo].IDViewOrgCenter Org on CD.OrgCenter = Org.CodeID
Left Outer Join Production.[dbo].IDViewOrgSubCenter Sub on CD.OrgSubcenter = Sub.CodeID
Left Outer Join Production.[dbo].IDViewCollectionOp CO on cd.centerid = CO.CodeID
Left Outer Join Production.[dbo].IDViewRecruiter Rec on Rec.CodeID = DM.RecruiterID
Left Outer Join Production.[dbo].rpt_Accounts Acct on Acct.AccountID = DM.AccountID
Left Outer Join Production.[dbo].rpt_FixedSiteScheduleMaster FSM on FSM.DrawID = DM.DrawID
Left Outer Join Production.[dbo].rpt_LocationDetail LD on LD.LocationID = DM.LocationID
Join Production.[dbo].rpt_SiteMaster SM on SM.SiteID = DM.SiteID

Where 
(dbo.returnDateTime(year(DM.Fromdatetime),month(DM.Fromdatetime),day(DM.Fromdatetime)) between '01/04/2015' and '01/04/2015')
or     (dbo.returnDateTime(year(Changes.previousdrivedate),month(Changes.previousdrivedate),day(Changes.previousdrivedate)) between '01/04/2015' and '01/04/2015')

实际上,查询以这种方式运行得较慢。

这是一个滑稽的执行计划。我从来没有见过这样的东西。嗯,就像我说的:我没有设计它,但我正试图找到一种改进它的方法。我在计划中看到了很多危险的模式,你将不得不真的返工很多东西。唯一切实可行的办法是针对最严重的问题。请张贴实际执行计划。我们需要找出是什么花了很多时间。希望很少有热点。如果没有-这将需要一些认真的工作。有趣的问题。哦,还有函数调用。想知道这些背后隐藏着什么…谢谢usr,我已经编辑了原始问题,包括执行计划。
-- In the FROM statement
Join Hemasphere_Dev.[dbo].CriticalDriveChanges Changes on (Changes.SourceDriveID = DM.DriveID And Changes.SourceShiftID = DSD.ShiftID And Changes.ChangeWhen Between '01/01/2015' And '01/15/2015')
    --Hemasphere_Dev.[dbo].returnDateTime(year(Changes.ChangeWhen),month(Changes.ChangeWhen),day(Changes.ChangeWhen)) between '01/01/2015' And '01/15/2015')


-- In the WHERE statement
DM.FromDateTime Between '01/01/2015' And '01/15/2015'
Or Changes.PreviousDriveDate Between '01/01/2015' and '01/15/2015'
--(dbo.returnDateTime(year(DM.FromDateTime),month(DM.FromDateTime),day(DM.FromDateTime)) Between '01/01/2015' And '01/15/2015')
--Or (dbo.returnDateTime(year(Changes.previousdrivedate),month(Changes.previousdrivedate),day(Changes.previousdrivedate)) Between '01/01/2015' And '01/15/2015')