首先我要说的是,我对存储过程没有太多帮助,所以我对此的看法可能完全没错,但我想我会来这里试试找在将整个事情吹起来并重新开始之前,解决我当前的问题。
我有一个存储过程,只是运行了一堆我已经放在一起的其他查询。它由一堆Insert
,Update
和Delete
查询组成,当我运行此存储过程时,需要2个小时才能完成。
当我单独运行每个查询时,总共需要大约45分钟。
显然,单独运行它们并将它们作为存储过程运行之间存在很大的时间差异,但是能够运行单个存储过程要方便得多。
我做过一些研究,最常见的答案是减速是由于"参数嗅探"。我对参数嗅探答案的问题是我没有在我的存储过程中内置任何参数。正如我之前提到的,我构建了一堆查询,并将它们简单地粘贴到存储过程中。这可能不是最好的方法,但当时对我来说是有道理的。
我的问题是,存储过程是否运行较慢,因为我没有参数或因其他原因导致转速较慢?此外,有没有办法在我现有的配置下加快速度?
以下是我的存储过程与第一对查询的示例。
ALTER PROCEDURE [dbo].[LDS_Step_2]
AS
------------------------------------------------------
--******* Text Import 2 Append ********
------------------------------------------------------
INSERT INTO [dbo].[Text_Import_2]([Foundation_Account_Number], [Foundation_Account_Name], [Billing_Account_Number], [Billing_Account_Name], [Wireless_Number], [Market_Cycle_End_Date], [Item], [Day], [Date], [Time], [To_From], [Type], [KB_Msg_Min], [Rate_Pd], [Rate_Code], [Feature], [In_Out], [Intl_Tax], [Roaming_indicator], [Total_Charge])
Select
[Foundation Account Number], [Foundation Account Name],
[Billing Account Number], [Billing Account Name],
[dbo].[Master_Wireless_Number].Wireless_ID,
LEFT([Market Cycle End Date],2) + '/' + SUBSTRING([Market Cycle End Date],3,2) + '/20' + RIGHT([Market Cycle End Date],2) as [Market Cycle End Date],
[Item], [Day],
LEFT([Date],2) + '/' + SUBSTRING([Date],3,2) + '/20' + RIGHT([Date],2) as [Date],
[Time], [To From], [Type], [KB Msg Min], [Rate Pd], [Rate Code],
[Feature], [In Out], [Intl Tax], [Roaming indicator],
[Total Charge]
FROM
[dbo].[Text_Import]
INNER JOIN
[dbo].[Master_Wireless_Number] ON [dbo].[Master_Wireless_Number].Wireless_Number = [dbo].[Text_Import].[Wireless Number]
------------------------------------------------------
--******* Voice Import 2 Append *********
------------------------------------------------------
INSERT INTO [dbo].[Voice_Import_2] (
[Foundation Account Number]
,[Foundation Account Name]
,[Billing Account Number]
,[Billing Account Name]
,[Wireless Number]
,[Market Cycle End Date]
,[Item]
,[Date]
,[Time]
,[Number Called]
,[Called To]
,[Minutes Charged]
,[Rate Pd]
,[Rate Code]
,[Feature]
,[Airtime Charge]
,[LD Add Charge]
,[Intl Tax]
,[Roaming indicator]
,[Total]
)
Select
[Foundation Account Number]
,[Foundation Account Name]
,[Billing Account Number]
,[Billing Account Name]
,Master_Wireless_Number.Wireless_ID
,LEFT([Market Cycle End Date],2) + '/' + SUBSTRING([Market Cycle End Date],3,2) + '/20' + RIGHT([Market Cycle End Date],2) as [Market Cycle End Date]
,[Item]
,LEFT([Date],2) + '/' + SUBSTRING([Date],3,2) + '/20' + RIGHT([Date],2) as [Date]
,[Time]
,[Number Called]
,[Called To]
,[Minutes Charged]
,[Rate Pd]
,[Rate Code]
,[Feature]
,[Airtime Charge]
,[LD Add Charge]
,[Intl Tax]
,[Roaming indicator]
,[Total]
FROM [dbo].[Voice_Import]
INNER JOIN [dbo].[Master_Wireless_Number] ON [dbo].[Master_Wireless_Number].Wireless_Number = [dbo].[Voice_Import].[Wireless Number]