放在存储过程中时,查询执行速度较慢

时间:2015-08-20 12:35:21

标签: sql-server

我有一个查询,其中我也使用了一个函数。它在不到一分钟的时间内执行。但是当我在存储过程中调用相同的查询时,它需要大约8分钟。为什么?我无法理解为什么会发生这种情况以及为什么花费这么多时间?我认为当我从存储过程中调用函数时,大部分时间都消耗掉了。 这是我的问题: -

 SELECT  et.X,et.Y,et.EquipID as ID,e.EquipmentName as Name,e.EquipmentNo,eg.EquipGroup as 'Fleet_Name',et.SpeedOfTheVehicle as Speed,et.IgnitionStatus,convert(varchar,et.SignalDateTime) as SignalDateTime,
et.DriverID,case d.DriverName when '' then 'Name' else d.DriverName end as DriverName,
case isnull(d.EmployeeNo,'') when '' then '0' else d.EmployeeNo end  as DriverNo,
case isnull(d.LicenseNo,'') when '' then '0' else d.LicenseNo end as LicenseNo,
dbo.GetFilterColorStatusOfEquipment(et.SignalDateTime,et.SpeedOfTheVehicle,(SELECT COUNT(J.JobId) FROM tbl_Notification J 
               inner JOIN tbl_NotificationAssign JN ON  JN.NotificationNo =J.NotificationNo
               inner JOIN dbo.tbl_CustomStatus JS ON JS.CustomStatusID=J.CustomStatusID 
               INNER JOIN dbo.tbl_SystemStatus ss ON ss.SystemStatusID=JS.SystemStatusID
               WHERE JN.DriverID=et.DriverID AND ss.SystemStatusID !=9),et.IgnitionStatus) as FilterStatus,
e.SerialNo,e.GPSIMIENO,'Equipment' TYPE,etr.Vector,si.ImgPath as 'Icon',et.Address,
etr.EquipTypeID,si.StatusTypeID,ss.SystemStatusCode
from dbo.tbl_Equipment e 
left outer join dbo.tbl_EquipmentTrack et  on et.EquipID=e.EquipID 
left outer join dbo.tbl_DriverMaster d on et.DriverID=d.DriverID 
LEFT OUTER JOIN dbo.tbl_EquipmentGroup eg ON eg.EquipGroupID=e.EquipGroupID
LEFT OUTER JOIN dbo.tbl_EquipmentType etr ON etr.EquipTypeID=eg.EquipTypeID
full outer join dbo.tbl_StatusIMG si on etr.EquipTypeID=si.NotificationType and si.StatusTypeID=2 
full outer join dbo.tbl_SystemStatus ss on ss.SystemStatusID=si.SystemStatusID

where 
et.X is not null and et.Y is not null and e.EquipmentName is not null AND e.Available='Available'
AND ((dbo.GetFilterStatusOfEquipment(et.SignalDateTime,et.SpeedOfTheVehicle,(SELECT COUNT(J.JobId) FROM tbl_Notification J 
               inner JOIN tbl_NotificationAssign JN ON  JN.NotificationNo =J.NotificationNo
               inner JOIN dbo.tbl_CustomStatus JS ON JS.CustomStatusID=J.CustomStatusID 
               INNER JOIN dbo.tbl_SystemStatus ss ON ss.SystemStatusID=JS.SystemStatusID
               WHERE JN.DriverID=et.DriverID AND ss.SystemStatusID !=9),et.IgnitionStatus) in (select val from dbo.split(@filter,','))) OR
(@filter='*' or @filter=''))

0 个答案:

没有答案