On our SQL Server database, we have a table that is partitioned on a date column. For each date, we inserted half a million records. We noticed that the query performance was good for dates that are closer to the partition start range and it gradually degraded for each date moving forward.
Here is my partition function
CREATE PARTITION FUNCTION partition_position_monthly (DATE)
AS RANGE RIGHT FOR VALUES ('2019-09-01', '2019-11-01');
Table
CREATE TABLE PartitionTest(
ID int IDENTITY(1,1) NOT NULL,
col1 varchar(256) ,
col2 varchar(128) ,
col3 varchar(128) ,
BusinessDate date , -- partition column
) ON partition_scheme_monthly(BusinessDate)
There is a clustered index on the BusinessDate column.
Here is the query used
select top 1000 * from PartitionTest where BusinessDate = ?
CPU and IO recordings for each business date
BusinessDate = 2019-09-01 CPU time = 31 ms Scan count 1, logical reads 80, physical reads 0,, read-ahead reads 0
BusinessDate = 2019-09-02 CPU time = 63 ms Scan count 1, logical reads 24905, physical reads 0, read-ahead reads 3131
BusinessDate = 2019-09-03 CPU time = 125 ms Scan count 1, logical reads 49727, physical reads 0, read-ahead reads 7
BusinessDate = 2019-09-04 CPU time = 172 ms Scan count 1, logical reads 74551, physical reads 0, read-ahead reads 7
BusinessDate = 2019-09-05 CPU time = 234 ms Scan count 1, logical reads 99376, physical reads 0, read-ahead reads 117
As you can see the CPU time and logical reads gradually kept on increasing for BusinessDates that are farther from the partition start range.
Is this the expected behaviour while fetching data from a partition?
We plan to do partition on monthly data, and the query response time for days that are towards the end of the month is beyond our acceptable limits. Is there a way to achieve constant CPU time and logical reads for each day in the partition?