我有两个名为"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.
这是正常的吗?
答案 0 :(得分:1)
是的,这是正常的
您的2个DBCC命令已删除查询计划和缓存数据。必须再次从磁盘读取数据,这可能是主要的开销。
如果您添加SET STATISTICS IO ON
,您将在DBCC之后看到更多“物理页面读取”和“预读取”,因为数据是从磁盘加载的
我几乎从不运行它们。有关更多信息,请参阅这些dba.se问题