Use case for SQL server table partitioning
Often we are asked by our clients about Table Partitioning, and specifically, which tables will be good candidates to be partitioned? Here are some of the main use cases for Table Partitioning:
- You have the Enterprise Edition of SQL Server 2005 or higher.
- The table contains or will contain more than 5-6 million rows and growing fast, or its size is growing by around 1GB per month or more.
- The FULL backup is taking too long or the backup file is too large and older data is not being updated (i.e.: users can only update data from the last 3 months).
- Data needs to be archived or purged on a regular basis, potentially the current archiving or deletion of data is causing blocks or deadlocks to other processes.
- There is a NOT NULL date column or another NOT NULL sequential column that the table can be partitioned upon.
- Better if most queries are including the partitioned column in WHERE clauses (i.e: between the date range).
- Create a file and a filegroup per partition (even if the files are created in the same place). This way, it is easy to backup (i.e.: FILEGROUP backup), maintain and archive/purge.
- The best way to partition a table is by a date column because data is usually archived or purged by a date. If you do not have such a column, you may want to consider adding a column that will contain the current date/time when the row is created. This column can contain the default GETDATE(). Using an ID or a calculated column may cause too many headaches. If the application returns an error when adding the date column, consider using a view on top of the underlying partitioned table.
- Partitioning requires maintenance:
- To add files, filegroups and partitions on a regular basis and in advance.
- Monitor data growth and potentially modify the partition architecture (i.e.: move from a monthly partition to a weekly or daily partition).
- Archiving/purging partitions on a regular basis. Consider using a SWITCH partition for quick archiving and purging.
- You can defragment indexes per partition.
- Remember that statistics cannot be updated by partition, however, you may want to consider FILTERED INDEXES or FILTERED STATISTICS to avoid updating statistics on the entire table, as well as improving performance in specific cases.
- Consider using MAXDOP <> 1 on the instance level or for specific queries that span multiple partitions in order to take advantage of parallelism. Configure parallelism with caution.