我有 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.
这是正常的?