1

我有 2 个名为"Users(60,0000 records),UserBasicInfo(60,0000 records)"的表,Users 表在 UsersID 列上有一个聚集索引。UserBasicInfo 表有一个 UsersID FK 指向 Users 表 UsersID 列,并且在UpdateTime,UsersID列上具有非聚集索引。

CREATE TABLE [dbo].[Users](
    [UsersID] [int] IDENTITY(100000,1) NOT NULL,
    [LoginUsersName] [nvarchar](50) NOT NULL,
    [LoginUsersPwd] [nvarchar](50) NOT NULL,
    [Email] [nvarchar](80) NOT NULL,
    [IsEnable] [int] NOT NULL,
    [CreateTime] [datetime] NOT NULL,
    [LastLoginTime] [datetime] NOT NULL,
    [LastLoginIp] [nvarchar](50) NOT NULL,
    [UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
    [UsersID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[UserBasicInfo](
    [UserBaicInfoID] [int] IDENTITY(1,1) NOT NULL,
    [UsersID] [int] NOT NULL,
    [ResumePoints] [nvarchar](50) NOT NULL,
    [IsChineseOrEnglish] [int] NOT NULL,
    [UserName] [nvarchar](50) NOT NULL,
    [Sex] [int] NOT NULL,
    [Height] [int] NOT NULL,
    [Birthday] [datetime] NOT NULL,
    [Age] [int] NOT NULL,
    [IDCard] [nvarchar](50) NOT NULL,
    [IsMarryed] [int] NOT NULL,
    [NativePlace] [nvarchar](50) NOT NULL,
    [PoliticalStatus] [int] NOT NULL,
    [CurrentAddress] [nvarchar](50) NOT NULL,
    [CurrentAddressDetail] [nvarchar](50) NOT NULL,
    [WorkExperience] [int] NOT NULL,
    [HighestEducation] [int] NOT NULL,
    [LogoPath] [nvarchar](200) NULL,
    [MobilePhone] [nvarchar](50) NOT NULL,
    [Phone] [nvarchar](50) NULL,
    [QQ] [nvarchar](50) NULL,
    [Blog] [nvarchar](300) NULL,
    [MicroBlog] [nvarchar](300) NULL,
    [PositionDesired] [nvarchar](100) NOT NULL,
    [IndustrySmallClass] [nvarchar](100) NULL,
    [PositionName] [nvarchar](100) NOT NULL,
    [PositionType] [int] NOT NULL,
    [WorkAddressLarge] [int] NOT NULL,
    [WorkAddressSmall] [nvarchar](200) NOT NULL,
    [WorkAddressSmallText] [nvarchar](100) NOT NULL,
    [Salary] [int] NOT NULL,
    [HousingRequirement] [int] NOT NULL,
    [ToWorkTime] [int] NOT NULL,
    [ResumeState] [int] NOT NULL,
    [IsSystemAdd] [int] NOT NULL,
    [CreateTime] [datetime] NOT NULL,
    [UpdateTime] [datetime] NOT NULL,
    [RefreshDateTime] [datetime] NOT NULL,
    [RefreshTime] [int] NOT NULL,
    [TotalTime] [int] NOT NULL,
 CONSTRAINT [PK_UserBasicInfo] PRIMARY KEY CLUSTERED 
(
    [UserBaicInfoID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
ALTER TABLE [dbo].[UserBasicInfo]  WITH CHECK ADD  CONSTRAINT [FK_UserBasicInfo_Users] FOREIGN KEY([UsersID])
REFERENCES [dbo].[Users] ([UsersID])

但执行速度慢:

DBCC DROPCLEANBUFFERS   
DBCC FREEPROCCACHE
SELECT TOP 100 * FROM Users U INNER JOIN UserBasicInfo UB ON UB.UsersID=U.UsersID ORDER BY UB.UpdateTime DESC

SQL Server Execution Times:
   CPU time = 16 ms,  elapsed time = 3568 ms.

在此处输入图像描述 然后快速执行以下:

SELECT TOP 100 * FROM Users U INNER JOIN UserBasicInfo UB ON UB.UsersID=U.UsersID ORDER BY UB.UpdateTime DESC

 SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 163 ms.

在此处输入图像描述

这是正常的?

4

1 回答 1

1

是的,这很正常

您的 2 个 DBCC 命令已经删除了查询计划和缓存数据。必须再次从磁盘读取数据,这可能是主要开销。

如果添加SET STATISTICS IO ON,您将在 DBCC 之后看到更多“物理页面读取”和“预读”,因为数据是从磁盘加载的

我几乎从不运行它们。有关更多信息,请参阅这些 dba.se 问题

于 2013-06-27T08:39:36.387 回答