SQL Server Query and Index Tuning Mladen Prajdić dSolutions SI
About me 1999...
Server troubleshooting Data structures Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning
Server troubleshootinG Perfmon SQL Profiler, SQL Trace Event Notifications Extended Events DMVs sys.dm_os_wait_stats sys.dm_exec_requests sys.dm_exec_sql_text sys.dm_exec_query_plan sys.dm_tran_locks
Server troubleshooting Data structures Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning
Data Pages in no logical order No page deallocations with delete Data structures HEAP Bulk inserts Staging tables Data Pages in no logical order No page deallocations with delete
Data structures clustered index Data pages are logically ordered All data on the leaf node Fill factor Uniquifier
Data structures Nonclustered index Pointers to actual pages with data CI key or RID Uniquifier Included columns
Server troubleshooting Data structures Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning
Indexing practices and troubleshooting THE ENDLESS CLUSTERED INDEX DEBATE Clustered index <> Primary Key Int, DateTime, Guid, Composite columns Page splits Fragmentation (CI and NCI)
Indexing practices and troubleshooting THE ENDLESS CLUSTERED INDEX DEBATE Type CI width (b) Rows NCI num Size(Mb) INT 4 1.500.000 10 57.2 DATETIME 8 114.5 GUID 16 228.9 OTHER 32 457.8 Know your data!
Indexing practices and troubleshooting Problem? Diagnose Tune Test INDEX ANALYSIS
Indexing practices and troubleshooting MISSING INDEXES 3 DMVs, Database Tuning Advisor, SSMS suggestions UNUSED INDEXES sys.dm_db_index_usage_stats FRAGMENTED INDEXES sys.dm_db_index_physical_stats
Indexing practices and troubleshooting INDEXING POINTERS Foreign keys One multicolumn or multiple single column indexes Beware of Bookmark Lookup Included columns
Indexing practices and troubleshooting TIPPING POINT Only valid for non-covering nonclustered indexes
Indexing practices and troubleshooting ENTERPRISE EDITION FEATURES Compresion sp_estimate_data_compression_savings Filtered indexes Somewhat limited functionality
Indexing practices and troubleshooting STATISTICS Value frequency histogram Async auto update stats Needed to build better execution plans Multicolumn, Custom and Filtered stats
Indexing practices and troubleshooting STATISTICS
Indexing practices and troubleshooting QUICK SUMMARY Narrow, increasing values for keys Try to eliminate bookmark lookup Included columns are your friend Statistics maintenance
Server troubleshooting Data structures Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning
SQL Profiler, SQL Trace, Extended events SET STATISTICS IO Query tuning SQL Profiler, SQL Trace, Extended events SET STATISTICS IO SET STATISTICS TIME Execution Plans Minimize logical reads and CPU
Solution for every performance problem Query tuning Solution for every performance problem NOLOCK JUST KIDDING
Report query with UDF and correlated subqueries in the select list Query TunNing Example: Report query with UDF and correlated subqueries in the select list We‘ll make it GO FASTER!
Forced Parameterization „Magic“ bullets Forced Parameterization Optimize for ad hoc workloads
Don‘t just add or remove indexes blindly Think set based Summary Know your data Don‘t just add or remove indexes blindly Think set based Scalar UDFs bad, Table valued UDFs good Use CROSS APPLY
VPRAŠANJA? Po zaključku predavanja prosim izpolnite vprašalnik. Vprašalniki bodo poslani na vaš e-naslov, dostopni pa bodo tudi preko profila na spletnem portalu konference. www.ntk.si . Z izpolnjevanjem le tega pripomorete k izboljšanju konference. Hvala!