optimising queries - series 4 designing effective indexes
TRANSCRIPT
www.dageop.com
Optimising Queries
®
OQ-04 Designing effective indexes
DR. SUBRAMANI PARAMASIVAM (MANI)
About me
Dr. SubraMANI ParamasivamPhD., MCT, MCSE, MCITP, MCP, MCTS, MCSACEO, Principal Consultant & Trainer @ DAGEOP (UK) Email: [email protected] Blog: http://dataap.org/blog
Follow Us
https://www.facebook.com/pages/YOUR-SQL-MAN-LTD/http://www.youtube.com/user/YourSQLMAN
https://twitter.com/dageop
https://uk.linkedin.com/in/dageop
Proud Sponsor
• SQLBits• SQL Saturdays• MCT Summit• SQL Server Geeks
Summit• Data Awareness
Programme• Dageop’s Data Day
®
www.DataAP.org
SPEAKER
Contents• OQ-04 Designing effective indexes• Relating indexes to query types• Providing alternate access paths• Increasing sort efficiency• Reducing I/O with covering indexes• Implementing sparse indexes
www.dageop.comOptimizing Queries
Designing effective indexes• Index helps performing better query results.• One Clustered index per table.• SQL Server 2008 R2: 249 Non-clustered index• SQL Server 2012: Supports 999 Non-clustered indexes per table.• Index usually created based on most commonly used column to
improve performance.
www.dageop.comOptimizing Queries
Designing effective indexes• Avoid over-indexing in heavily updated tables • Keep indexes narrow, with fewer columns possible.• Large number of indexes affect the performance of INSERT, UPDATE,
DELETE and MERGE statements.• Large numbers of indexes can help the performance of queries that do not
modify data (simple SELECT statements).• Indexing small tables is not advisable. Query optimizer takes longer to
traverse the index searching for data than to perform a simple table scan. • Indexed views can provide significant performance gains (with
aggregations, table joins, or a combination of aggregations and joins).www.dageop.comOptimizing Queries
Relating indexes to query types• Before creating an Index, analyse the columns that are being used• Create clustered or non clustered index on definite condition columns
used in the query.• Create the index on integer column for effective use.• Creating a clustered index on a Primary key is very effective..
www.dageop.comOptimizing Queries
Increasing sort efficiency• Creating index on sort column increases the performance. • Defining clustered index on sort column, already clustered index will store the
data in sorted order, letting you retrieve data without additional sorting.
• In earlier releases of SQL Server the indexes are created in ascending order by default. • For descending order additional sorting was required.
• SQL Server 2000 onwards indexes can be created in ascending or descending order.
www.dageop.comOptimizing Queries
Reducing I/O with Covering Indexes• Covering Index created for set of additional columns that are used in a
query.• Indexes plays a vital role in performance tuning. • Too many indexes or too many covering indexes will decrease the
performance.
• Non-Clustered index still don’t fire up the performance. • SQL Server 2005 introduced a concept called “Covering Indexes”
www.dageop.comOptimizing Queries
Implementing Sparse Indexes• Creating a filtered index on a sparse column makes the query perform
much efficient.• Sparse columns can be created which has NULL values for at least
>30% of the data in a specific column for better performance.• Creating a filtered Index on this sparse column will be much faster.
www.dageop.comOptimizing Queries
ReviewDesigning effective indexes
Relating indexes to query typesProviding alternate access pathsIncreasing sort efficiencyReducing I/O with covering indexesImplementing sparse indexes
www.dageop.com Optimizing Queries
®
www.dageop.com