I just had a situation where I had to include a column in an index. This required dropping the index, and recreating it. This got me thinking, surely that's a lot of unnecessary work.
Say I had instead created the new index first, then dropped the old one. Let's also assume that I have some way of indicating that the old index will not be dropped until after the new one has been created.
Would the server get any performance benefit by using the old index while creating the new one?
Best Answer
You can do
There is no particular advantage of doing so in the first case.
Whilst the existing index provides the desired sort order it will not be used for this as it does not contain the newly added column
B
and so it would require a lookup back to the base table for each row. The plan shows a table scan and sort.The use of
DROP_EXISTING
here could provide benefit if you were removing an included column though - as in the secondDROP_EXISTING
example (as the original index would both have the desired order and cover all columns).The plan for this shows that the original index was read to create the replacement.