sq l performance tuning faq

Upload: smruti-ranjan

Post on 14-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Sq l Performance Tuning FAQ

    1/4

    1. Name five different tools which can be used for performance tuning and their associated purpose.Performance Monitor\System Monitor - Tool to capture macro level performance metrics.

    1. Profiler - Tool to capture micro level performance metrics based on the statements issued by alogin, against a database or from host name.

    2. Server Side Trace - System objects to write the detailed statement metrics to a table or file,similar to Profiler.

    3. Dynamic Management Views and Functions - SQL Server objects with low level metrics toprovide insight into a specific portion of SQL Server i.e. the database engine, query plans,

    Service Broker, etc.

    4. Management Studio's Built-In Performance Reports - Ability to capture point in time metrics aspre-defined by Microsoft.

    5. Custom scripts - Custom scripts can be developed to monitor performance, determine IO usage,monitor fragmentation, etc. all in an effort to improve performance.

    6. Third party applications - Performance monitoring and tuning applications from vendors in theSQL Server community.

    2. Explain how the hardware running SQL Server can help or hinder performance.1. Taxed CPUs will queue requests and hinder query performance.2. Insufficient memory could cause paging resulting in slow query performance.3. Incorrectly configured disk drives could exacerbate IO problems.

    3. Why is it important to avoid functions in the WHERE clause?Because SQL Server will scan the index or the table as opposed to seeking the data. The scan

    operation is a much more costly operation than a seek.

    Often a slightly different approach can be used to prevent using the function in the WHERE clause

    yielding a favorable query plan and high performance.

    4. How is it possible to capture the IO and time statistics for your queries?Use the SET STATISTICS IO and SET STATISTICS TIME settings in your queries or enable the settings in

    your Management Studio session.

    5. True or False - It is possible to correlate the Performance Monitor metrics with Profiler data in asingle SQL Server native product?

    True - This functionality is possible with SQL Server Profiler.

    6. How can I/O statistics be gathered and reviewed for individual database files?By using the fn_virtualfilestats function to capture the metrics.

    This process can be automated with a script to determine the file usage with numerous samples.

    7. What is a query plan and what is the value from a performance tuning perspective?A query plan is the physical break down of the code being passed to the SQL Server optimizer.

    The value from a performance tuning perspective is that each component of the query can be

    understood and the percentage of resource utilization can be determined at a micro level. As query

  • 7/27/2019 Sq l Performance Tuning FAQ

    2/4

    tuning is being conducted, the detailed metrics can be reviewed to compare the individual coding

    techniques to determine the best alternative.

    8. True or False - It is always beneficial to configure TempDB with an equal number of fixed sizedfiles as the number of CPU cores.

    False - With always being the operative word in the question.

    Depending on the version of SQL Server, the disk subsystem, load, queries, etc., a 1 to 1 ratio of files

    to cores may be necessary on high end SQL Servers with intense processing.

    If you do not have that luxury, a starting point may to be have half the number of tempdb files as

    compared to CPU cores.

    This is a configuration to load test and monitor closely depending on the type of processing, load,

    hardware, etc. that your SQL Server is expected to support.

    9. Explain the NOLOCK optimizer hint and some pros\cons of using the hint.The NOLOCK query hint allows SQL Server to ignore the normal locks that are placed and held for a

    transaction allowing the query to complete without having to wait for the first transaction to finish

    and therefore release the locks.

    This is one short term fix to help prevent locking, blocking or deadlocks.

    However, when the NOLOCK hint is used, dirty data is read which can compromise the results

    returned to the user.

    10.Explain three different approaches to capture a query plan.1. SHOWPLAN_TEXT2. SHOWPLAN_ALL3. Graphical Query Plan4. sys.dm_exec_query_optimizer_info5. sys.dm_exec_query_plan6. sys.dm_exec_query_stats

    11.True or False - A LEFT OUTER JOIN is always faster than a NOT EXISTS statement.False - With always being the operative word. Depending on the situation the OUTER JOIN may or

    may not be faster than a NOT EXISTS statement. It is necessary to test the techniques, review the

    query plans and tune the queries accordingly.12.Name three different options to capture the input (code) for a query in SQL Server.

    1. DBCC INPUTBUFFER2. fn_get_sql3. sys.dm_exec_sql_text

  • 7/27/2019 Sq l Performance Tuning FAQ

    3/4

    13.Explain why the NORECOMPUTE option of UPDATE STATISTICS is used.This command is used on a per table basis to prevent the table from having statistics automatically

    updated based on the 'Auto Update Statistics' database configuration.

    Taking this step will prevent UPDATE STATISTICS from running during an unexpected time of the day

    and cause performance problems.

    By setting this configuration it is necessary to manually UPDATE STATISTICS on a regular basis.

    14.Explain a SQL Server deadlock, how a deadlock can be identified, how it is a performance problemand some techniques to correct deadlocks.

    A deadlock is a situation where 2 spids have data locked and cannot release their lock until the

    opposing spid releases their lock. Depending on the severity of the deadlock, meaning the amount

    of data that is locked and the number of spids that are trying to access the same data, an entire

    chain of spids can have locks and cause a number of deadlocks, resulting in a performance issue.

    Deadlocks can be identified by Profiler in either textual, graphical or XML format.

    Deadlocks are a performance problem because they can prevent 2 or more processes from being

    able to process data. A deadlock chain can occur and impact hundreds of spids based on the data

    access patterns, number of users, object dependencies, etc.

    Deadlocks could require a database design change, T-SQL coding change to access the objects in the

    same order, separating reporting and OLTP applications, including NOLOCK statements in SELECT

    queries that can accept dirty data, etc.

    15.Please explain why SQL Server does not select the same query plan every time for the same code(with different parameters) and how SQL Server can be forced to use a specific query plan.The query plan is chosen based on the parameters and code being issued to the SQL Server

    optimizer. Unfortunately, a slightly different query plan can cause the query to execute much

    longer and use more resources than another query with exactly the same code and only parameter

    differences.

    The OPTIMIZE FOR hint can be used to specify what parameter value we want SQL Server to use

    when creating the execution plan. This is a SQL Server 2005 and beyond hint.

    16.What is Index Tuning Wizard?Index Tuning Wizard is a software application that identifies tables which have inefficient indexes. It

    makes recommendations on how indexes should be built on a database to optimize performance.

    The recommendations are based on T-SQL commands that the wizard analyzes.

    List out what Index Tuning Wizard can do.

    1. It identifies tables in need of an index change2. Implements recommendations3. Determines how a proposed change might affect performance

  • 7/27/2019 Sq l Performance Tuning FAQ

    4/4

    4. Has the capability to make indexes change immediately and schedule them5. Helps to tune indexes.

    17.Explain how partitioning an important part of database optimization is.Partitioning distributes database tables over different database which may reside on a different

    server. Vertical portioning helps to fit more rows on a database page to improve data access

    performance. Partitioning helps to do multiple tasks simultaneously. It increases performance. It

    helps to manage data.

    18.What is the purpose of SQL Profiler in SQL server?SQL Profiler captures SQL Server events from a server. The events are saved in a trace file that can

    be used to analyze and diagnose problem.

    The different purposes of using SQL Profiler are:

    It is used to find the cause of the problem by stepping through problem queries.

    It is very useful to analyze the cause of slow running queries.

    It can be used to tune workload of the SQL server.It also stores security-related actions that can be reviewed by a security administrator.

    SQL Profiler also supports auditing the actions performed on instances of SQL Server.

    19.How do you identify and correct a SQL Server performance issue?Identification - Use native tools like Profiler, Perfmon, system stored procedures, dynamic

    management views, custom stored procedures or third party tools

    Analysis - Analyze the data to determine the core problems Testing - Test the various options to ensure they perform better and do not cause worse

    performance in other portions of the application

    Knowledge sharing - Share your experience with the team to ensure they understand theproblem and solution, so the issue does not occur again

    20. How do you go about tuning a SQL Server query? Identify the query causing the issue. Review the query plan by issuing SHOWPLAN_TEXT, SHOWPLAN_ALL, Graphical Query Plan

    or sys.dm_exec_query_stats.

    Review the individual query components to determine which components of the query havethe highest cost.

    Outline options to improve the query such as moving from cursor based logic to set basedlogic or vice versa, changing the JOIN order, WHERE clause or ORDER BY clause, adding

    indexes, removing indexes, creating covering indexes,

    etc. Test the options to determine the associated performance improvement. o Implement the

    solution.