0

I have a partitioned table that contains approx. 16 billion rows. The table has a clustered columnstore index and one partition aligned non-clustered index. The partitions are all on the same filegroup. The table is partitioned by day. I plan to run a weekly process that truncates partitions containing data older than 90 days. The process also removes the partition (using a partition function merge range stmt). During a given weekly run, there may be approx. 500 million rows truncated across multiple partitions. Should I be rebuilding the indexes or updating stats after truncating that much data?

On SQL Server 2017

2
  • I wouldn't imagine you would need to, as the NC index itself is aligned to the partitions, therefore any dropped data is removed along the same lines. A statistics update might be prudent. For a non-aligned index maybe a periodic index rebuild, but not every night. Don't forget to leave an empty partition at each end always. Commented May 1, 2022 at 19:59
  • dup on MS Q&A Commented May 2, 2022 at 0:49

1 Answer 1

2

No need to rebuild indexes after the purge. A partition truncate and merge removes both data and storage from the table. The remaining partitions are unaffected by the purge operation and thus don't need rebuilding afterwards.

You probably don't need to bother update statistics for the clustered columnstore index unless you've created column statistics. The column segment value metadata, used for rowgroup elimination, is also removed by the purge.

Updating statistics on the non-clustered b-tree index after the purge is a good idea since there is only one stats blob per index. Stats will otherwise stale after the purge.

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

2 Comments

Does it make a difference if there are non-aligned indexes? (not relevant in this particular case)
@Charlieface, one cannot use partition-level truncate with a non-aligned index so you are right it's not relevant here. A DELETE would be required for the purge, in which case a reorg and stats update (or rebuild) would be appropriate.

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.