Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Server Query and Index Tuning

Similar presentations


Presentation on theme: "SQL Server Query and Index Tuning"— Presentation transcript:

1 SQL Server Query and Index Tuning
Mladen Prajdić dSolutions SI

2 About me

3 Server troubleshooting Data structures
Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning

4 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

5 Server troubleshooting Data structures
Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning

6 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

7 Data structures clustered index
Data pages are logically ordered All data on the leaf node Fill factor Uniquifier

8 Data structures Nonclustered index
Pointers to actual pages with data CI key or RID Uniquifier Included columns

9 Server troubleshooting Data structures
Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning

10 Indexing practices and troubleshooting
THE ENDLESS CLUSTERED INDEX DEBATE Clustered index <> Primary Key Int, DateTime, Guid, Composite columns Page splits Fragmentation (CI and NCI)

11 Indexing practices and troubleshooting
THE ENDLESS CLUSTERED INDEX DEBATE Type CI width (b) Rows NCI num Size(Mb) INT 4 10 57.2 DATETIME 8 114.5 GUID 16 228.9 OTHER 32 457.8 Know your data!

12 Indexing practices and troubleshooting
Problem? Diagnose Tune Test INDEX ANALYSIS

13 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

14 Indexing practices and troubleshooting
INDEXING POINTERS Foreign keys One multicolumn or multiple single column indexes Beware of Bookmark Lookup Included columns

15 Indexing practices and troubleshooting
TIPPING POINT Only valid for non-covering nonclustered indexes

16 Indexing practices and troubleshooting
ENTERPRISE EDITION FEATURES Compresion sp_estimate_data_compression_savings Filtered indexes Somewhat limited functionality

17 Indexing practices and troubleshooting
STATISTICS Value frequency histogram Async auto update stats Needed to build better execution plans Multicolumn, Custom and Filtered stats

18 Indexing practices and troubleshooting
STATISTICS

19 Indexing practices and troubleshooting
QUICK SUMMARY Narrow, increasing values for keys Try to eliminate bookmark lookup Included columns are your friend Statistics maintenance

20 Server troubleshooting Data structures
Agenda Server troubleshooting Data structures Indexing practices and troubleshooting Query tuning

21 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

22 Solution for every performance problem
Query tuning Solution for every performance problem NOLOCK JUST KIDDING 

23 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! 

24 Forced Parameterization
„Magic“ bullets Forced Parameterization Optimize for ad hoc workloads

25 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

26 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. . Z izpolnjevanjem le tega pripomorete k izboljšanju konference. Hvala!


Download ppt "SQL Server Query and Index Tuning"

Similar presentations


Ads by Google