I have several large SQL Server tables where the current partition functions are not extended beyond this month, and the procedure that is supposed to split the partition function into new date ranges before the final partition has data in it did not run as expected.
All of these tables have a clustered columnstore index. While that index is in place you cannot split a partition function range if the partition you are splitting has data.
My strategy was to drop the clustered columnstore index from each table that uses the partition function, then update the partition scheme and split the partition function range as needed, then rebuild the clustered columnstore index.
It would look something like this:
USE [Database]
GO
DROP INDEX [reporting_ClaimStatus2_cci] ON [reporting].[ClaimStatus]
GO
------------------------------------
ALTER PARTITION SCHEME [PS_RPT1_Date_Month_Right]
NEXT USED [FG_ClaimDetail_2023M12]
GO
ALTER PARTITION FUNCTION [PF_RPT1_Date_Month_Right]()
SPLIT RANGE ( N'2023-12-01T00:00:00.000')
GO
------------------------------------------------------------
CREATE CLUSTERED COLUMNSTORE INDEX [reporting_ClaimStatus2_cci]
ON [reporting].[ClaimStatus]
WITH (DROP_EXISTING = OFF, COMPRESSION_DELAY = 0)
GO
My biggest issue is that I don't know how to estimate the amount of time or memory it will take to drop and recreate these indexes as some tables have more than 2B records.
Can you recommend how to estimate how long it will take to drop and recreate an index on a table, or can you recommend a different strategy for fixing the partitions?
Yes I can! Your observation of not being able to split a partition that has data in it is the key. The generally accepted best practice for avoiding that is to always have an empty partition on the side of the range that you're splitting. So, in your example (which I assume is in anticipation of the upcoming rollover into the month of December 2023), you'd also add a partition boundary for January 2024. Then, sometime in the month of December, you'll add a boundary for February 2024. By always staying one (or two, depending on how you're counting) month ahead of current, you're splitting an empty partition which is totally fine.
If you're paranoid, add a couple of partitions in there and stay several months ahead. Any way you do it though, I'd recommend adding monitoring for something like "Oh hey... there are fewer than «desired number» empty partitions at the end of the scheme. Might want to do something about that.".