Re: Indexing strategy



Ryan (ryanofford@xxxxxxxxxxx) writes:
ALTER TABLE [dbo].[DEALER_SOURCE_DATA_VALUES] WITH NOCHECK ADD
CONSTRAINT [PK_DEALER_SOURCE_DATA_VALUES] PRIMARY KEY CLUSTERED
(
[DEALER_SOURCE_DATA_ID],
[FIELD_CODE]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

This table has approx 25 million rows. I would have added indexes to
Dealer_Source_Data_Id and Field Code seperately. This table holds the
data ID which can be related back to a row in another table for the
year, month and Dealer ID. It also holds all lines and the value
against those lines. Quite often queries would be needed for everything
by the Dealer_Source_Data_Id hence the first index I would add. Also,
we want to sum (for example) all of a specific field_code, hence the
other index I would add.

We would normally have approx 4,000 unique Field_Codes per
Dealer_Source_Data_Id.

The PK is correct, but not good for querying what we need to as it
would only be used when we specify both Dealer_Source_Data_Id and
Field_Code in order to return a value. Correct ?

Not really. A query only by DEALER_SOURCE_DATA_ID would use the
clustered index. Unless you do queries like:

SELECT COUNT(*), DEALER_SOURCE_DATA_ID
FROM tbl
GROUP BY DEALER_SOURCE_DATA_ID

there is not reason to add an NC index on DEALER_SOURCE_DATA_ID.


But you are correct that the clustred index is not good for queries
on a certain FIELD_CODE.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: estimation the buffer cache hit ratio
    ... Now buffer cache hit ratio oscilate about 95-98. ... I would run Profiler and look for long-running queries. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Disable and Rebuild or Drop and recreate Index
    ... columns that are frequently used in those queries, ... disable and rebuild all index or just drop and recreate. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Can a View be protected to support "JOINS" only?
    ... SELECT * FROM MyView -- would fail ... custom query tool where the users only can build queries in some guided ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Error while transferring code from MSSQL 2000 to 2005
    ... queries: you get much better use of the plan cache in SQL Server. ... I see is a query, and I don't know about the underlying tables. ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: The best elegant solution to override 65k rows limit in a sheet
    ... Access ships with MSDE.. ... >SQL Server Books Online (again-- Access ships with freeware SQL Server ... better ways to achieve their results through queries. ...
    (microsoft.public.excel)

Loading