可能重复:
非聚集索引插入
我正在尝试计算在特定表上使用非聚集索引的成本,但我没有在插入的执行计划中看到任何维护成本。
该表如下所示:
CREATE TABLE [dbo].[ASPStateTempSessions](
[SessionId] [nvarchar](88) NOT NULL,
[Created] [datetime] NOT NULL,
[Expires] [datetime] NOT NULL,
[LockDate] [datetime] NOT NULL,
[LockDateLocal] [datetime] NOT NULL,
[LockCookie] [int] NOT NULL,
[Timeout] [int] NOT NULL,
[Locked] [bit] NOT NULL,
[SessionItemShort] [varbinary](7000) NULL,
[SessionItemLong] [image] NULL,
[Flags] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[SessionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[ASPStateTempSessions] ADD DEFAULT (getutcdate()) FOR [Created]
GO
ALTER TABLE [dbo].[ASPStateTempSessions] ADD DEFAULT ((0)) FOR [Flags]
GO
除了 [SessionID] 上的聚集索引外,它还具有以下非聚集索引
/****** Object: Index [Index_Expires] Script Date: 12/14/2012 10:13:58 ******/
CREATE NONCLUSTERED INDEX [Index_Expires] ON [dbo].[ASPStateTempSessions]
(
[Expires] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
但是当我为以下运行执行计划时,它会更新具有非聚集索引的列:
UPDATE [ASPState].dbo.ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETUTCDATE())
WHERE SessionId = '32gghltsuoesnvlzbehchp2m2014c0f1'
RETURN 0
我在执行计划中没有看到任何成本提及:
平时看不到吗?如何计算写入操作中该索引的成本?
尝试在Plan Explorer中生成实际计划。
对于一个狭窄的计划,实际成本不包括在 XML 中,因此您不会看到那些,但您至少能够看到非聚集索引受到影响。
在重复的问题中可以找到更多信息:
以及 Martin 之前指出的这些博客文章: