更改Azure SQL数据库存储过程后未更新实际执行计划

时间:2017-10-28 08:34:23

标签: sql-server azure-sql-database sql-execution-plan

我的Azure SQL数据库存储过程的实际执行计划指出了以下警告:

enter image description here

所以我在dbo.Interest_rate_changes中添加了一个持久的计算列,如下所示:

[Effective_date]  AS (CONVERT([date],CONVERT([nchar](8),[Effective_date_int]),(112))) PERSISTED NOT NULL

然后,我使用对Interest_date的引用替换了存储过程中对Interest_date_int的所有引用。

我再次运行查询,但实际执行计划中出现了相同的警告,即使存储过程中现在不存在对Effective_date_int的引用。

我尝试使用DBCC FREEPROCCACHE清除缓存,但Azure SQL数据库不允许这样做。

我做错了什么?

回应评论the actual execution plan is here

查询是这样的:

EXEC TEST_PopulateCachedDailyInterest 11,'2017-12-31'

存储过程是这样的(道歉我不是专业人士):

CREATE PROCEDURE [dbo].[TEST_PopulateCachedDailyInterest] (@entityid int = 0, @enddate date)
AS

SET NOCOUNT ON;

TRUNCATE TABLE TEST_CachedDailyInterest;

WITH A AS
(
SELECT
    MyEntity AS Entity,
    MyInstrument AS Instrument,
    Accrual_date AS AccrualDate,
    Balance_x_Par_value_x_Effective_rate AS AccrualNumerator,
    Yearfrac_reciprocal AS AccrualDenominator

FROM

(SELECT
    MyEntity,
    MyInstrument,
    Instrument_currency,
    Interest_convention,
    Yearfrac_date_shift,
    Calendar_date AS Accrual_date,
    (SELECT SUM(Units) FROM Unit_transactions_indexed WITH (NOEXPAND) WHERE Entity = MyEntity AND Instrument = MyInstrument AND DATEADD(day,Opening_balance_date_shift,Transaction_date) < Calendar_date) * Par_value *
    (SELECT TOP 1 Interest_rate  FROM Interest_rate_changes WHERE Instrument = MyInstrument AND DATEADD(day,Interest_date_shift, Effective_date) <= Calendar_date ORDER BY Effective_date DESC) AS Balance_x_Par_value_x_Effective_rate

FROM

(SELECT  MyEntity, MyInstrument, Min_date, Max_date, Opening_balance_date_shift, Interest_date_shift, Interest_convention, Yearfrac_date_shift, Par_value, Instrument_currency FROM
(SELECT MyEntity, MyInstrument, DATEADD(day,-3,MIN(Transaction_date)) AS Min_date, IIF(SUM(Units)<>0, @enddate, IIF(DATEADD(day,3,MAX(Transaction_date))>=@enddate, @enddate, DATEADD(day,3,MAX(Transaction_date)))) AS Max_date
FROM
(SELECT MyEntity, MyInstrument, Transaction_date, Units FROM
(SELECT Entity AS MyEntity, Instrument AS MyInstrument, Transaction_date, Units FROM Unit_transactions_indexed WITH (NOEXPAND)
WHERE Entity = @entityid AND Units <> 0 AND Units IS NOT NULL) AS A
INNER JOIN
(SELECT ID FROM Instruments WHERE Interest_type>0)  B
ON  A.MyInstrument = B.ID) C
GROUP BY MyEntity, MyInstrument)  D
INNER JOIN Instruments ON D.MyInstrument = Instruments.ID
INNER JOIN Interest_types ON Interest_type = Interest_types.ID) AS D

CROSS JOIN Calendar_dates WHERE Calendar_date BETWEEN Min_date AND Max_date) AS F

INNER JOIN Yearfracs_reciprocal WITH (NOEXPAND) ON Balance_x_Par_value_x_Effective_rate<>0 AND
            Balance_x_Par_value_x_Effective_rate IS NOT NULL AND
            Yearfrac_reciprocal IS NOT NULL AND
            DATEADD(day,-F.Yearfrac_date_shift,F.Accrual_date) = Yearfracs_reciprocal.Calendar_date AND
            Interest_convention = Convention_ID
)

INSERT INTO TEST_CachedDailyInterest
SELECT
Entity AS EntityId,
Instrument AS InstrumentId,
AccrualDate,
AccrualNumerator,
AccrualDenominator
FROM A
WHERE ISNULL(AccrualNumerator,0)<>0

dbo.Interest_rate_changes的表架构是:

CREATE TABLE [dbo].[Interest_rate_changes](
    [Instrument] [int] NOT NULL,
    [Effective_date_int] [int] NOT NULL,
    [Interest_rate] [decimal](9, 7) NOT NULL,
    [Effective_date]  AS (CONVERT([date],CONVERT([nchar](8),[Effective_date_int]),(112))) PERSISTED NOT NULL,
 CONSTRAINT [PK_Instrument_Date] PRIMARY KEY CLUSTERED 
(
    [Instrument] ASC,
    [Effective_date] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)

0 个答案:

没有答案