Przeglądaj źródła

Added more SQLIntersection sessions

pmasl 6 lat temu
rodzic
commit
1f78b1de76

BIN
Sessions/SQLIntersection-2018/Gems to Help You Troubleshoot Query Performance v2.pdf


BIN
Sessions/SQLIntersection-2018/Practical guidance to make your tier-1 SQL Server roar.pdf


BIN
Sessions/SQLIntersection-2018/SQL-Server-Upgrades-Done-the-Right-Way.pdf


BIN
Sessions/SQLIntersection-2018/SQL-Server-Upgrades-Done-the-Right-Way.pptx


+ 32 - 0
Sessions/SQLIntersection-2018/automatic-tuning/README.md

@@ -0,0 +1,32 @@
+This is a repro package to demonstrate the Automatic Tuning (Auto Plan Correction) in SQL Server 2017. 
+This feature is using telemtry from the Query Store feature we launched with Azure SQL Database and SQL Server 2016 to provide built-in intelligence.
+
+This repro assumes the following:
+
+- SQL Server 2017 installed (pick at minimum Database Engine) on Windows. This feature requires Developer or Enterprise Edition.
+- You have installed SQL Server Management Studio or SQL Operations Studio (https://docs.microsoft.com/en-us/sql/sql-operations-studio/download)
+- You have downloaded the RML Utilities from https://www.microsoft.com/en-us/download/details.aspx?id=4511.
+- These demos use a named instance called SQL2017. You will need to edit the .cmd scripts which connect to SQL Server to change to a default instance or whatever named instance you have installed.
+
+0. Install ostress from the package RML_Setup_AMD64.msi. Add C:\Program Files\Microsoft Corporation\RMLUtils to your path.
+
+1. Restore the WideWorldImporters database backup to your SQL Server 2017 instance. The WideWorldImporters can be found in https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers
+
+2. Run Scenario.cmd to customize the WideWorldImporters database and start the demo. Leave it running...
+
+3. Setup Performance Monitor on Windows to track SQL Statistics/Batch Requests/sec
+
+4. While Scenario.cmd is running, run Regression.cmd (you may need to run this a few times for timing reasons). Notice the drop in batch requests/sec which shows a performance regression in your workload.
+
+5. Load recommendations.sql into SQL Server Management Studio or SQL Operations Studio and review the results. Notice the time difference under the reason column and value of state_transition_reason which should be AutomaticTuningOptionNotEnabled. This means we found a regression but are recommending it only, not automatically fixing it. The script column shows a query that could be used to fix the problem.
+
+6. Stop Scenario.cmd workload by pressing CTRL+C, and then choose "N" when prompted to terminate the batch.
+
+7. Now let's see what happens with automatic plan correction which uses this command in SQL Server 2017:
+
+ALTER DATABASE <db>
+SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = ON )
+
+8. Run Auto_tune.cmd which uses the above command to set automatic plan correct ON for WideWorldImporters, and starts same workload as Scenario.cmd
+
+9. Repeat steps 4-6 as above. In Performance Monitor you will see the batch requests/sec dip but within a second go right back up. This is because SQL Server detected the regression and automatically reverted to "last known good" or the last known good query plan as found in the Query Store. Note in the output of recommendations.sql the state_transition_reason now says LastGoodPlanForced.

BIN
Sessions/SQLIntersection-2018/automatic-tuning/at-demo.zip


BIN
Sessions/SQLIntersection-2018/live_query_troubleshooting/live_query_troubleshooting.zip


+ 130 - 0
Sessions/SQLIntersection-2018/new_xevents/ExtendedEvents.sql

@@ -0,0 +1,130 @@
+-- LWP related extended events Demo
+
+CREATE EVENT SESSION [PerfStats_Node] ON SERVER
+ADD EVENT sqlserver.query_thread_profile(
+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.ring_buffer(SET max_memory=(25600))
+ADD TARGET package0.event_file(SET filename=N'C:\IP\Tiger\SQL Intersection\SQL Intersection Winter 2018\Gems to Help You Troubleshoot Query Performance\new_xevents\PerfStats_Node.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
+
+USE AdventureWorks2016CTP3
+GO
+
+DROP EVENT SESSION [PerfStats_Node] ON SERVER 
+GO
+ALTER EVENT SESSION [PerfStats_Node] ON SERVER STATE = start;  
+GO  
+
+-- Execute plan with many nodes
+SELECT e.[BusinessEntityID], 
+       p.[Title], 
+       p.[FirstName], 
+       p.[MiddleName], 
+       p.[LastName], 
+       p.[Suffix], 
+       e.[JobTitle], 
+       pp.[PhoneNumber], 
+       pnt.[Name] AS [PhoneNumberType], 
+       ea.[EmailAddress], 
+       p.[EmailPromotion], 
+       a.[AddressLine1], 
+       a.[AddressLine2], 
+       a.[City], 
+       sp.[Name] AS [StateProvinceName], 
+       a.[PostalCode], 
+       cr.[Name] AS [CountryRegionName], 
+       p.[AdditionalContactInfo] 
+FROM   [HumanResources].[Employee] AS e 
+       INNER JOIN [Person].[Person] AS p 
+       ON RTRIM(LTRIM(p.[BusinessEntityID])) = RTRIM(LTRIM(e.[BusinessEntityID])) 
+       INNER JOIN [Person].[BusinessEntityAddress] AS bea 
+       ON RTRIM(LTRIM(bea.[BusinessEntityID])) = RTRIM(LTRIM(e.[BusinessEntityID])) 
+       INNER JOIN [Person].[Address] AS a 
+       ON RTRIM(LTRIM(a.[AddressID])) = RTRIM(LTRIM(bea.[AddressID])) 
+       INNER JOIN [Person].[StateProvince] AS sp 
+       ON RTRIM(LTRIM(sp.[StateProvinceID])) = RTRIM(LTRIM(a.[StateProvinceID])) 
+       INNER JOIN [Person].[CountryRegion] AS cr 
+       ON RTRIM(LTRIM(cr.[CountryRegionCode])) = RTRIM(LTRIM(sp.[CountryRegionCode])) 
+       LEFT OUTER JOIN [Person].[PersonPhone] AS pp 
+       ON RTRIM(LTRIM(pp.BusinessEntityID)) = RTRIM(LTRIM(p.[BusinessEntityID])) 
+       LEFT OUTER JOIN [Person].[PhoneNumberType] AS pnt 
+       ON RTRIM(LTRIM(pp.[PhoneNumberTypeID])) = RTRIM(LTRIM(pnt.[PhoneNumberTypeID])) 
+       LEFT OUTER JOIN [Person].[EmailAddress] AS ea 
+       ON RTRIM(LTRIM(p.[BusinessEntityID])) = RTRIM(LTRIM(ea.[BusinessEntityID]))
+GO
+
+ALTER EVENT SESSION [PerfStats_Node] ON SERVER STATE = stop;  
+GO 
+
+-- Choose any event and let's open the associated cached plan.
+-- I want to see which operator this one is, and where in the plan it sits
+
+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
+GO
+
+-- How will I search for my node_id? Use showplan search in SSMS.
+
+-------------------------------
+
+-- Now for a new event. A LWP-based "query_post_execution_showplan"
+
+DROP EVENT SESSION [PerfStats_LWP_Plan] ON SERVER 
+GO
+CREATE EVENT SESSION [PerfStats_LWP_Plan] ON SERVER
+ADD EVENT sqlserver.query_plan_profile(
+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.ring_buffer(SET max_memory=(25600))
+ADD TARGET package0.event_file(SET filename=N'C:\IP\Tiger\SQL Intersection\SQL Intersection Winter 2018\Gems to Help You Troubleshoot Query Performance\new_xevents\PerfStats_LWP_Plan.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
+
+ALTER EVENT SESSION [PerfStats_LWP_Plan] ON SERVER STATE = start;  
+GO   
+
+-- Let's run the following query
+SELECT e.[BusinessEntityID], 
+       p.[Title], 
+       p.[FirstName], 
+       p.[MiddleName], 
+       p.[LastName], 
+       p.[Suffix], 
+       e.[JobTitle], 
+       pp.[PhoneNumber], 
+       pnt.[Name] AS [PhoneNumberType], 
+       ea.[EmailAddress], 
+       p.[EmailPromotion], 
+       a.[AddressLine1], 
+       a.[AddressLine2], 
+       a.[City], 
+       sp.[Name] AS [StateProvinceName], 
+       a.[PostalCode], 
+       cr.[Name] AS [CountryRegionName], 
+       p.[AdditionalContactInfo] 
+FROM   [HumanResources].[Employee] AS e 
+       INNER JOIN [Person].[Person] AS p 
+       ON RTRIM(LTRIM(p.[BusinessEntityID])) = RTRIM(LTRIM(e.[BusinessEntityID])) 
+       INNER JOIN [Person].[BusinessEntityAddress] AS bea 
+       ON RTRIM(LTRIM(bea.[BusinessEntityID])) = RTRIM(LTRIM(e.[BusinessEntityID])) 
+       INNER JOIN [Person].[Address] AS a 
+       ON RTRIM(LTRIM(a.[AddressID])) = RTRIM(LTRIM(bea.[AddressID])) 
+       INNER JOIN [Person].[StateProvince] AS sp 
+       ON RTRIM(LTRIM(sp.[StateProvinceID])) = RTRIM(LTRIM(a.[StateProvinceID])) 
+       INNER JOIN [Person].[CountryRegion] AS cr 
+       ON RTRIM(LTRIM(cr.[CountryRegionCode])) = RTRIM(LTRIM(sp.[CountryRegionCode])) 
+       LEFT OUTER JOIN [Person].[PersonPhone] AS pp 
+       ON RTRIM(LTRIM(pp.BusinessEntityID)) = RTRIM(LTRIM(p.[BusinessEntityID])) 
+       LEFT OUTER JOIN [Person].[PhoneNumberType] AS pnt 
+       ON RTRIM(LTRIM(pp.[PhoneNumberTypeID])) = RTRIM(LTRIM(pnt.[PhoneNumberTypeID])) 
+       LEFT OUTER JOIN [Person].[EmailAddress] AS ea 
+       ON RTRIM(LTRIM(p.[BusinessEntityID])) = RTRIM(LTRIM(ea.[BusinessEntityID]))
+OPTION (RECOMPILE, USE HINT('QUERY_PLAN_PROFILE'))
+GO
+
+ALTER EVENT SESSION [PerfStats_LWP_Plan] ON SERVER STATE = stop;  
+GO 
+
+-- Let's see the event and what it provides