Abstract
Periodic SqlServer database maintenance steps, like 1)updating statistics and 2)defragment indexes, can contribute to query performance.
1. Query performance problem – check DB maintenance
Our application is ASP.NET MVC on the SqlServer database, and we received complaints from one of our customers that some queries are timing out in the production system. So, we have a query performance problem.
We, of course, looked into a number of places for potential improvements, like rewriting C#/EF queries, Indexing strategies for the Tables involved in the query Execution plan, activating the “Query Store” tool, etc.
But also, one area appeared as a candidate for improvement, which is typically in the domain of the customer’s DBA/Database Analysts. Some database maintenance steps can contribute to query performance.
1.1. DB maintenance steps of interest
We identified 2 potential steps of interest.
- Update database statistics
- Defragment Indexes
Step 1. While doing query execution plan analysis via different tools available on our test system, we noticed that some statistics were not updated in 2 years. Database statistics are important since the query optimizer uses info like table cardinality to create an optimal execution plan. So, there is no harm in triggering the update procedure periodically by ourselves.
Step 2. Some tables in our database are growing very fast due to the number of daily transactions. So, indexes could become fragmented over time. Periodic index examination for fragmentation and rebuild can be beneficial. Only rebuilding an index can interfere with the regular operation of a database. Typically, it locks the table whose index is rebuilt against writes.
1.2. Automatic or manual execution
Depending on the customers' specific situation, we are considering 2 strategies for execution of the above steps.
- Manual maintenance execution
- Automatic periodic execution
Approach 1. The idea is to enable the ASP.NET application administrator to manually activate maintenance execution, based on need, via the application menu option at the time when he/she thinks is suitable for that environment. App administrators might not have DBA access or skills to run necessary stored procedures manually.
Approach 2. The idea is to schedule periodic execution of the maintenance steps above, for example, once a week when the database workload is low. Rebuilding an index can interfere with the regular operation of a database. Typically it locks the table whose index is rebuilt against writes.
2. Update database statistics
Based on [1]
- In some cases, you can improve query performance by using UPDATE STATISTICS or the stored procedure sp_updatestats to update statistics more frequently than the default updates.
- Updating statistics causes queries to recompile. We recommend not updating statistics too frequently.
- If using UPDATE STATISTICS or making changes through SQL Server Management Studio, it requires ALTER permission on the table or view.
- If using sp_updatestats requires membership in the sysadmin fixed server role or ownership of the database (dbo).





Join the conversation! Your thoughts help the community grow.