sql server - SQL Index - is this overlapping? -
i'm going through , removing duplicate , redundant indexes in sql database.
so if have 2 identical indexes delete.
if have overlapping indexes delete, example...
- index 1: brand, model
- index 2: brand, model, price
i delete index 1.
what indexes in same order fields?
- index 1: brand, model
- index 2: brand, price, model
can safely delete index 1 or not?
my guess no i'm not sure
no, not safe remove that. order , position of columns important.
the introduction of price
column between other 2 columns (brand
, model
) issue. without index on (brand,model)
, the model
values "in order" under brand
. price
column added before model
, model
values no longer "in order".
for example, query that's doing this:
where brand = 'foo' , model >= 'bar' , model <= 'cat'
can make effective use of index on (brand,model)
it use index on (brand,price,model)
, range scan on leading column brand
. after that, model values it's looking anywhere under that, under value of price, index less effective.
if don't have queries using index in (brand,model)
, safe drop it.
also, of these indexes may "unique" indexes uses enforce uniqueness, it's not safe remove those, unless there's equivalent index same columns in different order.
Comments
Post a Comment