There is one table with partition, where partition function and scheme is defined like below:
CREATE PARTITION FUNCTION DateRangePF (CHAR(8))
AS RANGE RIGHT FOR VALUES ('20180101','20190101')
CREATE PARTITION SCHEME DateRangePS
AS PARTITION DateRangePF TO (Y2018FG, Y2019FG);
There are lot of data into the partition with boundary value '20190101' and we decided to partition it into 4 parts with following boundary values and associated file groups:
- '20190101' with file group Y012019FG,
- '20190401' with file group Y042019FG,
- '20190701' with file group Y072019FG,
- '20191001' with file group Y102019FG.
Now, what could be the best strategy to switch the data from older single partition with boundary value '20190101' to these four partitions?
Best Answer
Assuming your partitioned table is aligned, use a similarly partitioned staging table for the partition maintenance. This will avoid the costly data movement and logging when non-empty partitions are split.
Below is an example gleaned from the DDL in your question. Note that your partition scheme DDL is incorrect since the partition function with 2 boundaries creates 3 partitions, with the first being for data prior to year 2018. All 3 partitions must be mapped to a filegroup so I used
PRIMARY
in this script. Not sure why you choseCHAR(8)
instead ofDATE
for the partitioning column data type sinceDATE
requires only 4 bytes per row compared to 8.