• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,777
On Slideshare
0
From Embeds
0
Number of Embeds
25

Actions

Shares
Downloads
14
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 Query Performance Analysis Level 1
  • 2. Addhoc QueriesAny non-Parameterized queries are called addhoc queries. Forexample :SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100In sql server if we execute a sql query it goes through two stepsjust like any other programming languages:• 1. Compilation• 2. Execution
  • 3. Properties of addhoc query• Case sensitive• Space sensitive• Parameter sensitiveSql severs treats two same sql query but of different parametersas different sql statements. For example:• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
  • 4. Effect of faulty C# code• Sql server has took extra n * (Compilation time) ms to display records• Extra time to insert records in cached plans.• Sql server has to frequently fire a job to delete the cached plan since it will reach the max limit very soon.• It will not only decrease the performance of this sql query but all sql queries of other application since this faulty code will force to delete cached query plans of other sql statement.
  • 5. Prepared queriesExample:(@Msgid int)SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = @Msgid• It is not case, space and parameter sensitive and it is our goal.
  • 6. Query Processing• Non-Procedural: . SELECT, DELETE, UPDATE statements etc.• a. Analyze the query.• b. Get execution plan.• b. Process the query.• Procedural: Stored procedure, sql functions etc.
  • 7. Query Optimizer
  • 8. Query OptimizerThe query optimizer in SQL Server is cost-based. It includes:1. Cost for using different resources (CPU and IO)2. Total execution timeIt determines the cost by using:• Cardinality: The total number of rows processed at each level of a query plan with the help of histograms , predicates and constraint• Cost model of the algorithm: To perform various operations like sorting, searching, comparisons etc.
  • 9. Execution Plan and Caching• Query Plan• Execution Context• Database Engine uses a cost-based approach to determine which execution plans to remove from the procedure cache.
  • 10. Assignments• 1. Give any example in which join performs better than sub query.• 2. Give me any example in which order matters in WHERE clause.• 3. Give me any three examples which query returns same output but have different execution planhttp://msdn.microsoft.com/en- us/library/ms175913(v=sql.105).aspx
  • 11. THANK YOU