1

One of the biggest benefits of table partitioning is that, "it is possible to rebuild an index on specific partition".

Imagine there is a partitioned table (has 12 partitions for now), which has clustered and a few non-clustered indices, all partition aligned.

I want to add a new nonclustered index to table, which does not have to be built for old partitions. I need this index for only the last 3 partitions.

So, how can I create a new nonclustered index for last 3 partitions of 12 partitioned table?

1 Answer 1

1

That is not possible. It would create problems for parameterized queries because the query planner would never statically know that the index can be used (except if there was a constant-expression predicate).

You can create a filtered index with `where partitionKey >= startOfSomePartition'. Your queries have to include this predicate statically, though.

You might try a view over two partitioned tables which have different schema. That's not very convenient to develop though.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 @usr We use the filtered index strategy on big fact table FKs. It helps us to minimize storage and maintenance costs. Since the filter has to be static (can't reference functions like GETDATE()) we usually drop and create once a week, using dynamic sql to build the new index predicate definition. Also, partition elimination is key to getting the index to be used, but that's a given any time you deal with big partitioned tables.
One item of note: filtered indexes using >=, <=, >, < work well unless you are using parameters, i.e. they only work if you are using literals in your where-clause and not a variable or parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.