Index_2

1,920 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,920
On SlideShare
0
From Embeds
0
Number of Embeds
1,589
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Index_2

  1. 1. SQL Query Performance Analysis
  2. 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. 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. 4. Types of Index• Table without any index is called Heap• There are two type of index:1. Clustered index2. Non-Clustered index
  5. 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 a balanced tree(B tree).CREATE UNIQUE [CLUSTERED] INDEX <Name> ON <ObjectName>( <ColumnName> [ASC | DESC ] [ ,...n ] )
  6. 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. 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. 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. 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. 10. Based on clustered Index
  11. 11. Based on heap
  12. 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. 13. THANK YOU

×