我有一张包含7,526,511条记录的表格,其定义如下:
/****** Object: Table [dbo].[LogSearches] Script Date: 12/07/2009 09:23:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LogSearches](
[ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[Acct_ID] [int] NULL,
[RecordCount] [int] NOT NULL,
[PageNumber] [int] NOT NULL,
[Site_ID] [int] NOT NULL,
[SearchAPI] [bit] NOT NULL,
[FormSearch] [bit] NOT NULL,
[IPAddress] [varchar](15) NOT NULL,
[Domain] [nvarchar](150) NOT NULL,
[ScriptName] [nvarchar](500) NOT NULL,
[QueryString] [varchar](max) NULL,
[Referer] [nvarchar](1024) NOT NULL,
[SearchString] [nvarchar](max) NOT NULL,
[UserAgent] [nvarchar](2048) NULL,
[Processed] [datetime] NOT NULL,
[Created] [datetime] NOT NULL,
[IntegerIP] [int] NULL,
CONSTRAINT [PK_LogSearches] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[LogSearches] ADD CONSTRAINT [DF_LogSearches_Processed] DEFAULT (getdate()) FOR [Processed]
GO
ALTER TABLE [dbo].[LogSearches] ADD CONSTRAINT [DF_LogSearches_Created] DEFAULT (getdate()) FOR [Created]
GO
执行计划如下所示:
StmtText StmtId NodeId Parent PhysicalOp LogicalOp Argument DefinedValues EstimateRows EstimateIO EstimateCPU AvgRowSize TotalSubtreeCost OutputList Warnings Type Parallel EstimateExecutions
---------------------------------------------------------------------------------------- ----------- ----------- ----------- ------------------------------ ------------------------------ -------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------- ------------- ------------- ----------- ---------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------- ---------------------------------------------------------------- -------- ------------------
SELECT TOP 1 * FROM LogSearches 1 1 0 NULL NULL 1 NULL 1 NULL NULL NULL 0.0032832 NULL NULL SELECT 0 NULL
|--Top(TOP EXPRESSION:((1))) 1 2 1 Top Top TOP EXPRESSION:((1)) NULL 1 0 1E-07 11848 0.0032832 [LOALogs].[dbo].[LogSearches].[ID], [LOALogs].[dbo].[LogSearches].[Acct_ID], [LOALogs].[dbo].[LogSearches].[RecordCount], [LOALogs].[dbo].[LogSearches].[PageNumber], [LOALogs].[dbo].[LogSearches].[Site_ID], [LOALogs].[dbo].[LogSearches].[SearchAPI], [LOALo NULL PLAN_ROW 0 1
|--Clustered Index Scan(OBJECT:([LOALogs].[dbo].[LogSearches].[PK_LogSearches])) 1 3 2 Clustered Index Scan Clustered Index Scan OBJECT:([LOALogs].[dbo].[LogSearches].[PK_LogSearches]) [LOALogs].[dbo].[LogSearches].[ID], [LOALogs].[dbo].[LogSearches].[Acct_ID], [LOALogs].[dbo].[LogSearches].[RecordCount], [LOALogs].[dbo].[LogSearches].[PageNumber], [LOALogs].[dbo].[LogSearches].[Site_ID], [LOALogs].[dbo].[LogSearches].[SearchAPI], [LOALo 1 2956.71 8.279319 11848 0.0032831 [LOALogs].[dbo].[LogSearches].[ID], [LOALogs].[dbo].[LogSearches].[Acct_ID], [LOALogs].[dbo].[LogSearches].[RecordCount], [LOALogs].[dbo].[LogSearches].[PageNumber], [LOALogs].[dbo].[LogSearches].[Site_ID], [LOALogs].[dbo].[LogSearches].[SearchAPI], [LOALo NULL PLAN_ROW 0 1
(3 row(s) affected)
当我运行查询时,它没有在任何合理的时间范围内完成。我让查询运行超过5分钟,它仍然没有返回我要求的单行。这种类型的慢速SELECT性能对数据库产生了其他影响,例如难以摆脱我们不再需要的行。
你知道我的瓶颈可能在哪里吗? 98 gig数据库及其日志在SQL Server 2008上的4磁盘RAID 10上运行,驱动器上有超过100 GB的可用空间。
答案 0 :(得分:0)
您是否检查过您是否遇到阻塞问题?
答案 1 :(得分:0)
创建另一个具有所需结构的表并在那里复制/“泵”数据,然后删除旧表并重命名新表是否有用?对于特定的id范围,您可能需要“批量”执行此操作:
INSERT INTO LogSearches_new ... SELECT * FROM LogSearches WHERE ID BETWEEN 1 AND 999999