Blogs

Leveraging SQL Server Partitioning for Performance Boost

Leveraging SQL Server Partitioning for Performance Boost

23-Apr-24

Invia, a renowned name in the telecom industry, has developed a cutting-edge application named My Fleet Manager (MFM). MFM is designed to offer an intuitive dashboard experience for enterprise customers. A critical component behind this application’s efficiency is its data handling capability. In this article, we will delve into how we used SQL Server partitioning to optimize our “rated_event” table, which holds approximately 10 billion records across 150 columns.

The Challenge

MFM is supported by the backend system known as PCX. PCX is the data warehouse for the MFM application. The “rated_event” table is the heart of the PCX system. It stores detailed information about every rated event in the telecom system. With the sheer volume of records, querying this table for specific data could become quite slow, resulting in a suboptimal user experience.

The Solution: Partitioning

To overcome this challenge, we decided to partition the “rated_event” table. SQL Server partitioning allows large tables to be broken down into smaller, more manageable pieces, yet still accessed as a single table. This can significantly enhance query performance by enabling more efficient data access.

Partitioning Strategy

Our partitioning strategy focused on the “event_date” column, which records when each event occurred. We decided to use range partitioning, creating partitions based on the event date. This approach is logical since most queries on the “rated_event” table are time-bound.

Step 1: Defining the Partition Function

The first step in our partitioning process was to create a partition function. This function defines how the rows in the table are divided into partitions.

CREATE PARTITION FUNCTION EventDatePartitionFunction (datetime) AS RANGE RIGHT FOR VALUES (‘2022–01–01’, ‘2022–02–01’, …, ‘2023–01–01’);

Here, we’ve created a partition function named EventDatePartitionFunction that partitions the data based on the ‘event_date’ column, which is of datetime data type. The data is partitioned such that each partition contains all the rows with ‘event_date’ values in the same month.

Step 2: Defining the Partition Scheme

Next, we created a partition scheme to define where each partition should be stored. For our implementation, all partitions were stored on the primary filegroup, but this could be customized based on available storage and performance considerations.

CREATE PARTITION SCHEME EventDatePartitionScheme AS PARTITION EventDatePartitionFunction ALL TO ([PRIMARY]);

Step 3: Partitioning the “rated_event” Table

With the partition function and scheme in place, we were ready to partition the “rated_event” table. We did this by modifying the table definition to use the partition scheme for the ‘event_date’ column.

CREATE TABLE rated_event ( … (other columns) event_date datetime, … (other columns) ) ON EventDatePartitionScheme(event_date);

This table creation script creates the “rated_event” table with partitioning applied on the ‘event_date’ column. The table will be partitioned based on the EventDatePartitionScheme we defined earlier.

Maintenance Benefits

One of the significant advantages of partitioning the “rated_event” table is the ease of index maintenance. Full index rebuilds used to take around 30 hours, which resulted in significant downtime for our application. With partitioning, we can now rebuild individual monthly index partitions, which takes approximately 30 minutes per partition. This drastically reduces the downtime required for maintenance tasks and allows us to perform these tasks more frequently, ensuring optimal performance.

SQL Server partitioning also enables efficient management of large tables by allowing the truncation of specific partitions. This feature is particularly advantageous when dealing with massive datasets, as it enables targeted removal of data, reducing the impact on system resources and enhancing overall performance. Truncating a specific partition is a precise and speedy operation compared to truncating the entire table, making it a valuable tool for database administrators in optimizing data maintenance tasks.

The Outcome

The partitioning process was a resounding success. Query performance improved significantly, with some queries seeing a performance improvement of up to 70%. The application’s users experienced faster and more responsive dashboards, leading to increased satisfaction and productivity.

Best Practices and Considerations

While partitioning significantly improved our performance, it’s important to note that it’s not a one-size-fits-all solution. Here are some best practices and considerations:

  1. Choose the Right Partition Key: The choice of the partition key is crucial. It should be a column that is often used in where clauses and can evenly distribute the data across partitions.
  2. Monitor and Maintain Partitions: Over time, data distribution can change. Regular monitoring and maintenance of partitions, including splitting and merging partitions, is necessary to ensure continued performance benefits.
  3. Test Thoroughly: Always test partitioning strategies in a non-production environment first. This will help you understand the impact on performance and ensure there are no unforeseen issues.

Conclusion

Partitioning the “rated_event” table was a key step in optimizing the performance of the MFM application at Invia. It is a testament to how database design and administration techniques can be leveraged to support the needs of large-scale applications. By carefully planning and implementing SQL Server partitioning, we were able to significantly enhance the user experience and overall performance of our application. Implementing SQL Server partitioning for the “rated_event” table at Invia has been a game-changer. It has not only improved query performance but also streamlined our maintenance tasks. By partitioning the table based on the “event_date” column and aligning the indexes with the partitioning scheme, we have achieved significant performance gains and reduced downtime for our MFM application. This has allowed us to provide the best flexibility and service to our enterprise customers in the telecom industry.