June 10, 2009 at 8:54 am
Hi All,
I currently have a dilemma, its to do with a table and also its current schema. At the moment, it has a nonclustered unique index on the ClientMatchID column, as this is more like the identifier column on the table, this column is often used within joins with other table.
CREATE TABLE [dbo].[ClientMatchPort](
[ClientMatchID] [int] NOT NULL,
[CodeVendorID] [int] NOT NULL,
[StockID] [int] NOT NULL,
[ClientMatchValue] [varchar](50) NOT NULL,
[LastRevised] [datetime] NULL,
[ActivationDate] [datetime] NULL,
[TrunkID] [bigint] NULL
)
On the other hand, the LastRevised column is often used as a where clause after joining the ClientMatchID column with other columns from other tables and inline views, there is no specific order to the joins.
My proposal is to make the ClientMatchID the Primary key and also clustered and create a nonclustered index on the LastRevised column. On speaking to a mate, his argument is that there are a lot of cases where there exists a WHERE clause looking at the LastRevised column.
My instinct tells me that best practices dictate that clustered indexes are not best placed on a date column.
Any thoughts ?
June 10, 2009 at 9:16 am
Dean Jones (6/10/2009)
Hi All,I currently have a dilemma, its to do with a table and also its current schema. At the moment, it has a nonclustered unique index on the ClientMatchID column, as this is more like the identifier column on the table, this column is often used within joins with other table.
CREATE TABLE [dbo].[ClientMatchPort](
[ClientMatchID] [int] NOT NULL,
[CodeVendorID] [int] NOT NULL,
[StockID] [int] NOT NULL,
[ClientMatchValue] [varchar](50) NOT NULL,
[LastRevised] [datetime] NULL,
[ActivationDate] [datetime] NULL,
[TrunkID] [bigint] NULL
)
On the other hand, the LastRevised column is often used as a where clause after joining the ClientMatchID column with other columns from other tables and inline views, there is no specific order to the joins.
My proposal is to make the ClientMatchID the Primary key and also clustered and create a nonclustered index on the LastRevised column. On speaking to a mate, his argument is that there are a lot of cases where there exists a WHERE clause looking at the LastRevised column.
My instinct tells me that best practices dictate that clustered indexes are not best placed on a date column.
Any thoughts ?
If your date queries are range based, then the clustered index on the date column may be worthwhile. Remember, the clustered index is the order in which the data is physically stored on disk.
June 10, 2009 at 5:30 pm
The column which is used the most for RANGE SELECTION (between, >, <) should be chosen for clustered index.
Then all records from the selection will be located consequently.
_____________
Code for TallyGenerator
June 10, 2009 at 7:51 pm
Lynn Pettis (6/10/2009)
If your date queries are range based, then the clustered index on the date column may be worthwhile. Remember, the clustered index is the order in which the data is physically stored on disk.
Kind of. Data within each page is in order. Pages may not be in order, especially after page splits, but are treated logically as if they were.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 15, 2009 at 11:28 am
An important thing you need to consider here is the usage of "LastRevised" column. As the name indicates, I assume, it stores the last modified date of the record. In that case, if you have a clustered index on "LastRevised" column, the row has to physically move whenever you update the column. That will affect your update performance. So it all depends what performance (insert/update/select) is important to you.
June 15, 2009 at 11:53 am
Thanks for the reply, but doesnt thesame rule apply if the Clustered index was on an integer column ?
August 14, 2009 at 2:11 pm
Sorry for the late reply.
Yes. That's why it's better to avoid clustered index on a column which values would change constantly.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply