Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1518

Is a column redundant in a nonclustered index if it's in the clustered index?

X-Received by 10.224.215.68 with SMTP id hd4mr10999268qab.5.1370959426981; Tue, 11 Jun 2013 07:03:46 -0700 (PDT)
X-Received by 10.49.61.229 with SMTP id t5mr764834qer.36.1370959426962; Tue, 11 Jun 2013 07:03:46 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!p1no4581483qaj.0!news-out.google.com!10ni1297qax.0!nntp.google.com!p1no4581480qaj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.databases.ms-sqlserver
Date Tue, 11 Jun 2013 07:03:46 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=194.83.173.135; posting-account=dELd-gkAAABehNzDMBP4sfQElk2tFztP
NNTP-Posting-Host 194.83.173.135
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <e19b3c72-590a-4534-9212-ab337adb3ba0@googlegroups.com> (permalink)
Subject Is a column redundant in a nonclustered index if it's in the clustered index?
From rja.carnegie@gmail.com
Injection-Date Tue, 11 Jun 2013 14:03:46 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.databases.ms-sqlserver:1518

Show key headers only | View raw


SQL Server 2005, and the question may not make sense.  Or the answer
may be "It doesn't matter very much which you choose".  But, here goes.

I'm considering using index statements such as,

ALTER TABLE     AliasSubject
ADD CONSTRAINT  PK_AliasSubject
PRIMARY KEY CLUSTERED (costcentre, AliasSubjectID)
;

CREATE NONCLUSTERED INDEX IX13_Ali_SeemisSubjectID ON AliasSubject
(SeemisSubjectID, costcentre)
;

costcentre is char(7), the other columns are char(2), the 
table row size is around 100 bytes, and the table has a few 
thousand rows.  [IX13_Ali_SeemisSubjectID] doesn't have
a unique key.

I think I understand that the nonclustered index is based on
the clustered index, so in a sense the clustered index key 
is there in the index.

I am rewriting a design in which the previous version of 
[IX13_Ali_SeemisSubjectID] has only [SeemisSubjectID] as key,
but I suspect that queries are going to involve both [costcentre]
and SeemisSubjectID] in a JOIN condition.

But I'm wondering:

1. Given that [costcentre] is the first term in the primary key 
and the clustered index, is it redundant, not useful, to tack on
[costcentre] at the end of  the non-unique key in the 
nonclustered index?

2. If instead I am considering the following nonclustered index,
is [costcentre] redundant?

CREATE NONCLUSTERED INDEX IX13_Ali_SeemisSubjectID ON AliasSubject
(SeemisSubjectID) INCLUDE (costcentre)
;

(This is very like the first nonclustered index with a shorter key,
but I think that a non-unique index internally uses a key 8 bytes 
longer that is unique, in which case it's a choice between 
10 bytes or 17, not 2 bytes or 9.)

3. Are the answers different if [SeemisSubjectID] is a unique key
but I also want to use [costcentre] in a JOIN condition?

I suppose there is also an argument to put the column in even if
it's redundant for query performance and makes the key longer and
less efficient, so that somebody coming to it after me can see 
that the column is considered important.  But I'm already
choosing to disbelieve the version that I found, that seems to
imply that the column isn't important.

Back to comp.databases.ms-sqlserver | Previous | NextNext in thread | Find similar


Thread

Is a column redundant in a nonclustered index if it's in the clustered index? rja.carnegie@gmail.com - 2013-06-11 07:03 -0700
  Re: Is a column redundant in a nonclustered index if it's in the clustered index? Erland Sommarskog <esquel@sommarskog.se> - 2013-06-11 20:53 +0200
    Re: Is a column redundant in a nonclustered index if it's in the clustered index? rja.carnegie@gmail.com - 2013-06-17 09:24 -0700

csiph-web