Visualizes execution plan / statistics information
A query execution plan outlines how the SQL Server query optimizer actually ran (or will run).
An execution plan, simply put, is the result of the query optimizer's attempt to calculate the most efficient way to implement the request represented by the T-SQL query you submitted.
You can use the execution plan to identify the exact piece of SQL code that is causing the problem
Execution plan Facts about the SQL Query Analyzer
SQL Query Analyzer has number of steps, one of them is the query optimizer.
Optimizer uses the statistics to calculate the cost-based plan, the optimal way to execute the query. It calculates a number of plans.
Statistics exists for relevant columns and indexes.
Estimated execution plan is the output of the optimizer.
Actual execution plan is the output of the actual query execution
Estimated and Actual execution plan can differ if statistics is not accurate.
Column statistics Column statistics Generally, column statistics, if needed by the Query Optimizer, are generated automatically by SQL Server when queries are being optimized by the Query Optimizer.SQL Server's engine will update the statistic when:
When data is initially added to an empty table
The table had > 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records since that collection date
The table had < 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records + 20% of the row count from the previous statistics collection date
-There are two cases when SQL Server will not automatically create column statistics, even when they fit the criteria described above. These include: when the costs needed to create the column statistics are larger than the costs of the query plan; and when SQL Server is too busy. 6
Column statistics Column statistics continued There are two cases when SQL Server will not automatically create column statistics, even when they fit the criteria described in the previous sheet. These include:
When the costs needed to create the column statistics are larger than the costs of the query plan;
Each of them are less than ideal from a performance perspective. 10
Optimization General optimalisation steps: Use primairy keys Use foreign keys Use constrains Create indexes for the where clauses User ‘included’ indexes for query results (read) Use the execution plan for further optimalisation steps. Use the profiles, see next subject, verification of the previous steps. Note: For write actions it is better to have not to mutch indexes. 11 Use these by default in the design process, should be … for most of the joins.
IntroductionMaintenance Database maintenancetasks Managing data and transaction log files Eliminating index fragmentation Ensuring accurate, up-to-date statistics Establishing an effective backup strategy 22
Maintenancetasks Transaction log files Transaction log is separated file. Transaction file will grow for each database change. The steps of grow can be configured. 23
Maintenancetasks Index fragmentation Indexes are used for performance Indexes will be fragmented by delete, merge and insert actions. Indexes can also be fragmented by database (auto)shrink. Don’t use shrink! 24
Maintenancetasks Accurate, up-to-date statistics Provides information nessessary for the optimizer to make its calculation (Estimated and actual execution plan should be the same). Rebuild the statistics 25
Maintenancetasks Effective backup strategy Backup the actual data situation Back in time (transaction time) 26
Maintenancetasks Automatic processes in SQL Server:
SQL-T statements in a JOB scheduling
Executed with SQL statements for dedicated actions. Don’t use this for maintenance, use the Maintenance Plans.
Part of the database management tools. Part is called Maintenance Plans. Note: May generate unwanted overhead on a production system and “locks”. Plan maintenance at a ‘correct’ moment. 27
Run profiler when you expect performance issues and on regular basis.
Schedule maintenance Plans for the normal maintenance tasks.
Note: SQL Server instance installation and configuration is not part of this presentation. But for performance issues, your most ‘important’ databases/tables, could or must be configured on hardware/spindels with a fast raid configuration! 29
References Link references: E-Books* references: -SQL Server Execution Plans by Grant Fritchey, ISBN 978-1-906434-04-5 -Mastering SQL Server Profiler by Brad M McGehee, ISBN 978-1-906434-11-3 *eBooks also used for some pictures. 30