Re: Redundant Indexes?

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Erland Sommarskog (esquel_at_sommarskog.se)
Date: 12/27/04


Date: Mon, 27 Dec 2004 00:14:03 +0000 (UTC)

Jorge Luzarraga Castro (jluzarraga@fidens.cl) writes:
> I´ve got a table called 'prd_movcomision' (I´ve attached a script with its
> structure) which has several indexes as you can see. There are several
> indexes which are contained in others. For example:
>
> CREATE INDEX [A] ON [dbo].[prd_movcomision]([pers_rutcia], [poli_codigo],
> [itpo_codigo]) ON [PRIMARY]
> GO
>
> CREATE INDEX [B] ON [dbo].[prd_movcomision]([poli_codigo],
> [itpo_codigo])
> ON [PRIMARY]
> GO
>
> CREATE INDEX [C] ON [dbo].[prd_movcomision]([prop_codigo]) ON [PRIMARY]
> GO
>
>
> Given the previous indexes, [B] is contained within [A] and [C] is
> contained within [B]. The question is if this is really neccessary or
> once I have an index A the other indexes (B and C) are redundant.

There are no redudant indexes in your table. There may be unused indexes,
that I can't tell, because that depends on your queries.

While the columns index B is included in index A, a query like:

   SELECT * FROM tbl WHERE poli_coidgo = @val1 AND itpo_codigo = @val2

cannot seek index A to find any rows. It can scan the index, though.
The difference here is that "seek" means that SQL Server finds the
value by walking the fast way through the index tree. "scan" means
that SQL Server searches all leaf pages of the index, which is considerably
slower. In reality, SQL Server will probably scan the entire table instead,
which is even slower. (As a scan. Beside the scanning the index, SQL Server
will also have to access data pages, and with many hits, that can be more
data-pages access than a table scan.)

The same goes for index C, assuming that you mean to have itpo_codigo hear.

So the important issue here, is whether you actually have any queries for
which these indexes are useful.

> I´m having too many problems with the size of the database, it is
> growing too fast.

I don't think dropping indexes is a very good help to address that. In
such case it's better to examine whether there is data that is inserted
multiple times, data which is not removed as it should be etc.

Dropping an index can conserve some space - but it can also kill
performance, if there is a query which needs the index.

-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp


Relevant Pages

  • Re: Bulk inserting into database using ADO.NET... deadly slow?
    ... program (look in your SQL Server documentation for "BULK INSERT"). ... > the DataSet, so to reduce the DB updates, but I found that when reaching ... > about 100K rows the DataSet becomes slower and slower, ... why is it so painfully slow to insert big chunks ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: performance problem
    ... Define slower, and how big is the table after the inserts? ... Pro SQL Server 2000 Database Design ... > memory grows to more that 500 MB and the it doesn't free. ... > CRecordset) and when inserting binary data I must open query for edit ...
    (microsoft.public.sqlserver.programming)
  • Re: sql server i/o bottle neck ?
    ... 20% slower than Oracle. ... large log cache and large redolog - so lot happens in the cache before ... at least not SQL Server. ...
    (comp.databases.ms-sqlserver)
  • Re: Performance difference between SQL Server 2005 and 2008
    ... I can see some plans in 2008 needing a small tuning due to the differences in the optimizer but usually once you do they run faster. ... We in the process if migrating our SQL Server 2005 database Active/Active ... We have setup and configured SQL Server 2008 cluster and I ... Did anyone has similar experience when stored procedure ran slower ...
    (microsoft.public.sqlserver.programming)
  • Re: Replacement for Enterprise Manager?
    ... It was slower to load the SEM in our testing, ... I'll have to talk to our testers to see if we can ... the Professional Association for SQL Server. ...
    (microsoft.public.sqlserver.tools)