Quantcast
Channel: MSSQL Tiger Team
Viewing all 194 articles
Browse latest View live

SQL Server 2017 Showplan enhancements

$
0
0

In my previous post on Easy way to get statistics histogram programmatically, I referred to statistics as the building blocks on which the Query Optimizer reasons to compile a good enough plan to resolve queries. Knowing the status of distribution statistics over a given table and set of columns allows the user to have insight into how SQL Server might have used or misused the existing information.

Towards the end of that post, I show an example on how you can leverage some DMFs inline, in order to to get information on which stat and respective histogram steps cover my predicate, in the scope of my table and column.

We are happy to announce that identifying which statistics were in fact used by the Query Optimizer for a given compilation has become much easier: they are now part of Showplan.

When looking at the properties of the root node, here’s what we know: one statistic object [IX_CustomerStatus] was used by the Query Optimizer, and I can see several statistic properties like SamplingPercent, current ModificationCount and when it was last updated.

 

image

 

OptimizerStatsUsage is available in cached plans, so getting the “estimated execution plan” and the “actual execution plan” will have this information.

In the above example, I see the ModificationCount is very high (almost as much as the table cardinality itself) which after closer observation, the statistic had been updated with NORECOMPUTE.

And looking and the Seek itself, there is a large skew between estimated and actual rows. In this case, I now know a good course of action is to update statistics. Doing so produces this new result: ModificationCounter is back to zero and estimations are now correct.

image 

Pedro Lopes (@sqlpto) – Program Manager


Smart Transaction log backup, monitoring and diagnostics with SQL Server 2017

$
0
0

In my previous blog post, I briefly talked about smart transaction log backup, monitoring and diagnostics along with other community driven improvements we released in SQL Server 2017 CTP 2.0. In this blog post we will go deep into a new DMF sys.dm_db_log_stats which we released in SQL Server 2017 CTP 2.1 that will enable DBAs and SQL Server community to build scripts and solutions that performs smart backups, monitoring and diagnostics of transaction log.

Smart Transaction Log Backups

Most DBAs today operating their SQL Server database in full recovery model schedule their transaction log backups to recur on a specific time interval  for instance, every 15 mins for a highly transactional database to avoid autogrowth of the transaction log files. This works very well assuming transactional activity is consistent or predictable throughout the backup interval, producing transaction log backup files of equal size with no autogrows. In most real-world production environment today, this is not true and pattern of transactional activity seen is similar to the one shown below. In the example shown below, the transactions between 9am – 9:15am are below average which produces a small transaction log backup file at 9:15 am but more importantly doesn’t lead to any autogrow. The transaction log activity between 9:15am – 9:30 am is higher than average and may cause all VLFs in transaction log file to be full which cannot be truncated due to pending backup. Thus, it leads to autogrow. Autogrow setting is like auto insurance where you would keep it ON but hope you never use it since it would hurt you over a long run. In this scenario, if you do not have any monitoring in place, you might end up with 1000s of VLFs due to frequent autogrows resulting to space issues, slow recovery, rollback issues, replication latency and cluster failovers with SQL Server resource taking long time to come online.

In sys.dm_db_log_stats, you will find a new column log_since_last_log_backup_mb which can be used in your backup script to trigger a transaction log backup when log generated since last backup exceeds a threshold value. With smart transaction log backup, the transaction log backup size would be consistent and predictable avoiding autogrows from transactional burst activity on the database. The resulting pattern from the transaction log backup would be similar to below.



Smart Transaction Log Monitoring and alerting

Monitoring VLFs

In sys.dm_db_log_stats, we have exposed couple of columns for VLF monitoring viz total_vlf_count and active_vlfs allowing you to monitor and alert if the total number of VLFs of the transaction log file exceeds a threshold value. Usually when you exceed 100s of VLF or if active_vlfs is approaching closer to total_vlfs, a DBA should be alerted to understand the cause of the transaction log truncation holdup and growth. A DBA can check log_truncation_holdup_reason column to understand the cause of the log truncation holdup and respond to the alert accordingly depending on the reason found. While monitoring your transaction log, total_vlf_count and active_vlfs values can be captured periodically in a scheduled job to report the usage pattern and monitor the overall health of the transaction log.

A healthy VLF usage pattern will look like below. Each time a transaction log backup is completed for full recovery database or checkpoint is completed for simple recovery database, log truncation would occur causing the active_vlfs to drop while total_vlfs remain constant.

If a log truncation doesn’t happen and active_vlfs approaches total_vlfs, it would lead to autogrow causing total_vlfs to increase. Now when the log truncation is unblocked and resumes, the active_vlfs falls back but the total_vlfs holds on to the new value until you shrink your transaction log files. Shrinking your transaction log file often can lead to disk fragmentation and reduce your disk throughput and performance.

Finally, following pattern can be most dangerous and leading indicators of poor health and maintenance of transaction log. It is important to understand the cause of log truncation holdup reason in this case and size the transaction log appropriately to avoid this scenario.

Monitoring log backup time

While monitoring transaction logs, one of the most important alerts is when transaction log backup is not completed for more than x hours. Transaction log backup failures can expose you to data loss and lead to log truncation holdup resulting into frequent autogrows. The log_backup_time column in sys.dm_db_log_stats can be used to determine the last transaction log backup and can be used to alert a DBA and trigger a backup in response to the alert. The last log backup time can also be derived from msdb database but one of the advantage of using log_backup_time column in sys.dm_db_log_stats is, it also accounts for the transaction log backup completed on secondary replica if the database is configured in Availability groups. If you are using msdb.dbo.backupset to trigger an alert for delayed or failed transaction log backups, it can lead to false triggers when database state changes in Availability groups as the msdb database is not synchronized.

Smart Transaction Log diagnostics

In sys.dm_db_log_stats, backup_lsn, checkpoint_lsn, recovery_lsn columns are exposed which can be used for troubleshooting and diagnostics. These lsns values can help you visualize a rough sketch of transaction log. Every once in a while, a DBA faces a situation where a user has a long running transaction in killed\rollback state causing blocking issue. In such scenario, a DBA is often in a dilemma to wait or restart the SQL Server instance hoping the universal solution would do the trick. In such scenario, a DBA can look at recovery_vlf_count and log_recovery_size_mb to understand the number of vlfs to recover and log size to recover if the database is restarted. High number of recovery_vlfs and log recovery size can lead to entire database in recovery state for long time if the database is restarted. High values of recovery vlfs and log recovery size can also be used as leading indicators for long failover time in FCI scenarios.

I am sure there are more scenarios where customers and community will find sys.dm_db_log_stats useful to proactively maintain a healthy state of the transaction log and improve the overall availability and predictability of the SQL Server instance.

 

Parikshit Savjani
Senior PM, SQL Server Tiger Team
Twitter | LinkedIn
Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam

 

SQL Server Migration Assistant (SSMA) v7.4 is now available

$
0
0

Overview

SQL Server Migration Assistant (SSMA) for Oracle, MySQL, SAP ASE (formerly SAP Sybase ASE), DB2, and Access allows users to convert a database schema to a Microsoft SQL Server schema, upload the schema, and then migrate data to the target SQL Server (see below for supported versions).

What is new?

  • SSMA for Oracle now supports Azure SQL Data Warehouse as a supported target platform for migration.
  • Supports the Data Warehouse storage options as outlined.

 

  • Supports the data distribution options as outlined.

 

  • The Query timeout option is now available during schema object discovery at source and target.

 

  • We have improved the quality and conversion metric with targeted fixes based on customer feedback.

NOTE:
Starting from v7.4, the 32-bit version of SSMA is being discontinued.
.Net 4.5.2 is a pre-requisite for installing SSMA v7.4

Downloads

Supported sources and target versions

Source: For supported sources, please review the information on the Download Center for each of the above SSMA v7.4 downloads.
Target: SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014, SQL Server 2016, SQL DB (Azure), SQL Server 2107 (Public Preview), Azure SQL Data Warehouse.

Resources

Columnstore Index: How do I find tables that can benefit from Clustered Columnstore Index

$
0
0

Most of us understand that clustered columnstore index can typically provide 10x data compression and can speed up query performance up to 100x. While this sounds all so good, the question is how do I know which tables in my database could potentially benefit from CCI? For a traditional DW scenario with star schema, the FACT table is an obvious choice to consider. However, many workloads including DW have grown organically and it is not trivial to identify tables that could benefit from CCI. So the question is how can I quickly identify a subset of tables suitable for CCI in my workload?

Interestingly, the answer lies in leveraging the DMVs that collect data access patterns in each of the tables. The following DMV query provides a first order approximation to identify list of tables suitable for CCI. It queries the HEAP or the rowstore Clustered index using DMV sys.dm_db_index_operational_stats to identify the access pattern on the base rowstore table to identify tables that meet the criteria listed in the comments below:

-------------------------------------------------------
-- The queries below need to be executed per database. 
-- Also, please make sure that your workload has run for
-- couple of days or its full cycle including ETL etc
-- to capture the relevant operational stats
-------------------------------------------------------
-- picking the tables that qualify CCI
-- Key logic is
-- (a) Table does not have CCI
-- (b) At least one partition has > 1 million rows and does not have unsupported types for CCI
-- (c) Range queries account for > 50% of all operations
-- (d) DML Update/Delete operations < 10% of all operations
select table_id, table_name
from (select quotename(object_schema_name(dmv_ops_stats.object_id)) + N'.' + quotename(object_name (dmv_ops_stats.object_id)) as table_name,
     dmv_ops_stats.object_id as table_id,
     SUM (leaf_delete_count + leaf_ghost_count + leaf_update_count) as total_DelUpd_count,
     SUM (leaf_delete_count + leaf_update_count + leaf_insert_count + leaf_ghost_count) as total_DML_count,
     SUM (range_scan_count + singleton_lookup_count) as total_query_count,
     SUM (range_scan_count) as range_scan_count
  from sys.dm_db_index_operational_stats (db_id(),
    null,
    null, null) as dmv_ops_stats
  where  (index_id = 0 or index_id = 1)
     AND dmv_ops_stats.object_id in (select distinct object_id
                                     from sys.partitions p
                                     where data_compression <= 2 and (index_id = 0 or index_id = 1)
                                     AND rows >= 1048576
                                     AND object_id in (select distinct object_id
                                                       from sys.partitions p, sysobjects o
                                                       where o.type = 'u' and p.object_id = o.id))
     AND dmv_ops_stats.object_id not in ( select distinct object_id
             				from sys.columns
             				where user_type_id IN (34, 35, 241)
             				OR ((user_type_id = 165 OR user_type_id = 167)  and max_length = -1))
  group by dmv_ops_stats.object_id
 ) summary_table
where ((total_DelUpd_count+0 * 100.0/NULLIF(total_DML_count+1, 0) < 10.0))
 AND ((range_scan_count*100.0/NULLIF(total_query_count, 0) > 50.0))

 

Example: Restore database AdventureWorksDW2016CTP3 and following the following steps

  • Step-1: Run the query. You will see no tables identified because there is no data access pattern available in the DMV sys.dm_db_index_operational_stats
  • Step-2: Run few analytics queries such as
Select c.CalendarYear,b.SalesTerritoryRegion, FirstName + ' ' + LastName as FullName,
count(SalesOrderNumber) as NumSales,sum(SalesAmount) as TotalSalesAmt , Avg(SalesAmount) as AvgSalesAmt
,count(distinct SalesOrderNumber) as NumOrders, count(distinct ResellerKey) as NumResellers
From FactResellerSalesXL a
inner join DimSalesTerritory b on b.SalesTerritoryKey = a.SalesTerritoryKey
inner join DimEmployee d on d.Employeekey = a.EmployeeKey
inner join DimDate c on c.DateKey = a.OrderDateKey
Where c.FullDateAlternateKey between '1/1/2006' and '1/1/2010'
Group by b.SalesTerritoryRegion,d.EmployeeKey, d.FirstName,d.LastName,c.CalendarYear

 

  • Step-3: Run the query again and you will see the following output identifying the FACT table that can potentially benefit from CCI

image

Now, to find about data compression savings, unfortunately it is not yet supported in the popular stored procedure sp_estimate_data_compression_savings but you can use the following work around for approximate calculation.

  1. Select top 2 million rows from the source table and load into a temp table.
  2. Measure the size using sp_spaceused. Let us say it is X
  3. Now enable CCI on temp table using https://docs.microsoft.com/en-us/sql/t-sql/statements/create-columnstore-index-transact-sql
  4. Measure the size using sp_spaceused. Let us say it is Y
  5. Divide Y/X to get compression ratio. The actual compression will vary depending upon data skew.

Hope this helps you discover tables that could qualify for columnstore index. As always, please feel free to reach out to me for any questions on columnstore index

Thanks,

Sunil Agarwal

SQL Server Tiger Team

Twitter | LinkedIn

Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam

SQL Server Diagnostics (Preview)

$
0
0

Today, Microsoft is releasing the SQL Server Diagnostics (Preview) extension within SQL Server Management Studio and Developer APIs to empower SQL Server customers to achieve more through a variety of offerings to self-resolve SQL Server issues.

 

 

What this offers to our customers?

Analyze Dumps – Customers using this extension will be able to debug and self-resolve memory dump issues from their SQL Server instances and receive recommended Knowledge Base (KB) article(s) from Microsoft, which may be applicable for the fix. The memory dumps are stored in a secured and compliant manner as governed by the Microsoft Privacy Policy.

 

For example, Joe, a DBA from Contoso, Ltd., finds that SQL Server has generated a memory dump while running a workload, and he would like to debug the issue. Using this feature, John can upload the dump and receive recommended KB articles from Microsoft, which can help him fix the issue.

 

FAQ:

Q. What version of SQL Server is supported?

Answer: SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014, SQL Server 2016.

Q. What version of SQL Server Management Studio (SSMS) is supported?

Answer: Microsoft SQL Server Management Studio (SSMS) 2016 or a later version ( SQL Server Management Studio 17.1 ).

If you don’t have SSMS installed, please install it from: SQL Server Management Studio

Q. Which process dumps can be uploaded for analysis?

Answer: The dumps we are analyzing are for SQL Server process (sqlservr.exe).

Q. What type of dumps are supported?

Answer: We support mini dumps, filtered dumps and full dumps. The dumps can be of the following types – .dmp, .hdmp, .mdmp.

Q. What are the scenarios in which the dump may have been generated?

Answer: The dumps could have been generated for exceptions, hangs, non-yielding scheduler and manual.

Q. What SQL Server platforms are supported?

Answer: We support SQL Server on-premise and SQL Server running on VM’s.

Q. What is maximum size of the dumps?

Answer: The maximum size of the dumps can be up to 100 GB. If the file size is more than 8 GB we recommend to use LZ4 compression to compress the file before the upload.

Q. How is the recommendation determined?

Answer: The memory dump is analyzed for the root cause like exceptions, assertion or non-yielding schedulers and it is matched with any publicly available fixes for the issue in the form of KB articles.

 

View Recommendations –

Customers will be able to keep their SQL Server instances up-to-date by easily reviewing the recommendations for their SQL Server instances. Customers can filter by product version or by feature area (e.g. Always On, Backup/Restore, Column Store, etc.) and view the latest Cumulative Updates (CU) and the underlying hotfixes addressed in the CU.

 

 

To continue with the previous example, Contoso, Ltd. uses SQL Server 2016, and Joe wants to understand the fixes pertaining to every feature area before he applies the latest CU. Using this feature, he can view all the fixes that are part of the CU across the different SQL Server feature areas. In the future, Joe also wants to receive proactive recommendations, including bug fixes, assessment and migration to latest SQL versions, from Microsoft.

FAQ:

Q. What are the recommendations when I click on View Recommendations ?

Answer: We provide the information on the Latest Cumulative Updates for all supported SQL Server versions –  SQL Server 2008 R2, SQL Server 2012, SQL Server 2014, SQL Server 2016.

Developer APIs –

Developers who want to discover and learn about our APIs can view our developer portal and then use our APIs in their custom applications. Developers can log and discuss issues and even submit their applications to the application gallery.

 

For example, Contoso, Ltd. has a monitoring system in place that detects issues whenever SQL Server generates memory dumps. Using our developer APIs, Joe can now extend the monitoring system to call our APIs to pick up the memory dump, create and send custom alerts, including recommended Knowledge Base (KB) article(s) applicable to the fix, to his extended team.

 

Note:

This extension requires Microsoft SQL Server Management Studio (SSMS) 2016 or a later version. If you do not have the latest Microsoft SQL Server Management Studio (SSMS) installed, please install it from here.

If you would like to assess database migration to SQL Server from Microsoft Access, DB2, MySQL, Oracle and Sybase please reference this article.

To migrate existing on-premises SQL Server, Oracle, and MySQL databases to Azure, whether your target database is Azure SQL Database, Azure SQL Database Managed Instance, or Microsoft SQL Server in an Azure virtual machine, learn more about the Azure Database Migration Service. For an opportunity to participate in a limited preview of this service, please submit a nomination.

Indirect Checkpoint and tempdb – the good, the bad and the non-yielding scheduler

$
0
0

Indirect checkpoint was first introduced in SQL Server 2012 to provide predictable database recovery governed by target_recovery_time option set at the database level. In SQL Server 2016, indirect checkpoint is ON by default with target_recovery_time set to 60 seconds for model database. The conventional or automatic checkpoint algorithm assumes fixed time interval to recover each log record without accounting for the number of pages dirtied by a database transaction. In simpler terms, when (number of log records * fixed time interval to recover a log record) exceeds recovery interval set at the instance level, automatic checkpoint is triggered on the database. As automatic checkpoint doesn’t account for the dirty pages from each transaction (an important influencer of recovery time), it makes the recovery time less predictable. With indirect checkpoint, the engine maintains partitioned dirty page lists per database to track the number of dirty pages in the buffer pool for that database from each transaction. When the background recovery writer polling the dirty page manager detects the condition, where the number of dirty pages exceeds the dirty page threshold (calculated by heuristics), the recovery writer would trigger the flush of dirty pages to ensure database recovery would complete within the target_recovery_time set. In addition to predictable recovery time, the advantage of indirect checkpoint is, it smoothens the large IO burst activity observed with automatic checkpoints especially on high end machines with large memory to improve the overall IO latency and throughput of SQL Server instance. For example, backup of a database on large memory system can take long times with automatic checkpoint when a checkpoint (flushcache) is issued during backup which takes longer with longer IOs if indirect checkpoint is not enabled on the database.

Now that we understand the benefits of indirect checkpoint, let’s take a closer look at how recovery writer works internally to efficiently handle heavy transactional activity on the database. Recovery writer is a background thread like lazywriter thread which wakes up periodically based on a timed event to poll dirty page list. In addition to the timed wait, the recovery writer wake up is triggered if dirty pages exceeds the dirty page threhold. DIRTY_PAGE_POLL is a new system waittype introduced to support timed wait of recovery writer thread and if you see it as one of the high wait events in sys.dm_os_wait_stats, you can safely ignore it. When target_recovery_time is set at the database level, indirect checkpoint is activated and dirty page manager is created for the database. The dirty page manager maintains the dirty page lists for the database. For each database, we have dirty page list partitioned into 128 DPLists per database. Partitioned DPLists help improves concurrency and avoids any contention with each worker thread running on a scheduler writing to its corresponding dirty page list (Scheduler [0] -> DPList[0], Scheduler [1] -> DPList [1]). Due to this, when the transactional activity on the database is low (<3k-5k transactions per second), the overhead of tracking dirty pages in DPList is minimal and doesn’t impact the overall throughput of the workload running on the database with indirect checkpoint.

When the total number of dirty pages exceeds the dirty page threshold (calculated internally from target_recovery_time), the recovery writer wakes up, swaps the list and starts iterating through the DPList in the loop starting with the longest DPList, collecting the Page IDs and sorting the pages in the list to optimize and bundle writes together and finally posts asynchronous write request to write the pages as shown in the figure below. The IO completion (IOC) routine picks up the sorted dirty pages up to 128 contiguous pages in one IO write operation for completion.


The recovery writer acquires spinlock on DPList during the PageID collection while IOC threads also require spinlock on the same DPList to remove pages from the list when writes are completed. This results into healthy spinlock contention between recovery writer and IoC routine threads. While we can have multiple IoC threads (typically one per scheduler) to perform post-write processing, there is only one recovery writer per SQL Server instance. On highly transactional systems, the recovery writer may start falling behind due to high number of pages dirtied in short time or IO not catching up. If recovery writer starts falling behind resulting into long DPLists, the individual worker threads running on the scheduler starts playing the role of recovery writer to collect, sort and post write for dirty pages. This allows recovery writer to scale dynamically on heavy OLTP systems to ensure target_recovery_time interval set is met all the time. While multiple recovery writer routine running aggressively allows us to meet the target_recovery_time for predictable recovery, the overall throughput of workload may degrade under these circumstances due to additional overhead caused from each running worker performing recovery writer activity.

As mentioned earlier, each running worker thread populates the pages dirtied from the running batch into the respective DPList. As a result, if you have few long running batches, dirtying multiple buffers in a single worker thread execution, the distribution of dirty pages in the DPList gets skewed with few very long DPLists as shown in the figure above. For example, we have seen the single DPList growing with more than 20K-30K pages in the list with remaining lists relatively free. Under these circumstances, the recovery writers need to work aggressively on those longer lists while multiple IoC threads simultaneously writing and removing pages from the same list. In this scenario, the spinlock contention between recovery writer threads and IOC threads begins to become a bottleneck chewing additional CPU cycles and degrading the overall throughput of the workload.

One of the scenarios where skewed distribution of dirty pages in the DPList is common is tempdb. Starting SQL Server 2016, indirect checkpoint is turned ON by default with target_recovery_time set to 60 for model database. Since tempdb database is derived from model during startup, it inherits this property from model database and has indirect checkpoint enabled by default. As a result of the skewed DPList distribution in tempdb, depending on the workload, you may experience excessive spinlock contention and exponential backoffs on DPList on tempdb. In scenarios when the DPList has grown very long, the recovery writer may produce a non-yielding scheduler dump as it iterates through the long list (20k-30k) and tries to acquire spinlock and waits with exponential backoff if spinlock is taken by multiple IOC routines for removal of pages.

If you see non-yielding schedulers in your environment due to this, you will see the following symptoms

Errorlog

Messages Reported in Errorlog

Process 0:0:0 (0x34c0) Worker 0x000000FCD89BC160 appears to be non-yielding on Scheduler 9. Thread creation time: 13140343858116. Approx Thread CPU Used: kernel 0 ms, user 60968 ms. Process Utilization 13%. System Idle 86%. Interval: 70234 ms.
Process 0:0:0 (0x34c0) Worker 0x000000FCD89BC160 appears to be non-yielding on Scheduler 9. Thread creation time: 13140343858116. Approx Thread CPU Used: kernel 0 ms, user 120718 ms. Process Utilization 12%. System Idle 86%. Interval: 135452 ms.

Process 0:0:0 (0x34c0) Worker 0x000000FCD89BC160 appears to be non-yielding on Scheduler 9. Thread creation time: 13140343858116. Approx Thread CPU Used: kernel 0 ms, user 172343 ms. Process Utilization 12%. System Idle 87%. Interval: 195671 ms.
Process 0:0:0 (0x34c0) Worker 0x000000FCD89BC160 appears to be non-yielding on Scheduler 9. Thread creation time: 13140343858116. Approx Thread CPU Used: kernel 0 ms, user 228828 ms. Process Utilization 12%. System Idle 87%. Interval: 255890 ms.
A time-out occurred while waiting for buffer latch — type 3, bp 0000010C1900C6C0, page 4:323520, stat 0x10f, database id: 2, allocation unit Id: 6488064, task 0x000000FE6076D088 : 0, waittime 300 seconds, flags 0x19, owning task 0x00000102ED0C8108. Not continuing to wait.
A time-out occurred while waiting for buffer latch — type 3, bp 0000010C1900C6C0, page 4:323520, stat 0x10f, database id: 2, allocation unit Id: 6488064, task 0x000001033B2D7C28 : 0, waittime 300 seconds, flags 0x39, owning task 0x00000102ED0C8108. Not continuing to wait.

Non-Yielding Scheduler Dump

When you load the associated non-yielding scheduler dump in Windbg, load the symbols and see the stack of the thread non-yielding, you will see the following stack

00 sqlmin!Spinlock<100,11,1>::SpinToAcquireWithExponentialBackoff
01 sqlmin!DirtyPageMgr::WrotePage
02 sqlmin!RecoveryUnit::WrotePage
03 sqlmin!BPool::WritePageCompletion

04 sqlmin!FCB::IoCompletion
05 sqldk!IOQueue::CheckForIOCompletion
06 sqldk!SOS_Scheduler::SwitchContext
07 sqldk!SOS_Scheduler::SuspendNonPreemptive08 sqlmin!EventInternal<SuspendQueueSLock>::Wait
09 sqlmin!LatchBase::Suspend
0a sqlmin!BUF::AcquireLatch
0b sqlmin!BPool::Get

To detect if your SQL Server instance is experiencing excessive spinlock contention on DPList even if there is no non-yielding scheduler detected, you can use the following diagnostics available in SQL Server

DMV

Use sys.dm_os_spinlock stats DMV to look for a high number of spins and backoff events over periods of time. Run the following query multiple time in the interval of 1 min. Calculate the difference between the snapshot to identify the number of spins and backoffs between the consecutive snapshots.

Note: It is expected to see some spins and backoffs due to healthy spinlock contention between the recovery writers and IoC threads so you will have to compare the different snapshot to see if exponential backoff continues to increase.

select getdate() as‘Date Captured’,* from sys.dm_os_spinlock_stats where name =‘DP_LIST’

XEvents

You can use the following script to capture Xevent for spinlock backoff for DPList in your environment. The Callstack captured from the Xevents can be analyzed using SQLCallStackResolver developed by Arvind Shyamsundar.

select map_value, map_key, name from sys.dm_xe_map_values
where map_value LIKE (‘DirtyPageList’)

create event session spin_lock_backoff on server
add event sqlos.spinlock_backoff
(action (package0.callstack)
where type = 100 ) –Map value for DirtyPageList from previous query
add target package0.asynchronous_bucketizer
(set filtering_event_name=‘sqlos.spinlock_backoff’,
source_type=1,
source=‘package0.callstack’)
with (MAX_MEMORY=50MB, MEMORY_PARTITION_MODE = PER_NODE)

alter event session spin_lock_backoff on server state=start

select * from sys.dm_xe_sessions where name = ‘spin_lock_backoff’

waitfor delay ’00:01:00′

select event_session_address, target_name, execution_count, cast (target_data as XML)
from sys.dm_xe_session_targets xst
inner join sys.dm_xe_sessions xs on (xst.event_session_address = xs.address)
where xs.name = ‘spin_lock_backoff’

alter event session spin_lock_backoff on server state=stop
drop event session spin_lock_backoff on server

Recommendations

  • If you have experienced non-yielding scheduler in your environment and non-yielding callstack resembles similar to the list above, we recommend disabling the indirect checkpoint on tempdb using startup stored procedure as shown below. (Below script requires you to run it with sysadmin priviledges). Alternatively, you can disable indirect checkpoint on tempdb by setting target_recovery_time to 0 for model database but we do not recommend it since it disables indirect checkpoint on any new user database created on the instance and depending on the memory on your server, it can degrade the performance for create database, backup database as checkpoint may take long to flush cache and lead to IO burst.

    USE MASTER
    GO

    sp_configure ‘show advanced options’,1
    reconfigure

    sp_configure ‘scan for startup procs’,1
    reconfigure

    CREATE PROCEDURE usp_disable_indirectchkpt_tempdb
    AS BEGIN

    — whenever instance starts up (using startup stored procedure)
    ALTER DATABASE [tempdb] SET TARGET_RECOVERY_TIME = 0 MINUTES
    END

    EXEC SP_PROCOPTION usp_disable_indirectchkpt_tempdb,‘STARTUP’,‘ON’
    GO

    select name,target_recovery_time_in_seconds from sys.databases
    where database_id=2

    — Restart SQL Server
    — Verify if target_recovery_time is set to 0 for tempdb

    select name,target_recovery_time_in_seconds from sys.databases
    where database_id=2

  • If you are running SQL Server 2016, we highly recommend monitoring and capture the output of sys.dm_os_spinlock stats DMV for DP_LIST spinlock periodically to establish a baseline and detect spinlock contention on DP_List.
  • For tempdb, there is no recovery goals as it is recreated on restart so indirect checkpoints on tempdb may not make much sense from recovery perspective but indirect checkpoint is still important to smoothen the IO burst activity from automatic checkpoint and to ensure the dirty pages in tempdb do not continue to take away buffer pool pages from user database workload. In this scenario, we recommend tuning the target_recovery_interval to higher value (2-5 mins) for recovery writer to be less aggressive and strike a balance between large IO burst and DPList spinlock contention.
  • If you are evaluating or planning to upgrade to SQL Server 2016, it is important to compare performance of your workload with indirect checkpoint (multiple target_recovery_time) and without indirect checkpoint and choose the most optimal setting for your environment.

 

Parikshit Savjani
Senior PM, SQL Server Tiger Team
Twitter | LinkedIn
Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam

Loan Chargeoff Prediction Solution Templates are Live in Cortana Intelligence Solutions Gallery

$
0
0

A charged off loan is a loan that is declared by a creditor (usually a lending institution) that an amount of debt is unlikely to be collected, usually when the loan repayment is severely delinquent by the debtor. Chargeoff loan has huge financial implication on lending institutions’ financial statement.  No banks or credit unions like to have high percentage of chargeoff loans in their books. Having data ahead of time of which loans are most likely to be charged off will buy tremendous lead time for the banks to save the loans from charging off. Loan manager could formulate personalized plan with the borrower on how to continue with loan repayment rather than incurring the loan as a chargeoff.

For more information, read this blog: End to End Loan ChargeOff Prediction Built Using Azure HDInsight Spark Clusters and SQL Server 2016 R Service

We have published two solution templates deployable using two technology stacks for the above chargeoff scenario:-

  1. Loan Chargeoff Prediction using SQL Server 2016 R Services – Using DSVM with SQL Server 2016 and Microsoft ML, this solution template walks through how to create and clean up a set of simulated data, use 5 different models to train, select the best performant model, perform scoring using the model and save the prediction results back to SQL Server. A PowerBI report connects to the prediction table and show interactive reports with the user on the chargeoff prediction.
  2. Loan Chargeoff Prediction using HDInsight Spark Clusters – This solution demonstrates how to develop machine learning models for predicting loan chargeoff (including data processing, feature engineering, training and evaluating models), deploy the models as a web service (on the edge node) and consume the web service remotely with Microsoft R Server on Azure HDInsight Spark clusters. The final predictions is saved to a Hive table which could be visualized in Power BI.

With just a few clicks to deploy the solution to their Azure subscriptions, external customers can explore the raw data, understand the data transformation, R model engineering and operationalization of the models. PowerBI report also allows the customers to explore the chargeoff historical and prediction data. Internal Microsoft sales and field team could also quick deploy the solution and demo to the customers on the end to end data pipeline and R model development.

We have also published the same solutions to GitHub, please play around with the solution templates and provide your feedback, here are some of the link on the blog and GitHub repo:-

Blog:- https://blogs.msdn.microsoft.com/rserver/2017/06/29/end-to-end-loan-chargeoff-prediction-built-using-azure-hdinsight-spark-clusters-and-sql-server-2016-r-service/

GitHub:- https://microsoft.github.io/r-server-loan-chargeoff/index.html

Solution Template in Cortana Intelligence Gallery:- https://gallery.cortanaintelligence.com/Solution/Loan-ChargeOff-Prediction-with-SQL-Server

https://gallery.cortanaintelligence.com/Solution/Loan-ChargeOff-Prediction-with-Azure-HDInsight-Spark-Clusters

 

Ajay Jagannathan (@ajaymsft)

Principal Program Manager

SQL Server 2016, Minimal logging and Impact of the Batchsize in bulk load operations

$
0
0

One of the design goals of SQL Server 2016 was to improve performance and scalability of the engine out of the box to make it run faster without the need of any knobs or trace flags for customers. As a part of these improvements, one of the enhancements made in the SQL Server engine code was turning on bulk load context (also referred as fast inserts or fast load context) and minimal logging by default when performing bulk load operations on database with simple or bulk logged recovery model. If you are not familiar with minimal logging, I would highly recommend reading this blog post from Sunil Agrawal where he explains how minimal logging works in SQL Server. For bulk inserts to be minimally logged, it still needs to meet the pre-requisite conditions which are documented here.

As part of these enhancements in SQL Server 2016, you no longer need to enable trace flag 610 for minimal logging into indexed table and it joins some of the other trace flags (1118, 1117, 1236, 8048) to become of part of the history. In SQL Server 2016, when the bulk load operation causes a new page to be allocated, all of the rows sequentially filling that new page are minimally logged if all the other pre-requisites for minimal logging discussed earlier are met. Rows inserted into existing pages (no new page allocation) to maintain index order are still fully logged, as are rows that are moved as a result of page splits during the load. It is also important to have ALLOW_PAGE_LOCKS turned ON for indexes (which is ON by default) for minimal logging operation to work as page locks are acquired during allocation and thereby only page or extent allocations are logged.

With the changes in SQL Server 2016, the table that summarizes minimal logging condition in our popular Data Loading Performance Guide changes to below

 

Table Indexes

Rows in table

Hints

With or Without TF 610

Concurrent possible

Heap Any TABLOCK Minimal Yes
Heap Any None Full Yes
Heap + Index Any TABLOCK Depends (3) No
Cluster Empty TABLOCK, ORDER (1) Minimal No
Cluster Empty None Minimal Yes (2)
Cluster Any None Minimal Yes (2)
Cluster Any TABLOCK Minimal No
Cluster + Index Any None Depends (3) Yes (2)
Cluster + Index Any TABLOCK Depends (3) No

(1) If you are using the INSERT … SELECT method, the ORDER hint does not have to be specified, but the rows must be in the same order as the clustered index. If using BULK INSERT the order hint must be used.
(2) Concurrent loads only possible under certain conditions. See "Bulk Loading with the Indexes in Place". Also, only rows written to newly allocated pages are minimally logged.
(3) Depending on the plan chosen by the optimizer, the nonclustered index on the table may either be fully- or minimally logged.

Impact of Batchsize in bulk load operations

While minimal logging and bulk load operations helps improve the performance of data load operations in indexes when data is pre-ordered or sequentially loaded, batchsize plays a critical role to achieve faster performance with efficient space utilization of the page and extent allocated by the bulk load operations. With fast load context, each bulk load batch acquires a new extent(s) bypassing the allocation cache to lookup for an existing extent with available free space to optimize insert performance. This means if you utilize smaller batchsize for e.g. 10 rows per batch, a new extent of size 64KB is reserved for each 10 records batch with the remaining pages in the extent unused but reserved for the object resulting into inefficient space utilization.

Thanks to Dan Guzman(b) who provided us with a repro of this scenario in SQL Server 2016 where we bulk load 1000 records with different batchsizes and the results of sp_spaceused is as shown below. You can see from the chart below, bulk load with batchsize of 10 rows leads to highest unused space followed by batchsize of 100 and least unused space when we use batchsize of 1000 which loads all records in single batch.

 

BatchSize

Data (KB)

index_size(KB)

Unused (KB)

Reserved (KB)

10

808

8

5656

6472

100

168

8

1176

1352

1000

128

8

128

264

 

It is also important to remember in minimal logging mode, data pages are flushed as soon as the batch is committed as we do not log all records and only allocations are logged. Hence if we choose a large batch size it can lead to write IO bursts and if the IO subsystem is not capable of handling the write IO burst, it can adversely affect the performance of bulk load operation and all other transactions running on SQL Server instance at that time.

It is therefore important to choose a batchsize which is multiple of the size of an extent (64KB) based on the average row size so that the rows efficiently fills the space within the extent and further the write IO size is limited to 64KB which is handled easily by most IO subsystem. Depending on the underlying disk IO performance, you can choose a batchsize anywhere between the size of 1 extent (64KB) to 64 extents (4MB), to strike a balance between efficient space utilization and optimal bulk load performance.

If for any reason, you cannot change the batchsize or if you are not seeing an improved data load performance with default minimal logging behavior, you can disable fast inserts behavior in SQL Server 2016 using trace flag 692 which we have documented here. We do not anticipate under normal circumstances this trace flag will be required for customers.

On a side note, we have many customers hitting AV with merge statement against database in simple recovery model as reported in connect item here. While we are working on the fix for the issue which will be released in upcoming servicing releases for SQL Server 2016, in the interim until the fix is made available, you can workaround the issue by using trace flag 692 at the session level or server level which disables minimal logging. Alternatively, you can also switch to full recovery model which also disables minimal logging but it can lead to increased transaction log management overhead.

Parikshit Savjani
Senior PM, SQL Server Tiger Team
Twitter | LinkedIn
Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam

 


Correlating xEvents with DMVs

$
0
0

Since the inception of xEvents there has been the need to occasionally correlate data from xEvent collections and DMVs. Specifically, using the query_hash and query_plan_hash actions and correlate with DMVs such as sys.dm_exec_requests and sys.dm_exec_query_stats for example. The blog post on Correlating XE query_hash and query_plan_hash to sys.dm_exec_query_stats in order to retrieve Execution plans for high Resource statements is a good example.

However, sometimes correlating this information is not easy. And that’s because the xEvent actions above are not the same data types as the respective columns in the DMVs, and the community spoke about that by opening Connect items.

Back in SQL Server 2016 and 2014 SP2 we introduced new xEvent actions query_hash_signed and query_plan_hash_signed, that allow you to join the DMVs with xEvents such as query_thread_profile, rpc_completed, sql_statement_completed and sql_batch_completed.

These exist side-by-side with the “non-signed” events so not to break any existing user implementations.

image

Let’s see an example creating the xEvent session below:

CREATE EVENT SESSION [QueriesXE] ON SERVER
ADD EVENT sqlserver.sql_statement_completed(
    ACTION(sqlos.scheduler_id,sqlserver.database_id,sqlserver.is_system,
    sqlserver.plan_handle,sqlserver.query_hash_signed,
    sqlserver.query_plan_hash_signed,sqlserver.server_instance_name,
    sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'C:\Temp\QueryProfileXE.xel',
    max_file_size=(50),max_rollover_files=(2))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
    MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,
    MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO
Then run a query that’s captured in the session:
USE AdventureWorks2016CTP3
GO
ALTER EVENT SESSION [QueriesXE] ON SERVER STATE = START
GO
SELECT *
FROM Sales.SalesOrderDetail sod
INNER JOIN Production.Product p ON sod.ProductID = p.ProductID
ORDER BY Style DESC
OPTION (MAXDOP 1)
GO
ALTER EVENT SESSION [QueriesXE] ON SERVER STATE = STOP
GO

 

When opening the xel file, we can see the following:
image
Use the new signed query plan hash and run below to see this query’s stats:
SELECT * FROM sys.dm_exec_query_stats
WHERE CAST(query_plan_hash AS BIGINT) = -2366658896559316405

 

Or adding the cached plan:

SELECT * FROM sys.dm_exec_query_stats
CROSS APPLY sys.dm_exec_query_plan(plan_handle)
WHERE CAST(query_plan_hash AS BIGINT) = -2366658896559316405

 

image
The above correlation can provide valuable insights during troubleshooting processes, especially when a more prolonged yet lightweight xEvent trace is collected, and upon analyzing it, more information from DMVs/DMFs is needed.

Pedro Lopes (@sqlpto) – Senior Program Manager

New in SSMS: Performance Dashboard built-in

$
0
0

Back in 2007, we released the Microsoft SQL Server 2005 Performance Dashboard Reports, which were designed to provide fast insight into performance issues from some newly created system views – DMFs (Dynamic Management Views). These were updated for SQL Server 2008 and later to SQL Server 2012, and while being very helpful they had a significant drawback – required separate download and install. This meant that when needed, most probably they were not installed in a specific SQL Server, and therefore were unusable when they were needed the most.

With the new SSMS 17.2, we are releasing the Performance Dashboard embedded as a built-in Standard Report. This means that it is available for any SQL Server instance starting with SQL Server 2008, without any extra downloads or running any extra scripts. Just connect to your server in SSMS and open the Performance Dashboard.

How to start it?

As seen below, just bring up the Reports context menu at the server level, and select the Standard Reports.

image

What to use it for?

The Performance Report allows a DBA to quickly identify whether there is any current performance bottleneck on the connected SQL Server. And if a bottleneck is found, easily capture additional diagnostic data that may be necessary to resolve the problem. Some common performance problems where the Performance Dashboard can help to solve include:

  • CPU bottlenecks (and what queries are consuming the most CPU)
  • I/O bottlenecks (and what queries are performing the most IO)
  • Index recommendations generated by the query optimizer (missing indexes)
  • Blocking
  • Resource contention (including latch contention)

See below an example where a CPU bottleneck is present:

image

 

What has changed since the 2012 release?

Besides being completely self-contained in SSMS, we have made a few changes to improve usability:

  • Under Historical Information section:
    • Added wait categorization to Waits report.
    • Filtered out all idle and sleep waits from Waits report.
    • Added new Latches report.
  • Under Miscellaneous Information, added a score column to the report. This report shows potential indexes that the query optimizer identified during query compilation. However, these recommendations should not be taken at face value.
    1. We recommend that only the indexes with a score greater than 100,000 should be evaluated for creation, as those have the highest anticipated improvement for user queries.
    2. Also, always evaluate if a new index suggestion is comparable to an existing index in the same table, where the same practical results can be achieved simply by changing an existing index instead of creating a new index. For example, given a new suggested index on columns C1, C2 and C3, first evaluate if there is an existing index over columns C1 and C2. If so, then it may be preferable to simply add column C3 to the existing index (preserving the order of pre-existing columns) to avoid creating a new index.

What permissions are needed to run the report?

This is aimed at sysadmin roles. Other roles require VIEW SERVER STATE and ALTER TRACE permissions.

 

Check out a demo of this and other SSMS features in the Tiger YouTube channel.

Pedro Lopes (@sqlpto) – Senior Program Manager

New in SSMS: Searching in Showplan

$
0
0

Have you ever analyzed a somewhat big plan? And while doing so did you ever wish you could search for something like table name, index name or column name?

In SSMS 17.2, we are including the ability to search all these and more in graphical showplan.

Let’s look at an example. I executed a query while an xEvent session with query_thread_profile is running (see sample session here). Opening the xel file provides a lot of insight. For example, going through the performance information collected per node, I see node 30 is doing a good part of the IO for this query.

image

Great. So now I want to open the associated cached plan, so I can see which operator this one is, and where in the plan it sits. I will correlate the query_plan_signed xEvent action with DMVs/DMFs (see example here).

SELECT qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
WHERE CAST(qs.query_plan_hash AS BIGINT) = -832496756154281217

How will I search for node_id 30? The showplan xml is available to search on in SSMS:

image

Ok, so it’s a Table Spool, but the plan XML has more Table Spools, and it’s fairly large, so I still need to visually search for this Table Spool manually. Not the best or fastest experience.

image

But what if I could search for node id 30 while looking at the graphical showplan?

Starting with SSMS 17.2, just use CTRL+F to start a search in graphical showplan (or right-click on a blank area of the plan, and in the context menu click on Find Node option), and you can quickly see exactly where node id 30 is:

image

But I could search on all physical operations containing the word Spool, and move thru them using the arrows (highlighted):

image

I can actually search on any property I want to, such as table name, column name, schema name, index name, index type and many other properties, making navigation in graphical showplan even easier:

image

This feature is available anywhere a graphical showplan is open, including Plan Comparison, Plan Scenarios and Query Store. More information on these other SSMS features available in New in SSMS: Query Performance Troubleshooting made easier!

Pedro Lopes (@sqlpto) – Senior Program Manager

Persisting statistics sampling rate

$
0
0

When SQL Server creates or updates statistics and a sampling rate is not manually specified, SQL Server calculates a default sampling rate. Depending on the real distribution of data in the underlying table, the default sampling rate may not accurately represent the data distribution and then cause degradation of query plan efficiency.

To improve this scenario, a database administrator can choose to manually update statistics with a specific sampling rate that can better represent the distribution of data. However, a subsequent automatic update statistics operation will reset back to the default sampling rate, possibly reintroducing degradation of query plan efficiency.

With the most recent SQL Server 2016 SP1 CU4, we released an enhancement for the CREATE and UPDATE STATISTICS command – the ability to persist sampling rates between updates with a PERSIST_SAMPLE_PERCENT keyword.

Let’s use an example. I’m using the following query:

SELECT [SalesOrderID],[ShipDate],[DueDate],[OrderDate]
FROM [Sales].[SalesOrderHeaderBulk]
WHERE OrderDate BETWEEN '8/30/2012 00:00:00.000' AND '9/30/2012 00:00:00.000'
GO

Looking at the actual plan, we see a skew between estimated and actual rows in the scan over the orders table:

image

Let’s check stats on this table then. I’m searching for stats on table orders with column col2 (part of the join argument):

SELECT ss.stats_id, ss.name, filter_definition, last_updated, rows,
    rows_sampled, steps, unfiltered_rows, modification_counter, persisted_sample_percent,
    (rows_sampled * 100)/rows AS sample_percent
FROM sys.stats ss
INNER JOIN sys.stats_columns sc
    ON ss.stats_id = sc.stats_id AND ss.object_id = sc.object_id
INNER JOIN sys.all_columns ac
    ON ac.column_id = sc.column_id AND ac.object_id = sc.object_id
CROSS APPLY sys.dm_db_stats_properties(ss.object_id, ss.stats_id) shr
WHERE ss.[object_id] = OBJECT_ID('[Sales].[SalesOrderHeaderBulk]')
    AND ac.name = 'OrderDate';

We see a statistic for the index used above, with a sampling rate of 6 percent. Let’s say I really need to improve estimations, and that having a higher sampling rate could just do that.

image

So I’ll just update this statistic, and while I could try to find a better (and higher) sampling rate, for this demo I’ll just update with full scan:

UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate] WITH FULLSCAN

image

Let’s see the estimations now:

image

Great, so what happens when auto update statistics is triggered? Or I have some stats maintenance job that does not explicitly sets the sampling rate?

UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate]

image

It’s back at default sampling (in this case 6 percent).

I really want to always update this statistic with 100 percent sampling rate, so I can now use the following PERSIST_SAMPLE_PERCENT keyword:

UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate]
WITH FULLSCAN, PERSIST_SAMPLE_PERCENT = ON

image

Notice the new persisted_sample_percent column is now showing 100 percent (because I used FULLSCAN). Both DBCC SHOW_STATISTICS and sys.dm_db_stats_properties have this new column.

What happens when auto update statistics is triggered or my stats are manually updated again?

UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate]

image
My choice for sampling percentage is now persisted. It will remain persisted until I set this option to OFF. When set to OFF (which is the default), the statistics sampling percentage will get reset to default sampling in subsequent updates that do not explicitly specify a sampling percentage.

Note that if a manual update statistics is executed with a different sampling percentage, but not using PERSIST_SAMPLE_PERCENT keyword to set it as the new persisted value, the previously set fixed sampling will still be in effect for subsequent auto update statistics, or any other manual update that does not set a specific sampling rate.

UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate] WITH SAMPLE 90 PERCENT

image

Pedro Lopes (@sqlpto) – Senior Program Manager

Tiger Team and Data Migration team at Data Platform Summit 2017

$
0
0

Tiger Team (@mssqltiger) represented by (Ajay Jagannathan, Parikshit Savjani, Tejas Shah and Akbar Farishta) and the Data Migration team represented by (Sudhakar Sannakkayala, Amit Banerjee and Nikhil Patel) will be in full force by speaking at 17 sessions at the Data Platform Summit (#DPS2017), Asia’s Premier Data & Analytics Conference taking place on 17-19 August in Bangalore, India. Data Platform Summit 2016 is a full 3-day conference with more than 200 breakout sessions, open talks, chalk talks and deep dive pre-con sessions on Database Administration, Database Development, Business Intelligence, Cloud & Big Data, and related technologies.

 

BannerSSGS_240x400px1   

This is a truly unique conference (see this video), comprised with multiple tracks on Database Management,Database Development, Business Intelligence, Advanced Analytics, Cloud, and Big Data. The summit attracts data platform experts from around the globe. DPS 2017 is the only Data/Analytics event in  Asia where product teams from Microsoft’s Data Group fly down from Redmond to deliver advanced sessions on the latest technologies. 

 

 

     image

 

Through several breakout sessions, chalk talks and open talks (see schedule below) we will talk about new features and enhancements in SQL Server, Azure Database for MySQL and PostgreSQL, and provide deep-dive into internals of these features. Additionally, if you are looking to upgrade, migrate or modernize your data platform (no matter what your source platform is), we will showcase several new tools and services that will make these efforts seamless. You will also have several opportunities to meet and interact with the team at the conference.

 

Day

Start Time

End Time

Room

Speaker

Session Title

Abstract

Day 1 - 17th

10:45

12:00

SHILOH

Nikhil Patel / Sudhakar Sannakkayala

DBA_B60 - Intermediate - Unleash Your Data From Oracle With A Move To SQL Server And Azure Sql Database

Abstract: Customers want to move their data from Oracle and other non-Microsoft databases to SQL Server and Azure SQL Database, but they don't have details about the right methods, best practices, and tools, which creates a barrier to pursuing such migrations. In this session, we will review the migration life cycle in detail and provide prescriptive information about how to migrate your Oracle databases to Azure by using Azure Database Migration Service and related tools. We will cover some common migration scenarios and customer case studies that we have assembled based on learnings from our preview and other field engagements with large enterprises. We will also share our roadmap, which will help you plan your enterprise database migrations.
Key Learning: After completing this session, you will know just how easy it is to migrate from Oracle to SQL Server and Azure SQL Database when you are empowered with right tools and services, and best practices to use during the process.

Day 1 - 17th

11:30

12:00

KILIMANJARO

Amit Banerjee

CLOUD/IoT/NoSQL_C13 - Running Applications On Azure Using Postgres/MySQL

Chalk-Talks are 30 minutes’ sessions focussing on conceptual & architectural understanding, that too with only whiteboard and marker. No Laptops, no PPTs, no demos – only whiteboard-ing!

Day 1 - 17th

12:15

13:30

YUKON

Parikshit Savjani

DBA_B61 - Advanced - Upgrade To SQL Server 2017: Intelligent Diagnostics Just Built-In

Abstract: SQL Server 2016 and SQL Server 2017 Just Works! But if you are a IT Professional you want to be armed with all the right diagnostics to react to a mission critical problem or tune the engine to the needs for your business. Dev-Ops also requires the right tools to build and tune queries for maximum performance. SQL Server 2016 and 2017 have all the diagnostics you need just built-in to the product. These are the foundation for great tools from vendors such as SentryOne, RedGate, SolarWinds, and Idera. We also have intelligence built-into the engine based on these diagnostics to automate, learn, and adapt. In this session we will show you the wide variety of these diagnostics with testimonies from vendors and SQL MVPs. You will learn why SQL Server diagnostics are the best in the industry, built-in, and spans all platforms across SQL Server, Azure, and Linux
Key Learning: 1. Understand the breadth and depth of built-in diagnostic choices that exist for SQL Server, Azure SQL Database, and SQL Server on Linux. 2. Hear customer case testimonies and evidence from ISV tool vendors, SQL MVPs, and Microsoft Premier Field Engineering and Support Engineering on how these diagnostics make them successful. 3. Learn new capabilities in SQL Server 2016 and 2017 that provide intelligence based on built-in diagnostics to automate and adapt reducing total cost of ownership and increasing dev-ops and IT efficiency.
Demos: Demos on Smart diagnostics introduced in SQL Server 20162017

Day 1 - 17th

13:45

15:00

HYDRA

Amit Banerjee

BIA_B02 - Advanced - Building 1 Million Predictions Per Second Using SQL-R

Abstract: Using the power of OLTP and data transformation in SQL 2016 and advanced analytics in Microsoft R Server, various industries that really push the boundary of processing higher number of transaction per second (tps) for different use cases. In this talk, we will walk through the use case of predicting loan charge off (loan default) rate, architecture configuration that enable this use case, and rich visual dashboard that allow customer to do what-if analysis. Attend this session to find out how SQL + R allows you to build an "intelligent datawarehouse".
Key Learning: Deploying solutions using R with SQL Server
Demos: Demo of 1 million transactions/sec

Day 1 - 17th

15:30

16:45

HYDRA

Ajay Jagannathan / Sudhakar Sannakkayala

DBA_B44 - Intermediate - Digitally Transform Your Business Through Migration And Modernization Of Your Data To SQL Platform Of Your Choice

Abstract: Today’s organizations must adapt quickly to change, using new technologies to fuel competitive advantage, or risk getting left behind. Organizations understand that data is a key strategic asset which, when combined with the scale and intelligence of cloud, can provide the opportunity to automate, innovate, and increase the speed of business.
Be it SQL Server, Azure SQL Database or Azure SQL Database Managed instance, learn how to migrate to any of these platforms easily using the Azure Database Migration Service and related tools. We'll cover various aspects of the migration lifecycle from assessment, remediation, data movement to validation and you will learn how easy it is to migrate and modernize your data platform when you are empowered with the right tools.
Key Learning: Learn various aspects of migration lifecycle.
Understand common issues encountered during a migration or modernization project.
Learn and use all the tools to make the migration experience smoother.
Demos: End to End migration

Day 1 - 17th

17:15

17:45

HEKATON

Ajay Jagannathan / Sudhakar Sannakkayala

DBA_O35 - How Do You Successfully Execute A Data Migration Project?

Open-Talks are 30 minutes free-flowing discussion on a specific topic. No laptops, no PPTs, no demos – only discussion and Q & A

Day 2 - 18th

13:15

13:45

HELSINKI

Tejas Shah

DBA_O48 - Non-Yielding Scheduler And Deadlocked Schedulers

Open-Talks are 30 minutes free-flowing discussion on a specific topic. No laptops, no PPTs, no demos – only discussion and Q & A

Day 2 - 18th

10:15

11:30

SPHINX

Ajay Jagannathan

DBA_B43 - Advanced - Life In The Fast Lane With SQL Server In-Memory OLTP

Abstract: Learn how the "Hekaton" engine works behind the scenes to deliver the amazing 30x performance improvements seen for customers moving to In-Memory OLTP. This session will include a look behind the scenes at threads, data and index design, transactions and concurrency, logging, storage, and natively compiled procedures. We will go into detail with scenarios, architectures, and actual customer case studies.
Key Learning: Explain how in-memory OLTP works to deliver upto 30x performance gains.
Articulate the difference between SQL Server transactions and In-Memory OLTP transactions
Understand the value and key scenarios where in-memory OLTP can be leveraged for customer applications.
Demos: How to use in-memory OLTP
Debugging natively compiled stored procs
Inside in-memory checkpoint
Customer case studies

Day 2 - 18th

11:00

11:30

KILIMANJARO

Parikshit Savjani

DBA_C40 - Indirect Checkpointing – The Good, The Bad And The Non-Yielding

Chalk-Talks are 30 minutes’ sessions focussing on conceptual & architectural understanding, that too with only whiteboard and marker. No Laptops, no PPTs, no demos – only whiteboard-ing!

Day 2 - 18th

11:45

13:00

SPHINX

Amit Banerjee

CLOUD/IoT/NoSQL_B40 - Basic - Azure Database for MySQL and PostgreSQL

Abstract: Azure Database for MySQL and Azure Database for PostgreSQL are managed database services built for developers using the community edition of MySQL PostgreSQL. Learn how you can leverage these new choices of managed database services to build scalable, secure and intelligent apps. Using insights from current customer scenarios and through live demos, we walk through the service management capabilities, best practices to move your databases to the service, and also focus on how the Microsoft Azure ecosystem of app and data services is unlocking the potential of MySQL and PostgreSQL in the Azure cloud platform.

Day 2 - 18th

14:00

14:30

KILIMANJARO

Ajay Jagannathan

DBA_C28 - Understanding And Troubleshooting Latches And Spinlocks

Chalk-Talks are 30 minutes’ sessions focussing on conceptual & architectural understanding, that too with only whiteboard and marker. No Laptops, no PPTs, no demos – only whiteboard-ing!

Day 2 - 18th

10:15

10:45

KILIMANJARO

Tejas Shah

DBA_C55 - SQL OS Scheduling

Chalk-Talks are 30 minutes’ sessions focussing on conceptual & architectural understanding, that too with only whiteboard and marker. No Laptops, no PPTs, no demos – only whiteboard-ing!

Day 2 - 18th

16:30

17:00

HELSINKI

Parikshit Savjani

DEV_O54 - Data Loading Best Practices

Open-Talks are 30 minutes free-flowing discussion on a specific topic. No laptops, no PPTs, no demos – only discussion and Q & A

Day 3 - 19th

08:45

10:00

HYDRA

Parikshit Savjani / Tejas Shah

DEV_B71 - Advanced - Gems To Turbocharge Your SQL Server Query Performance

Abstract: As DBAs and developers, you are often tasked to tune and optimize your queries for performance, better resource utilization and improve overall scalability of your workloads running on SQL Server.
In this session you will learn about SQL Server enhancements in the most recent versions that can help you troubleshoot query performance. Ranging from new xEvents to Showplan improvements, from LQS (and underlying infrastructure) to the revised Plan Comparison tool, learn how these can help you streamline the process of troubleshooting query performance and gain faster insights.
The target audience for the session could be any roles that want to learn what’s available to aid in SQL Server query troubleshooting space. That can be the developer that needs to squeeze every ounce of performance from his queries, to the DBA that has to understand the problem space of an ongoing performance issue.
Key Learning: The key takeaways from the session would be tips and tricks to tune your query performance to make it run faster on SQL Server
Demos: Demos of poorly written or performing queries and showcasing how to troubleshoot and tune query performance leveraging the improvements in recent version of SQL Server.

Day 3 - 19th

10:30

11:45

SHILOH

Tejas Shah

DEV_B79 - Intermediate - Improve Data Load Speed And Query Performance With Columnstore Indexes

Abstract: Is data load performance into columnstore slowing you down? Should you drop nonclustered indexes before loading data? What batchsize should you choose? How should you handle large number of Updates/Deletes? Columnstore index can speed up the performance of analytics queries significantly but are you getting the best performance possible? Come to this session to learn the best practices and the techniques customers have used to load data in parallel with minimal or reduced logging into columnstore index. Specifically, we will cover data load using BCP, Bulk Insert, SSIS or MERGE command, concurrent trickle insert in IOT scenario as well as moving data from staging table. We will also talk about how to diagnose performance issues in queries accessing columnstore index and the steps you can take to troubleshoot. Some of the techniques we discuss here are rowgroup elimination, statistics, partitioning, improving the query plan quality, tweaking the schema, and creating one or more nonclustered btree indexes.
Key Learning: Improving performance of analytics workload with columnstore indexes.
Demos: NA

Day 3 - 19th

10:30

11:00

DENALI

Akbar Farishta

DBA_C47 - Change Tracking and Enhancements in SQL Replication

Chalk-Talks are 30 minutes’ sessions focussing on conceptual & architectural understanding, that too with only whiteboard and marker. No Laptops, no PPTs, no demos – only whiteboard-ing!

Day 3 - 19th

12:00

13:15

SHILOH

Akbar Farishta

DBA_B45 - Intermediate - New features of AlwaysOn in SQL 2016 and SQL 2017

Abstract: SQL Server as an enterprise product is continuously evolving and we are making changes to AlwaysOn with the same cadence. In this sessions, we will be discussing about AlwaysOn improvements in SQL 2016 and SQL 2017 (Windows and Linux)
Key Learning: 1. Brief about internals of SQL Server AlwaysOn
2. SQL 2016 –
• Fundamental Changes to Always On Availability Groups
• Performance and Usability enhancements
3. New features in SQL 2017 (Windows and Linux)
Demos: 1) Database Level health Detection
2) Always On Direct Seeding
3) Latency tracker
4) Distributed AG  (if time permits)

Follow  SQLServerGeeks and the #DPS2017 hashtag on Twitter for new and exciting updates about the conference. We hope to meet you at the conference.

 

Ajay Jagannathan (@ajaymsft)

Principal Program Manager

Choosing the right server memory for restore and recovery of memory-optimized databases

$
0
0

Recovering database with memory-optimized tables involves hydrating the contents of checkpoint files (data/delta files) into memory and then replaying the tail of the log (see this link for more details). One of the important difference between disk based tables and memory-optimized store is frequency of checkpoints. Automatic checkpointing for in-memory tables occurs every 1.5GB of log records unlike traditional or indirect checkpoints (where checkpointing is done more often) leading to longer tail of log for in-memory tables. The 1.5 GB log flush is chosen to strike the right balance between flooding the IO subsystem with too many small inefficient IO operations and too few large IOPs. In most scenarios observed by our CSS teams, long recovery times for memory optimized databases is caused by the long tail of log which needs to be recovered for in-memory tables in the database. For these scenarios, running a manual checkpoint before a restart can reduce recovery times as manual checkpoint forces the checkpoint for memory optimized tables in addition to disk based tables.

Another important consideration to keep in mind during recovery of memory optimized tables is the table size in memory is larger than size on disk as only the data rows are persisted and not the indexes. During recovery, all the indexes of the tables are reconstructed which would consume more memory. Hence if you estimate the memory required to restore and recover a memory optimized database with size of the memory optimized filegroup on disk you may see OOM error. Let's say the size of memory optimized filegroup on disk is 300GB (with no traditional SQL data in the database) and if the max server memory is set to 325GB while you may expect the database to recover successfully but instead you might see OOM error.

Here's a memory sizing calculation to keep in mind while planning and sizing the restore and recovery of memory optimized database.

The first thing to note is that in case of to see how much memory is occupied by XTP, use the DMV sys. dm_db_xtp_memory_consumers on an online database:

SELECT ISNULL(SUM(allocated_bytes)/1024/1024, 0) as XTP_MEMORY_IN_MB

FROM
sys.dm_db_xtp_memory_consumers

This shows the memory consumed by tables and for other system operations.

In the above case, memory consumed may be around 340GB – which is already greater than 325GB and hence leading to OOM error.

Secondly, all of the max server memory is not available to be used by memory optimized tables. The percentage of memory depends on MAX SERVER MEMORY. See this link to find out what share your memory optimized tables would get. Here's a snippet from the docs:

In the example above, since the target committed memory is >96GB, the memory available is 90% of 325GB which is 292.5GB.

Lastly, it is recommended to use dedicated resource pools for databases with memory optimized tables. This is because SQL memory manager behaves differently for a default resource pool (which is used by most memory consumers and therefore is more generic in response to memory pressure) compared to a dedicated resource pool which the user has more control over. To bind a resource pool to a database, see this link.

In the example scenario if you bind the database to a resource pool with a MAX_PERCENT of 95%, we would get 95% of 90% of max server memory. To recover a 340GB database successfully, we would need ((340/0.95)/0.9) which is approximately 400GB of max server memory.

For more detailed information on memory requirements and how to deal with memory issues, please refer to the BOL link here.

Prashanth Purnananda
Software Engineer
SQL Server Tiger team

Backup Compression for TDE-enabled Databases: Important fixes in SQL 2016 SP1 CU4 and SQL 2016 RTM CU7

$
0
0

Backup Compression and Transparent Data Encryption (TDE) have been two immensely valuable and popular features for customers in SQL Server. In SQL Server 2016, backup compression was enabled for TDE databases where if you backup a TDE enabled database with compression and MAXTRANSFERSIZE > 64K, backup compression will kick in reducing backup size and improving overall backup performance and time. For more details, you can read blog post from our SQLCAT team on this improvement.

In past months, we discovered some edge scenarios related to backup compression for TDE databases causing backups or restores to fail, hence our recommendations have been

  • Avoid using striped backups with TDE and backup compression.
  • If your database has virtual log files (VLFs) larger than 4GB then do not use backup compression with TDE for your log backups. If you don't know what a VLF is, start here.
  • Avoid using WITH INIT for now when working with TDE and backup compression. Instead, use WITH FORMAT.
  • Avoid using backup checksum with TDE and backup compression

Note: The default native backup uses MAXTRANSFERSIZE = 64K when the database has single database file so compression doesn't kick in automatically for TDE enabled databases and above issues aren't encountered. However, there are certain scenarios listed below where SQL server engine chooses to use MAXTRANSFERSIZE > 64K dynamically to optimize for performance which means compression for TDE databases can kick in automatically even if maxtransfersize is not explicit set.

  • When the database has multiple data files created, it uses MAXTRANSFERSIZE > 64K for which the backup compression kicks in automatically if compression is specified and database has TDE enabled.
  • When performing backup to url, the default MAXTRANSFERSIZE = 1MB for which the backup compression kicks in automatically if compression is specified and database has TDE enabled.

Starting SQL 2016 RTM CU7, SQL 2016 SP1 CU4 and above, we have made improvements and updates to the SQL Server engine which would avoid the edge cases discussed earlier. If you plan to leverage native backup compression for TDE databases or are already using it, we strongly recommend applying the latest CUs on SQL 2016 to ensure you are not hitting any of the known issues we have discovered earlier.

If you are already using backup compression for TDE databases in your environment on SQL 2016 builds below RTMCU7/SP1CU4, we strongly recommend validating your backups by restoring them and apply latest CUs proactively to ensure your RPO/RTO requirements are met. If the restore of the backup from SQL Server build below RTMCU7/SP1CU4 is failing, applying latest CUs won't allow restore of older backups. Only backups created from latest CU build will avoid the above issues and can be restored without any errors.

It is important to know VDI support for backup compression on TDE enabled databases is not added yet and we plan to add it soon in upcoming servicing releases of SQL Server.

Parikshit Savjani
Senior PM, SQL Server Tiger Team
Twitter | LinkedIn
Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam


SQL Server 2012 Service Pack 4 (SP4) is now available!

$
0
0

SQL Server Product Team is excited to bring you the final release of SQL Server 2012 Service Packs, Service Pack 4 (SP4). This release of SQL 2012 Service Pack has 20+ improvements centered around performance, scalability and diagnostics based on feedback from customers and the SQL Server community. These improvements enable SQL Server 2012 to perform faster and scale out of the box on modern hardware design.

In addition to improvements listed below, SQL Server 2012 SP4 includes all the fixes up to and including SQL Server 2012 SP3 CU10.

For more details, please see the release blog post SQL Server 2012 Service Pack 4 (SP4) Released!

 

SQL Server Tiger at PASS Summit 2017

$
0
0

The SQL Server team will again be at the Summit this year. If we are not speaking or co-speaking in a session, you can find us at the SQL Server Clinic at any time.

Sessions

Here are the sessions where the SQL Server Tiger team is speaking or co-speaking:

SQL Server 2017: "Intelligence: Meet Database"

From Zero to Hero: Troubleshooting SQL Server Performance Made Easier

Upgrade to SQL Server 2017: Intelligent Diagnostics Just Built-in

Real-Time Business Insights Using SQL Server 2016 Distributed Availability Groups

Effectively Troubleshooting Latency and Failover of Always On

Customer Successes Migrating On-Premise Workload to Azure SQL Database

SQL Server Clinic

If you have a technical question, a troubleshooting challenge, give product feedback, or want to find out about best practices running your SQL Server?

Then the SQL Clinic is the place you want to go to. SQL Clinic is the hub of technical experts from SQL Product Group (including Tiger team), SQL CAT, SQL Customer Support Services (CSS), SQL Premier Field Engineering (PFE) and others.

Whether you want to ask a question, or bring your laptop and try some live troubleshooting, the experts at SQL Clinic will have the right advice for you!

Pedro Lopes (@sqlpto) – Senior Program Manager

Monitoring SQL Server and Azure SQL DB Session at DBA Fundamentals PASS VC

$
0
0

On 10/17/2017, we delivered a webinar session titled "Comprehensive Guide for Monitoring SQL Server and Azure SQL DB" hosted by DBA Fundamentals PASS Virtual Chapter. You can find the link to the recording below.

In the session, we talked about different tools you can use to monitor your SQL Server, both on Windows and Linux, and Azure SQL DB instances. Alex demo'ed:

  • SCOM
    • SQL Server MP (Windows and Linux)
    • Azure SQL DB MP
  • OMS
    • SQL Assessment (for SQL Server)
    • Azure SQL Analytics (for Azure SQL DB)
  • BPCheck (for SQL Server, Windows and Linux)

 

 

Ebru Ersan

Senior Program Manager, SQL Server Tiger Team

Follow us on Twitter: @mssqltiger | Team Blog: Aka.ms/sqlserverteam

 

New Showplan enhancements

$
0
0

If you follow this blog, you have seen that in the past few releases we have continuously included a number of diagnostic improvements to Showplan. You can read about some of them here.

Looking at the actual execution plan is one of the most used performance troubleshooting techniques. Having information on elapsed CPU time and overall execution time, together with session wait information in an actual execution plan allows a DBA to use showplan to troubleshoot issues away from the server, and be able to correlate and compare different types of waits that result from query or schema changes.

A few months ago we had introduced exposed in SSMS some of the per-operator statistics, such as CPU and elapsed time per thread. More recently, we have introduced overall query CPU and elapsed time tracking for statistics showplan xml (both in ms). These can be found in the root node of an actual plan. Available using the latest versions of SSMS v17, when used with SQL Server 2012 SP4, SQL Server 2016 SP1 and SQL Server 2017. For SQL Server 2014 it will become available in a future Service Pack.

image image

And also included the top 10 waits that the execution was waiting on (includes WaitType, WaitTimeMs and WaitCount), based on sys.dm_exec_session_wait_stats. Most common sleep and idle waits are filtered out from the actual plan, so that it becomes easier to really see the relevance of non-idle waits for query performance.

image

This allows a user to correlate waits with overall times, and be more precise in what to look for to improve query performance. For example, in the picture below, I can correlate the overall elapsed time with the top waits, see that CXPACKET were the most prevalent, that this query is running with DOP 12, and choose to reduce DOP as a way to address this (among other actions possible).

image

Available using the latest versions of SSMS v17, when used with SQL Server 2016 SP1 and SQL Server 2017. Note that CXPACKET wait will be available in showplan with SQL Server 2017 CU3 and 2016 SP2.

One other information you can now find in showplan is trace flags. This is relevant to understand what trace flags are active during compilation, and which one (if any) actually influence compilation. Below we can see trace flags 2371, 7412 and 9481 were active during compilation (IsCompileTime = True), but 2371 and 7412 did not influence the Query Optimizer (IsCompileTime = False). You can see more information on these trace flags and others in http://aka.ms/traceflags.

image

These can be found in the root node of even an estimated plan, given this is a compile time information. Available using the latest versions of SSMS v17, when used with SQL Server 2012 SP4, SQL Server 2016 SP1 and SQL Server 2017. For SQL Server 2014 it will become available in a future Service Pack.

Pedro Lopes (@sqlpto) – Senior Program Manager

Making parallelism waits actionable

$
0
0

During PASS we announced changes to how users will be able to make parallelism waits more actionable – specifically the “infamous” CXPACKET. This change effectively splits CXPACKET waits into an actionable wait (CXPACKET) and a negligible wait (CXCONSUMER). This change will be effective starting with upcoming SQL Server 2017 CU3 and SQL Server 2016 SP2 (this wait type is already present in Azure SQL Database).

So why split?

It’s important to mention a couple notes before getting into details:

  1. Parallelism use is intrinsically a benefit for costly queries, bound by the Cost Threshold for Parallelism and Max Degree of Parallelism server configurations among other considerations. See the Query Processing Guide for more in-depth information on how SQL Server implements parallelism. Also refer to Craig Freedman’s blog series on the topic.
  2. Waits are a normal part of the waits and queues model, allowing SQL Server to concurrently execute many more requests than there are schedulers available. See more about waits and queues here,

It’s also important to understand that parallelism is implemented as if it were two operators. There’s the producers that push data to consumers, and the consumers that may have to wait for data from producers.

And so it becomes easier to understand how producer waits are the ones that may require attention, while consumer waits are inevitable as a passive consequence of longer running producers.

What is what going forward?

With this split, CXPACKET occurs when trying to synchronize the query processor exchange iterator or getting a required buffer.

  • This is the actionable wait. If contention on this wait type becomes a problem for most of your workload, consider for example:
  • Lowering the Max Degree of Parallelism, which can be done at the server or query level;
  • Changing the default Cost Threshold for Parallelism based on observed query cost for your entire workload;
  • Or better yet, by improving cardinality estimations if actual rows are very different from estimations. See this previous blog post on how to use the new SSMS Plan Analysis feature to get insights into cardinality estimation differences. Improving estimations can include actions such as updating or adding statistics, revising the underlying index design (consider leveraging the Database Tuning Advisor for this), or even hinting the Query Optimizer in edge cases.

And CXCONSUMER occurs when a consumer thread waits for a producer thread to send rows.

  • This is a wait type that is a normal part of parallel query execution, and cannot be directly influenced by changing the above mentioned configurations. This is why I called it "negligible" above.

Where can I see how this affects my SQL Servers?

These wait types will be surfaced at the server level with sys.dm_os_wait_stats and session level with sys.dm_exec_session_wait_stats DMVs.

However, because CXCONSUMER is not actionable directly, this wait will not surface in the Performance Dashboard, in Query Store (waits are available starting with SQL Server 2017), nor in Showplan.

Practical example

Take the following simple query running in AdventureWorks2016:

SELECT *
FROM Sales.SalesOrderDetail SOD
INNER JOIN Production.Product P ON SOD.ProductID = P.ProductID
WHERE SalesOrderDetailID > 10
ORDER BY Style

With the resulting showplan:

 

image

Since we have wait stats and query time stats in the root node of showplan, let’s see how they look:

image image

A lot of CXPACKET waits, totaling over 31s, for 1.2s CPU and 2.8s overall elapsed execution time. Also notice from showplan, this query is executing with DOP 12:

image

As mentioned above, both producer and consumer waits are tracked at the server and session level, so let’s look at sys.dm_exec_session_wait_stats also. Note that any change that is done to improve on the high waits scenario above is aimed at producer waits (CXPACKET), given consumer waits (CXCONSUMER) may inevitably exist a normal part of parallelism:

image

Ok, so actually most of the parallelism waits are producer waits. We may expect to see consumer waits to go up in the initial moments of parallel query execution, but then stabilize.

A quick way to handle this scenario is to reduce DOP using a hint:

SELECT *
FROM Sales.SalesOrderDetail SOD
INNER JOIN Production.Product P ON SOD.ProductID = P.ProductID
WHERE SalesOrderDetailID > 10
ORDER BY Style
OPTION (MAXDOP 4)
In the resulting plan, here are the wait stats and query time stats:
image image

CXPACKET waits down to just over 10s, for 0.8s CPU and 2.7s overall elapsed execution time. So while the elapsed time remained very similar (although lower), there were gains in reducing CPU usage and waits (3x lower) by adjusting DOP just enough.

Your mileage may vary depending on your setup, but thinking that this query may run at scale in a given environment, the gains are relevant. And were made possible by all the insights unlocked in showplan.

Pedro Lopes (@sqlpto) – Senior Program Manager

Viewing all 194 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>