Simple query on sys.dm_db_partition_stats
on user database is running for close to 30 mins whereas it used to complete in less than 5 seconds earlier.
Query is just to fetch the right partition for loading the data and is not reading any data from user databases. Same query ran and completed in less than 5 seconds on any other large user database. Looking at the execution plan for this db and query output messages, we observed for one Table 'sysrowsets' . Scan count 1, logical reads is hundreds of thousands whereas on other databases, it is less than a thousand.
Here is the output for reference.
Table 'sysrowsets'. Scan count 888, logical reads 3227880, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0.
We are unable to query this sysrowsets
directly as it is an underlying table. Able to query when connected via DAC but couldn't find anything abnormal from this.
Still wondering what the reason for this many reads is and why is it taking such long time.
SQL Server Version: 2019, Compatibility Level: 150
SELECT Max(pstats.partition_number) AS PartitionNumber
FROM sys.dm_db_partition_stats AS pstats(NOLOCK)
INNER JOIN sys.destination_data_spaces AS dds(NOLOCK) ON pstats.partition_number = dds.destination_id
INNER JOIN sys.partition_schemes AS ps(NOLOCK) ON dds.partition_scheme_id = ps.data_space_id
INNER JOIN sys.partition_functions AS pf(NOLOCK) ON ps.function_id = pf.function_id
LEFT JOIN sys.partition_range_values AS prv(NOLOCK) ON pf.function_id = prv.function_id
AND pstats.partition_number = (
CASE pf.boundary_value_on_right
WHEN 0
THEN prv.boundary_id
ELSE (prv.boundary_id + 1)
END
)
WHERE OBJECT_Name(pstats.object_id) = 'OBJECTNAME'
AND OBJECT_SCHEMA_NAME(pstats.object_id) = 'DBNAME'
Partitions are equally created on all the user databases. Not too many tables were created on the database recently. Adding to that, mentioned query is to fetch data from only system DMVs and no table from user databases is being read. Hence, I assume there is no scope to add indexes for performance improvements. Also, this behavior is being observed all of a sudden since last 4 days. We restored last week full backup and tested with same query and got results in less than 5 seconds. No significant changes or upgrades are done to system or database.