У меня есть таблица с 193 569 270 строк в базе данных SQL Server 2005.В таблице представлены действия, выполняемые пользователями нашего сайта.Таблица определяется как:
<b>Name</b> <b>DataType</b>
ID int (identity) PK
ActivityTime datetime
PersonID int (should be an FK, but isn't)
ActivityTypeID int (should be an FK, but isn't)
Data1 varchar(50)
Data2 varchar(50)
У меня есть следующие индексы:
CREATE NONCLUSTERED INDEX [_MS_Sys_3] ON [dbo].[tblPersonActivity] ([PersonID] ASC)
INCLUDE ( [ID], [ActivityTime], [ActivityTypeID], [Data1], [Data2])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Activity] ON [dbo].[tblPersonActivity] ([PersonID] ASC, [ActivityTypeID] ASC, ActivityTime] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_tblPersonActivity_PersonArchive] ON [dbo].[tblPersonActivity] ([ActivityTime] ASC)
INCLUDE ([ID], [PersonID], [ActivityTypeID], [Data1], [Data2])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblPersonActivity] ADD CONSTRAINT [PK_tblPersonActivity] PRIMARY KEY CLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Это запрос, который я написал:
declare @archiveDate datetime
declare @curDate datetime
declare @startDate datetime
declare @curYear int
declare @preYear int
set @curDate = getdate()
set @curYear = year(@curDate)
set @preYear = @curYear - 1
set @archiveDate = @curDate
set @startDate = cast(('1/1/' + cast(@preYear as varchar(4))) as datetime)
declare @InactivePersons table
(PersonID int not null PRIMARY KEY)
insert into @InactiveBuyers
select
b.PersonID
from
HBM.dbo.tblPersons b with (INDEX(IX_tblPersons_InactiveDate_PersonID), nolock)
where
b.InactiveDate is not null
and b.InactiveDate '1/1/1900'
and b.InactiveDate '12/31/1899'
and b.InactiveDate = @StartDate
ПоследнийКогда я выполнял запрос, он выполнялся более 1 дня, прежде чем я его убил.Я что-то пропустил или это займет столько времени?
Спасибо за любую помощь, которую вы можете оказать.
Уэйн Э. Пфеффер