Hi
i am working on a table with 3 milion record and i decide to create index on table and also use table partitioning to partition the table on date(year), i create index and partition in afew way but in all case after i query on table and i compare with old table(without index) it takes longer time to execute and return result.
i create index in diffrent way :
1) create 4 file group and partition table to each file group
ALTER DATABASE NewSyslog ADD FILEGROUP FileGroup1 ALTER DATABASE NewSyslog ADD FILEGROUP FileGroup2 ALTER DATABASE NewSyslog ADD FILEGROUP FileGroup3 ALTER DATABASE NewSyslog ADD FILEGROUP FileGroup4 --Create Database File ALTER DATABASE NewSyslog ADD FILE ( NAME = Logs1, FILENAME = 'E:\Syslog\logs_filegroup1.ndf', SIZE = 1MB ) TO FILEGROUP FileGroup1 GO ALTER DATABASE NewSyslog ADD FILE ( NAME = Logs2, FILENAME = 'E:\Syslog\logs_filegroup2.ndf', SIZE = 1MB ) TO FILEGROUP FileGroup2 GO ALTER DATABASE NewSyslog ADD FILE ( NAME = Logs3, FILENAME = 'E:\Syslog\logs_filegroup3.ndf', SIZE = 1MB ) TO FILEGROUP FileGroup3 GO ALTER DATABASE NewSyslog ADD FILE ( NAME = Logs4, FILENAME = 'E:\Syslog\logs_filegroup4.ndf', SIZE = 1MB ) TO FILEGROUP FileGroup4
then i create partition function and scheme like :
CREATE PARTITION FUNCTION HitDateRange (datetime) AS RANGE LEFT FOR VALUES ('1/1/2013', '1/1/2014', '1/1/2015') GO CREATE PARTITION SCHEME HitDateRangeScheme AS PARTITION HitDateRange TO ( FileGroup1, FileGroup2, FileGroup3, FileGroup4 )
so i create my table on partiton scheme
CREATE TABLE [dbo].[Logs]( [ID] [int] IDENTITY(1,1) NOT NULL, [Timestamp] [datetime] NOT NULL, [SourceIPAddress] [nvarchar](50) NOT NULL, [FullUrl] [nvarchar](4000) NOT NULL, [Url] [nvarchar](512) NOT NULL, [Action] [nvarchar](10) NOT NULL, [User] [nvarchar](50) NULL, [TTL] [int] NULL, CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED ([ID] ASC,[Timestamp])) ON [HitDateRangeScheme] ([Timestamp])
then i insert 3 milion record into table and then test the query performance on this table and the old table, i saw the query run a little faster on old table.
so i create an index below:
2)
Create NonClustered Index NI_User_Timestamp On [dbo].[Logs]([User],[Timestamp])
the result is slower than old table,
3) then i create Index Include :
Create NonClustered Index NI_User_SourceIPAddress_FullUrl_Url_TTL On [dbo].[Logs]([User],[Timestamp]) Include([SourceIPAddress],[FullUrl],[Url],[TTL])
then i query table
Select [Timestamp] ,[SourceIPAddress] ,[FullUrl], [Url], [User] ,[TTL] From dbo.Logs Where [Timestamp] Between '1/1/2012' And '12/29/2013' And [User] = 'bill'
i test my select query whitout where clause ... but still it is a little slower.
4)then i recreate the table with Index partitioning like :
Create NonClustered Index NI_IP_User On [dbo].[Logs]([User]) On [HitDateRangeScheme]([Timestamp])
5) also i partition my table just on primary, means that i did not create file group for each partition,All To ([Primary])
6) also i did not partition my table, i make clusterd index on ID, and a nonclustered index on [Timestamp],[User]
Create NonClustered Index NI_Timestamp_User On [dbo].[Logs]([User],[Timestamp])
7) i create a nonclustered index just on [User] Column
after all these step still my query on new table is still a little slower.
so thanks for any help
Alimardani