删除语句不使用索引

时间:2017-05-02 03:06:38

标签: sql-server sql-server-performance

我有一张包含以下架构的表格......

CREATE TABLE [dbo].[Object1](
[id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[Column1] [datetime] NOT NULL,
[Column2] [int] NOT NULL,
[Column4] [char](4) NOT NULL,
[Column5] [money] NOT NULL,
[Column6] [bigint] NOT NULL,
[Column7] [char](6) NOT NULL,
[Column3] [bit] NOT NULL,
[Column8] [bigint] NULL,
CONSTRAINT [pk_Object1] PRIMARY KEY NONCLUSTERED 
([id] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF
, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)) 
GO
ALTER TABLE [dbo].[Object1] ADD  CONSTRAINT [DF_Object1_Column1]  DEFAULT (getutcdate()) FOR [Column1]
GO
ALTER TABLE [dbo].[Object1] ADD  CONSTRAINT [DF_Object1_Column3]  DEFAULT ((0))     FOR [Column3]
GO

每晚都会对此表运行删除查询...

delete from Object1 
where ( Column1 < DATEADD(dd, -40, GETUTCDATE()) )
OR ( Column3 = ? and Column1 < DATEADD(dd, -3, GETUTCDATE()))

表格有

  1. Index2(id) - 群集,唯一位于PRIMARY
  2. Index3(id) - 位于PRIMARY的非聚集
  3. Index1(id) - 位于非聚集,唯一的主键上 PRIMARY
  4. Index4(Column7) - 位于PRIMARY的非聚集
  5. Index5(Column2,Column7,Column4,Column5) - 非聚集 位于PRIMARY
  6. 查询产生以下计划......

    Execution Plan for Delete Statement

    该语句导致高度并发的表中出现阻塞。阻塞会导致系统错误。

    如果我重新创建“Object1_IX”以覆盖“Object1”字段,这仍然会发生。该表有6,568,449行,每晚修剪约200,000个。

0 个答案:

没有答案