In this session, database experts Pini Dibask and Jason Hall reveal the lesser-known features that’ll help you improve database performance in record time.
2. Confidential2
• Introductions
• SQL Server 2017 – The Microsoft Story
• Enhancements for Improved Performance and Tuning
• Automated Tuning
• Adaptive Query Processing
• Query Store Enhancements
• “Smaller” Enhancements
• “Smart” Differential and Log Backups
• TempDB Monitoring
• Query Store Enhancements
• Pay the Bills
Agenda
3. Confidential3
• Jason Hall, Quest Software
• 13 years on the roller coaster of enterprise software
• Frequent presenter, booth jockey, web caster, blogger, etc…
• New York Mets and Buffalo Bills fan, living in Boston…
• I’m a lot like you!
Who is this guy?
4. Confidential4
• Very little formal training
• My only certification was a MSTS SQL 2005
• Googling
• Watching presentations
• Sandboxing
• Breaking stuff
• Figuring out how to fix it
Why am I a lot like you?
6. Confidential6
• Linux and containers are cool, and may be game changing
• Require significant infrastructure change to leverage
• Graph databases are cool
• Require developers to build applications that leverage them
• This presentation focuses more on those features that you (DBA’s) can take
advantage of shortly after upgrading…
SQL Server 2017
8. Confidential8
• “Automated” way to find and fix plan regression issues
• Leverages information found in the SQL Server Query Store
• Plan Regression
Automated Tuning
9. Confidential9
• Query store will track plan regression, and log when it is detected
• sys.dm_db_tuning_recommendations
Plan Regression
10. Confidential10
SELECT reason, score,
script = JSON_VALUE(details, '$.implementationDetails.script'),
planForceDetails.*,
estimated_gain = (regressedPlanExecutionCount+recommendedPlanExecutionCount)
*(regressedPlanCpuTimeAverage-recommendedPlanCpuTimeAverage)/1000000,
error_prone = IIF(regressedPlanErrorCount>recommendedPlanErrorCount, 'YES','NO')
FROM sys.dm_db_tuning_recommendations
CROSS APPLY OPENJSON (Details, '$.planForceDetails')
WITH ( [query_id] int '$.queryId',
[current plan_id] int '$.regressedPlanId',
[recommended plan_id] int '$.recommendedPlanId',
regressedPlanErrorCount int,
recommendedPlanErrorCount int,
regressedPlanExecutionCount int,
regressedPlanCpuTimeAverage float,
recommendedPlanExecutionCount int,
recommendedPlanCpuTimeAverage float
) as planForceDetails;
Fixing Plan Regression
12. Confidential12
• SQL Server can automatically apply recommendation if the estimated gain is
greater than 10, or if the current plan is error prone
ALTER DATABASE current
SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = ON );
• You can also manually follow recommendations using the script provided:
Fixing Plan Regression
13. Confidential13
• This is new…
• Query must run “bad” a few times before recommendation is made
• Query Store must be operational (READ_WRITE)
• Cleared on instance restart, no way to view history
• https://docs.microsoft.com/en-us/sql/relational-databases/automatic-
tuning/automatic-tuning
Considerations
15. Confidential15
• https://www.youtube.com/watch?v=szTmo6rTUjM
• Prior releases would generate a plan prior to execution, and stick with it
• Now:
• Interleaved Execution
• Helps with MSTVF’s
• “Downstream” operations benefit from improved query statistics
• Batch mode memory grant feedback
• Adjust memory grants during execution
• Batch mode adaptive joins
• Hold off on choosing a join type until the first join input has been determined
Adaptive Query Processing (Adaptive Joins)
17. Confidential17
• Wait stats now available in Query Store runtime stats
• DMV: sys.query_store_wait_stats
• Wait events are categorized into resource buckets
• Will likely lead to additional Query Store space consumption
• One row per plan, runtime interval, and wait event category
Statement Level Wait Events – Query Store
18. Confidential18
• Full documentation at:
• https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-
views/sys-query-store-wait-stats-transact-sql
Wait Stats Categories
Wait category Wait types include in the category
CPU SOS_SCHEDULER_YIELD
Lock LCK_M_%
Latch LATCH_%
Buffer Latch PAGELATCH_%
Buffer IO PAGEIOLATCH_%
Tran Log IO LOGMGR, LOGBUFFER, LOGMGR_RESERVE_APPEND, LOGMGR_FLUSH,
LOGMGR_PMM_LOG, CHKPT, WRITELOGF
Network IO ASYNC_NETWORK_IO, NET_WAITFOR_PACKET, PROXY_NETWORK_IO,
EXTERNAL_SCRIPT_NETWORK_IOF
Parallelism CXPACKET, EXCHANGE
Memory RESOURCE_SEMAPHORE, CMEMTHREAD, CMEMPARTITIONED,
EE_PMOLOCK, MEMORY_ALLOCATION_EXT,
RESERVED_MEMORY_ALLOCATION_EXT, MEMORY_GRANT_UPDATE
Other Disk IO ASYNC_IO_COMPLETION, IO_COMPLETION, BACKUPIO,
WRITE_COMPLETION, IO_QUEUE_LIMIT, IO_RETRY
20. “There is no such thing as a small
enhancement, only a small DBA who does not
take advantage of one.”
Jason Hall
21. Confidential21
• When should I perform a differential backup?
• Traditionally, DBA’s rely on static backup schedules
• What if the database hasn’t changed very much?
• What if it has?
• New information is available in the following DMV to determine how much
data has changed since the last full:
• sys.dm_db_file_space_usage
• Modified_extent_page_count
“Smart” Differential Backups
22. Confidential22
• Similarly, a new DMF will show how much space is used in a log file
• sys.dm_db_log_stats(database_id)
• Log space since the last log backup
• Backup the log every 5 GB instead of every 5 minutes…
“Smart” Log Backups
23. Confidential23
• No check for full backup availability
• No handling of file retention
• DMV must be queried manually
• Stay tuned…
Not That Smart!
25. Confidential25
• Installer now allows a max file size of up to 256GB
• Warning if IFI is not enabled
TempDB Improvements
26. Confidential26
• Depending on the isolation levels used, SQL Server maintains data “history”
in the Version Store.
• This may allow for users to query “old” versions of the data while data is
being updated.
• SQL Server tries to clean up the version store if it can
• Occasionally it can’t
• New DMV exposes a database by database breakdown of version store
usage
• sys.dm_tran_version_store_space_usage
• Very useful for planning and migrating databases, while considering their
impact on TempDB size
TempDB Version Store
28. Confidential28
• High numbers of VLF’s (Virtual Log Files) can have a negative impact on
performance
• Historically, the only way to see how many VLF’s were used was through a
DBCC command
• New DMF: sys.dm_db_log_info(DB_ID) exposes this info
New DMF for VLF’s…
30. Confidential30
• Pause and resume index rebuilds
• Performance improvements for small database backups
• Query Store runtime stats now flushed during DBCC CLONEDATABASE
• Enhanced processor information in sys.dm_os_sys_info
• Sockets, Cores, and Sockets per Core
Other Enhancements