代码之家  ›  专栏  ›  技术社区  ›  Dan Short

执行选择非常慢

  •  0
  • Dan Short  · 技术社区  · 16 年前

    我有一个包含7526511条记录的表,定义如下:

    /****** 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分钟,但它仍然没有返回我请求的单行。这种类型的慢选择性能对数据库有其他影响,例如,很难除去不再需要的行。

    你知道我的瓶颈在哪里吗?98 Gig数据库及其日志运行在SQL Server 2008上的4磁盘RAID 10上,驱动器上有超过100 Gig的可用空间。

    2 回复  |  直到 9 年前
        1
  •  0
  •   HLGEM    16 年前

    你检查过是否有阻塞问题吗?

        2
  •  0
  •   Sergiy Tytarenko    9 年前

    创建另一个具有所需结构的表并在其中复制/泵送数据,然后删除旧表并重命名新表是否有用?对于特定的ID范围,您可能需要在“批”中执行此操作:

    INSERT INTO LogSearches_new ... SELECT * FROM LogSearches WHERE ID BETWEEN 1 AND 999999