Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver Subject: Re: Some questions about relational indexes and statistics in SS2005 Date: Tue, 07 May 2013 21:26:41 +0200 Organization: Erland Sommarskog Lines: 52 Message-ID: References: <34bd78e8-b0d3-447c-a5de-88d35d6b6383@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Info: mx05.eternal-september.org; posting-host="78e2ae7e6764121e217a035f19bdb315"; logging-data="26141"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+A1BSyIOUkFZuNVpSQLzYv" User-Agent: Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) Cancel-Lock: sha1:BZXDw56eYAaOWdqmoBvK7/NopRc= Xref: csiph.com comp.databases.ms-sqlserver:1470 (rja.carnegie@gmail.com) writes: > 1. A nonclustered index can "include" columns that are not part of > the index key: can this be done with a nonclustered primary key > constraint index? No. > but the workaround might be to /not/ have a primary key, > but have a unique nonclustered index with included columns, which > does everything except display that it is the table's primary key, You could, but I have never seen the need. But, yeah, I could see the scenario. > /or/, to create and then /disable/ the primary key index (if you > can do that), /and/ create the unique nonclustered index. You can't disable the PK. > 2. Will SQL Server ever automatically create a separate statistics group > on columns that are already the key of a clustered or nonclustered > index? And, if so, should I consider improving the index so that > it provides a satisfactory statistics group, and, how can I do that? Not sure that I understand the question, but SQL Server always creates statistics on the index columns. I have never heard "statistics group" before, but maybe you mean multi-column statistics. > (1) an index was created later than when the table was created, and a > statistics group was already auto-created on the columns before the > index was; Auto-stats are always single column statistics. Multi-column statistics are always user-initiated, either through CREATE INDEX or CREATE STATISTICS. > (3) an index and a statistics group are on more than one column > and have some of the same columns, or have columns in a different order; Then they are different indexes and statistics. Orders matter in both. > (4) a user-created statistics group has the same columns as an index. > Maybe all at the same time. All I know now is, they're there, > and I think they're a bad sign. If there is a user-defined statistics which has the same definition as an index, that statistics is redundant and should be dropped. -- Erland Sommarskog, Stockholm, esquel@sommarskog.se