Presentation is loading. Please wait.

Presentation is loading. Please wait.

Virtual techdays INDIA │ 18-20 august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI.

Similar presentations


Presentation on theme: "Virtual techdays INDIA │ 18-20 august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI."— Presentation transcript:

1 virtual techdays INDIA │ 18-20 august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI www.ExtremeExperts.com http://blogs.sqlxml.org/vinodkumar T: @vinodk_sql

2  Filtered Indexes  What  Why  How  Filtered Indexes vs. Indexed Views  Plan Reuseability virtual techdays INDIA │ 18-20 august 2010 A G E N D A

3  Filtered Indexes are an index on a subset of rows in a table  WHERE clause in CREATE INDEX  Filtered Statistics are stats over a subset of rows  No auto-created filtered statistics virtual techdays INDIA │ 18-20 august 2010 What is Filtered Index

4  Improve query performance  Improve plan quality  Statistics are more accurate  Reduce index size  Reduce index maintenance cost  Large number of indexes are feasible  Query optimizer will choose the right index virtual techdays INDIA │ 18-20 august 2010 Why use Filtered Index

5  Sparse columns  Most rows contain NULL  Also when small subset of rows contain NULL (e.g. End Date)  IsDeleted flag columns  Categories of data in same table  Bikes, Clothing, Accessories  Sets of related properties  IN clause  Window Search - different types of properties  Ranges of data values  Dollar amounts, time ranges, date ranges  SharePoint lists (AllUserData table)  Table partitions virtual techdays INDIA │ 18-20 august 2010 Why: Use Cases for Filtered Index

6  ::= {Conjunct [AND Conjunct]}  ::= { Disjunct | Comparison }  ::= { column IN (constant, …)}  ::= {column constant}  ::= IS | IS NOT | = | | ! = | > | > = | ! > | < | < = | ! < }  = NULL not supported (even with setting) virtual techdays INDIA │ 18-20 august 2010 How: Syntax

7  age = 10 and category > 20  age = 10 and category > 20 and category < 50  age in (10, 20, 30)  age in (10, 20) and category in (15, 25) virtual techdays INDIA │ 18-20 august 2010 Examples of Predicates

8  Filtered indices can only be created as non-clustered indices.  Filtered indexes are not allowed on views unless they are indexed views.  Filtered indexes cannot be created on XML, spatial, or fulltext indexes.  If a filtered index is marked Unique, it means for all the qualifying rows, the index values are unique.  The filter expression cannot reference a computed column or UDT virtual techdays INDIA │ 18-20 august 2010 Rules

9  No ALTER INDEX to alter where clause  Use CREATE INDEX WITH DROP_EXISTING = ON  Online operations work  DTA recommends filtered indexes  Missing indexes don't report filtered index virtual techdays INDIA │ 18-20 august 2010 Behaviors

10  SET options required  ANSI_NULLS - ON  ANSI_PADDING - ON  ANSI_WARNINGS - ON  ARITHABORT - ON (set by ANSI_WARNINGS - ON)  CONCAT_NULL_YIELDS_NULL - ON  NUMERIC_ROUNDABORT - OFF  QUOTED_IDENTIFIER - ON  If not set correctly:  Insert/update/delete don't work  Optimizer doesn't consider plan  Can’t create index virtual techdays INDIA │ 18-20 august 2010 SET Options

11  Must match exactly  Filtered index col > 500  Col > @a - no  Col > @a and Col > 500 - yes  Don't get used with autoparameterization  If parameter could be outside the filter virtual techdays INDIA │ 18-20 august 2010 Parameterized Queries

12  Filtered Stats updated based on colmodctr  Filter predicate not considered  Filtered Stats use same sampling algorithm  Filter predicate not considered  Filtered stats can become  Out of date or updated too frequently  Not representative of true cardinality  Solution: Use scheduled stats update  with FULLSCAN virtual techdays INDIA │ 18-20 august 2010 Filtered Statistics And Updating

13  sys.indexes  sys.stats  sys.dependencies virtual techdays INDIA │ 18-20 august 2010 Metadata

14 virtual techdays INDIA │ 18-20 august 2010 DEMO: Filtered Index Explained and Explored !!! Vinod Kumar M www.ExtremeExperts.com

15  Filtered Indices work best on columns where the Filter index criteria is simple and filters out a major portion of the rows in the table.  These work best in situations where columns are sparsely populated and index criteria is used to select only data that is populated with relevant values.  Generally using filtered indexes are useful for Sparse columns where most of the values in the column are NULL.  If the index needs to cover all rows in a table, use a regular index  If not, and the filtering condition is simple (fits within the filtered index grammar set), use a filtered index.  If filtering condition is complex, use an indexed view. virtual techdays INDIA │ 18-20 august 2010 Best Practices

16 virtual techdays INDIA │ 18-20 august 2010 Technology Comparison

17  Filtered Indexes: an alternative to indexed views  Available in all SQL Server editions  Only simple filtering predicates  Variety of Uses  Sparse columns the biggest  Filtered Statistics: space saving over indexes  But watch sampling and updating virtual techdays INDIA │ 18-20 august 2010 Summary

18 virtual techdays THANKS │ 18-20 august 2010 www.ExtremeExperts.com http://blogs.sqlxml.org/vinodkumar T: @vinodk_sql


Download ppt "Virtual techdays INDIA │ 18-20 august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI."

Similar presentations


Ads by Google