24. A query execution plan outlines how the SQL Server query optimizer actually ran (or will run).
25. 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.
26. You can use the execution plan to identify the exact piece of SQL code that is causing the problem4
27.
28. Optimizer uses the statistics to calculate the cost-based plan, the optimal way to execute the query. It calculates a number of plans.
34. 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
35. 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
44. SortEach of them are less than ideal from a performance perspective. 10
45. 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.
46.
47. The amount of the data returned is considerably large, which is causing any query to run slow.
48. Looking at the result set and looking at the user Statistics.
50. It will capture details for different trials and they are compared with each other.12
51. User statistics 13 Green arrows indicate improved statistics and red arrows indicate degrading statistics. A maximum of 10 trials are averaged in the display window
52. Demo Demo Query Analyser - Execution plan - User statistics 14
60. IntroductionMaintenance Database maintenancetasks Managing data and transaction log files Eliminating index fragmentation Ensuring accurate, up-to-date statistics Establishing an effective backup strategy 22
61. 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
62. 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
63. 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
69. Run profiler when you expect performance issues and on regular basis.
70. 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
71. 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