Your SlideShare is downloading. ×
Index
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

Index

161

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
161
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
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
  • 2. What is an index ?• Index is a way to organize data to make searching, sorting and grouping fasters• we need indexing when :1. WHERE, ON, HAVING clause (Searching)2. ORDER BY clause (Sorting)3. GROUP BY clause (Grouping) etc.
  • 3. Table scan:SELECT * FROM Student WHERE RollNo = 111Time complexity of table scan is : O(n)RollNo Name Country Age101 Greg UK 23102 Sachin India 21103 Akaram Pakistan 22107 Miyabi China 18108 Marry Russia 27109 Scott USA 31110 Benazir Banglades 17111 Miyabi Japan 24112 Rahul India 27113 Nicolus France 19
  • 4. Types of Index• Table without any index is called Heap• There are two type of index:1. Clustered index2. Non-Clustered index
  • 5. Clustered index• When we create a clustered index on any table physical organization of table is changed.• Now data of table is stored as binary search tree(B tree).CREATE UNIQUE [CLUSTERED] INDEX <Name> ON <ObjectName>( <ColumnName> [ASC | DESC ] [ ,...n ] )
  • 6. Types of scanning• Table scan: It is very slow can and it is used only if table has not any clustered index.• Index scan: It is also slow scan. It is used when table has clustered index and either in WHERE clause non-key columns are present or query has not been covered (will discuss later) or both.• Index Seek: It is very fast. Our goal is to achieve this.
  • 7. Clustered index• If we create table with primary key, sql server automatically creates clustered index on that table• A table can have only one clustered index .• Physical order of rows of table is same as logical order of key columns of clustered index.
  • 8. Terms of execution plan• Predicate: It is condition in WHERE clause which is either non- key column or column which has not been covered.• Object: It is name of source from where it getting the data. It can be name of table, Clustered index or non-clustered index• Output list: It is name of the columns which is getting from object.• Seek Predicate: It is condition in WHERE clause which is either key column or fully covered.
  • 9. Non-clustered index• It is logical organization of data of table. A non-clustered index can be of two types.1. Heap2. Based on clustered index.• If table has clustered index then leaf node of non-clustered index keeps the key columns of clustered index.• If the table has not any clustered index then leaf node of non- clustered index keeps RID which unique of each row of table.
  • 10. Based on clustered Index
  • 11. Based on heap
  • 12. Covering of queries• We can specify maximum 16 column names.• Sum of size of the columns cannot be more than 900 bytes.• All columns must belong to same table.• Data type of columns cannot be ntext, text, varchar (max), nvarchar (max), varbinary (max), xml, or image• It cannot be non-deterministic computed column.
  • 13. Statistics Analysis• The query optimizer uses statistics to create query plans that improve query performance• A correct statistics will lead to high-quality query plan.• Auto create and updates applies strictly to single-column statistics.• The query optimizer determines when statistics might be out- of-date by counting the number of data modifications since the last statistics update and comparing the number of modifications to a threshold.
  • 14. Goal• Should we use sub query or inner join?• Should we use temp table or table variable?Other tools:• Sql query profiler• Database Tuning Advisor• Resource Governor
  • 15. THANK YOU

×