[quoted text, click to view] "SQL Newbie" <sql@gospamyourself.com> wrote in message
news:e3gVvT%232EHA.1144@TK2MSFTNGP09.phx.gbl...
> > > Isn't it completely redundant ...
> >
> > No. SQL Server is free to use any single index or combination of indexes
> or
> > no index at all. The only way to find out what was used is by looking at
> the
> > execution plan.
> >
> > / Fredrik
> >
>
> But the execution plans changes over time, correct? (Based on data
growth,
> usage, etc.)
Yes
[quoted text, click to view] > Is the only way to truly keep on top of things is to test
> every query all the time? I'm looking for general practices here. For
> high-value queries then perhaps it would be wise to test different types
of
> indexes to see what worked best.
No. You only need to test your queries when you feel that the response time
is to slow. You only need to optimize until you reach a state wher
everything is good enough. Optimisations beyond this is a waste of time and
money. This is not only general practice, it is best practice.
[quoted text, click to view] > That leads to the follow-up question of: is there a way to tell if SQL
> Server isn't utilizing an index? (Say there is an index in place on
> customer+order+product and another index in place that I would consider to
> be a totally redundant on customer+order. It would be nice to track that
> customer+order hardly ever gets utilized.so the extra cost of having the
> index would outweigh any benefits of having the index in the first
place...
> (See what I mean?) Is there a tool that spits out this kind of index
bloat?
> Or is the tool labeled "DBA"? :)
Hmmm. You may make many different kind of queries Some of them will use an
index and some of them won't. I remember you asked "What if I update order
frequently?". I would suggest a single index on order rather than
customer+order
There's another problem. Isn't it reasonable to assume that you have more
orders than customers? The "orders" column" is more selective than
customers. Hopefully, you have more customers than products. The most
selective column should come first. In other words
order+customer+product is better than
customer+order+product
You don't need to change the table, only the index
[quoted text, click to view] > There are some 'redundant' indexes currently in place (that I didn't put
> there)
Like a customer+products index?
[quoted text, click to view] > and I don't want to simply remove them without debating on the
> consequences first. I'm obviously not a DBA and they weren't placed there
> by a DBA either. I will start testing queries and manually test to see
if
> SQL is choosing an executation plan that includes the redundant index but
> wouldn't it be difficult to know exactly if the extra cost of having the
> redundant index is worth it?
Why? Why do you want to know whether an index is used or not??? Some queries
do and some queries don't. What you should test is how your database
performs. That's the only thing that truly matters. Who cares whether an
index is used or not? Your customers certainly don't.
If I remove the redundant index, then SQL
[quoted text, click to view] > would simply (assumedly) choose a plan based on the bigger index ... and
if
> that is the case, and if the read costs are about the same for the server,
> then I'm assuming that it would be general practice to remove the
redundant
> index. I guess it simply takes experience to know if the read costs are
> 'about the same' = keep the index or drop the index?
>