• 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


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Praveen Srivatsa Director, AsthraSoft Consulting Microsoft Regional Director, Bangalore Session Code:
  • 2. Using Indexes? Indexing basics Successful applications can ultimately fail due to bad performance as they grow You cannot optimize what you do not understand Understand SQL Data storage Index organization and utilization
  • 3. SQL Server Storage Hierarchy Database Extent 8 contiguous 64K data pages Once extent full, next record will take up a whole additional extent. Pre-allocating space saves time.
  • 4. SQL Server Storage Hierarchy Page 64K bytes # of records/page varies with bytes/record Types of Pages: Data and Index pages Page Split When page becomes full, it splits New page allocated: ½ data from old page moved to new Rows 8060 bytes and 1024 columns
  • 5. B-tree Key Points to Remember Tree portion includes key attributes only ordered as in create index statement Keys packed in index pages Fewer bytes per key -> more keys per page/extent -> fewer page faults per access. Clustered indexes have records at leafs Records are in data pages Data pages sequentially linked Non-Clustered indexes point into heap or tree portion of clustered index
  • 6. Create INDEX Options CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name ON <object> ( column [ ASC | DESC ] [ ,...n ] ) [ INCLUDE ( column_name [ ,...n ] ) ] [ WHERE <filter_predicate> ] [ WITH ( <relational_index_option> [ ,...n ] ) ] [ ON { partition_scheme_name ( column_name ) … ] PAD_INDEX = { ON | OFF } | FILLFACTOR = fillfactor | SORT_IN_TEMPDB = { ON | OFF } | IGNORE_DUP_KEY = { ON | OFF } | STATISTICS_NORECOMPUTE = { ON | OFF } | DROP_EXISTING = { ON | OFF } | ONLINE = { ON | OFF } | ALLOW_ROW_LOCKS = { ON | OFF } | ALLOW_PAGE_LOCKS = { ON | OFF } | MAXDOP = max_degree_of_parallelism | DATA_COMPRESSION = { NONE | ROW | PAGE} [ ON PARTITIONS ( { <partition_number_expression> | <range> } [ , ...n ] ) ]}
  • 7. Working with Indexes
  • 8. XML Indexes XML Columns support indexes Multiple indexes PRIMARY SECONDARY PATH VALUE PROPERTY
  • 9. XML Indexes
  • 10. Sparse Columns and Filtered Indexes Sparse Columns Reduced data storage Unused Columns Filtered Indexes Indexes with filters
  • 11. Sparse Columns and Filtered Indexes
  • 12. Maintaining Indexes Page Splits Insert/delete order and rate critical Fragmentation Not OS fragementation – e.g. defrag tool Happens when database grows, pages split, and then data eventually deleted. Btrees great on maintaining balance on insertions, but with deletes, can end up with many pages containing small # of records.
  • 13. Fragmentation Problems Wasted space Sql server allocates an extend at a time Could end up with an extent, containing single page, with single record. Thrashing (way too many disk hits) Could end up with page 1 of data on one extend, page 2 on another, page 3 on the first, page 4 on another, …. Records all over the place Bit better for inserts but really bad for reads!
  • 14. Identifying Page Splits and Fragmentation
  • 15. Summary All data manipulation language statements can benefit, from indexes, but inserts, deletes, and updates are slowed. Indexes take up space and require page hits. Clustered indexes usually faster than non- clustered Indexes need to be maintained on a regular basis – use DMVs Use indexing strategy for XML and CLR data as well.
  • 16. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.