Your SlideShare is downloading. ×
Sql query analyzer & maintenance
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Sql query analyzer & maintenance

3,465
views

Published on

16 februari 2011 …

16 februari 2011

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,465
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SQL Analyzer tools&Database Maintenance
    Hans Schellingerhoudt
    16 februari 2011
    Presentation is createdforNspyre Technologie Group .Net
  • 2. Program
    2
  • 20.
    • SQL Query Analyzer
    3
  • 21. Introduction
    Introduction “Query Analyzer”
    • SQL Query Analyzer no longer exist as single “tool” (since SQL Server 2005/2008).
    • 22. Integrated in Management Studio.
    • 23. Visualizes execution plan / statistics information
    • 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 imple­ment the request represented by the T-SQL query you sub­mitted.
    • 26. You can use the execution plan to identify the exact piece of SQL code that is causing the problem
    4
  • 27. Execution plan
    Facts about the SQL Query Analyzer
    • SQL Query Analyzer has number of steps, one of them is the query optimizer.
    • 28. Optimizer uses the statistics to calculate the cost-based plan, the optimal way to execute the query. It calculates a number of plans.
    • 29. Statistics exists for relevant columns and indexes.
    • 30. Estimated execution plan is the output of the optimizer.
    • 31. Actual execution plan is the output of the actual query execution
    • 32. Estimated and Actual execution plan can differ if statistics is not accurate.
    5
  • 33. 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
    • 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
  • 36. 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;
    • 37. And when SQL Server is too busy.
    7
  • 38. Run analyzer
    How to run the SQL Query Analyser (and User statistics):
    • Open “new query” in management studio.
    • 39. Swith on the buttons “Actual execution plan” (and “User statistics”).
    • 40. Run the query and the information will be shown in the execution plan (en user statistics) windows.
    8
  • 41. Run analyzer
    Use the results of the execution plan:
    9
  • 42. Query tuning
    If you see any of the following in an execution plan, you should consider them warning signs and investigate them for potential performance problems:
    Each 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. User statistics
    User Statistics introduction:
    • Do not relate queries execution plan with query cost.
    • 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.
    • 49. Measure how much data is retrieved from server.
    • 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
  • 53.
    • Otheranalyzer tools (profiler)
    15
  • 54. Profilerintroduction
    16
    Database profiler
  • 55. Profiler
    17
    Using Profiler with the Database Engine Tuning Advisor
  • 56. TuningAdvisor
    18
    Using Profiler with the Database Engine Tuning Advisor
  • 57. TuningAdvisor
    19
    Using Profiler with the Database Engine Tuning Advisor
  • 58. TuningAdvisor
    20
  • 59.
    • Database Maintenance
    21
  • 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
  • 64. Maintenancetasks
    Effective backup strategy
    Backup the actual data situation
    Back in time (transaction time)
    26
  • 65. 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.
    • 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
  • 66. Maintenancetasks
    Demo Maintenance Plans
    28
  • 67. Conclusion
    General Conclusion
    • Use default design roles (create keys and indexes).
    • 68. Check important queries with an execute plan.
    • 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
  • 72. Questions?
    End of presentation
    31