August 15, 2016 at 11:59 pm
Wanted to know how do I create partition function for date range >90 days
basically I need partition all the rows from Table A which are older than 90 days from today.
Also how do I make it dynamic so that it can run every 15 days for eg.
Thanks in advance for help
August 16, 2016 at 3:02 pm
khushbu (8/15/2016)
Wanted to know how do I create partition function for date range >90 daysbasically I need partition all the rows from Table A which are older than 90 days from today.
Also how do I make it dynamic so that it can run every 15 days for eg.
Thanks in advance for help
Google for "Sliding Window Example for Partitioning".
Shifting gears, why do you need to partition the table? If you're doing it for performance of code, forget about partitioning. Partitioning usually slows code down a bit because of the multiple B-Trees that are formed. A properly indexed monolithic table will almost always beat a partitioned table when it comes to performance even in light of so called "partition elimination", which relies on the very indexes that make monoliths so fast.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 16, 2016 at 3:11 pm
khushbu (8/15/2016)
Wanted to know how do I create partition function for date range >90 days
You don't. Not exactly
Partition boundaries have to be fixed values, so you can have a partition on dates where the boundary is '2016-08-01 00:00:00', not a certain number of days in the past.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 16, 2016 at 11:33 pm
Thanks All.
Its sad that only hard coded date needs to be given. I was wandering of having a variable and scheduling a job so that I don't have to change every time. <sigh>
The partition is not for performance gain but I need to delete huge number of records (over billion) and tables have FK relationship. Normal Delete takes long long time, we also tried move required data to new table, drop old table, rename and create FK.
Of all these table partition was fastest
August 17, 2016 at 11:18 am
you can automate it - but depending on your volumes and what you do with the partition of over 90 days you may have performance issues.
assume a weekly process.
current table has 2 partitions (range right)
1 - 2016-04-01
2 -
Determine new date = equal today - 90 days (assume for example that resulting date is 2016-04-08)
do alter partion split for this date
Now there are 3 partitions on the table
1 - 2016-04-01
2 - 2016-04-08
3 -
do a merge partition of 1 and 2
Now there are 2 partitions on the table
1 - 2016-04-08
2 -
August 17, 2016 at 2:49 pm
A strongly recommend against doing the above. It'll work, but not well. The guidelines for adding partitions is to ensure that no data needs to move from one partition to another. If you do a split where rows in one partition suddenly belong in a new partition, they have to be moved. It's essentially a delete/insert operation, which is exactly what you're trying to avoid doing by partitioning the table.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply