master af39147d2449 cached
156 files
2.5 MB
663.6k tokens
8 symbols
1 requests
Download .txt
Showing preview only (2,654K chars total). Download the full file or copy to clipboard to get everything.
Repository: microsoft/Azure_Synapse_Toolbox
Branch: master
Commit: af39147d2449
Files: 156
Total size: 2.5 MB

Directory structure:
gitextract_s92epeuo/

├── .gitignore
├── Archive/
│   └── Tools/
│       └── GetObjectsFromExplain.ps1
├── Azure_Resource_Graph_Queries/
│   ├── Inventory-DedicatedSqlPool.kql
│   ├── Inventory-SparkPools.kql
│   └── README.md
├── Distribution_Advisor/
│   ├── CreateDistributionAdvisor_PublicPreview.sql
│   ├── README.md
│   ├── RunDistributionAdvisor.sql
│   └── e2e_queries_used_for_recommendations.sql
├── LICENSE
├── Log_Analytics_queries/
│   ├── Pipelines/
│   │   ├── CompletedPipelineDurationInSeconds.kql
│   │   └── TopNLongestRunningPipelines.kql
│   ├── ServerlessSql/
│   │   ├── CostPerQuery.txt
│   │   ├── CostPerQuery.txt.bak
│   │   ├── CostPerUser.txt
│   │   └── CostPerUser.txt.bak
│   ├── Spark/
│   │   └── CoresAndMemoryByApplication.kql
│   ├── StandaloneSQLPool/
│   │   ├── CreateAnAzureSynapseDashboard.docx
│   │   ├── DedicatedSqlPoolUsage.kql
│   │   ├── LargestBroadcastSteps.kql
│   │   ├── LargestDataMovementSteps.kql
│   │   ├── LogAnalyticsBasicQueries.sql
│   │   ├── LongestBuildReplicatedTableCache
│   │   ├── MostReplicatedTableRebuilds.txt
│   │   ├── QueriesByExecutionTime.kql
│   │   ├── RepTableBuildCacheExecutionCount
│   │   ├── RowsProcessedPerHour
│   │   ├── SingletonInserts.kql
│   │   ├── TempTablesNotCreatedAsHeap.kql
│   │   └── UnionVsUnionAll.kql
│   └── WorkspacesSQLPool/
│       ├── FindLargeBroadcasts.kql
│       ├── IdentifySingletonInserts.kql
│       ├── LongestRunningQueriesByExecutionTime.kql
│       ├── QueriesWithResourceGrant.kql
│       ├── QueryList_withResultSetCacheData.kql
│       ├── TempTableASHeap.kql
│       └── UnionVsUnionAll.kql
├── Monitor_Workbooks/
│   ├── DW_Summary_v1.1.workbook
│   ├── DedicatedSQLPool_workspace_v1.2.workbook
│   ├── DedicatedSqlPool_Non-Workspace_v1.4.workbook
│   ├── README.md
│   ├── SynapsePipelines_v1.1.workbook
│   ├── SynapseServerlessWorkbook.workbook
│   └── archive/
│       ├── DW_Summary.workbook.bak
│       ├── DedicatedSQLPool_workspace_v1.0.workbook
│       ├── DedicatedSQLPool_workspace_v1.1.workbook
│       ├── DedicatedSQLPool_workspace_v1.1.workbook.bak
│       ├── DedicatedSqlPool_Non-Workspace_v1.32.workbook
│       ├── StandaloneSqlPoolWorkbook_v1.31.json
│       ├── SynapsePipelines.workbook
│       ├── SynapsePipelines.workbook.bak
│       ├── SynapsePipelines_v1.1.workbook.bak
│       ├── SynapseServerlessWorkbook.workbook
│       ├── SynapseServerlessWorkbook.workbook.bak
│       ├── SynapseWorkbook_WIP_v01.json
│       ├── SynapseWorkbook_WIP_v02.json
│       ├── SynapseWorkbook_v1.00.json
│       ├── SynapseWorkbook_v1.01.json
│       ├── SynapseWorkbook_v1.1.json
│       ├── SynapseWorkbook_v1.3.json
│       ├── WorkspaceSQLPoolWorkbook_WIP_v0.60.JSON
│       ├── WorkspaceSQLPoolWorkbook_WIP_v0.73.JSON
│       └── WorkspaceSQLPoolWorkbook_WIP_v0.77.JSON
├── PowerBI/
│   ├── README.md
│   └── Templates/
│       ├── AzureSynapse_DbHealth_08_21_20.pbit
│       ├── AzureSynapse_Permissions_07172020.pbit
│       └── AzureSynapse_Realtime_07172020.pbit
├── README.md
├── SECURITY.md
├── Synapse_Analyzer/
│   ├── README.md
│   └── Synapse_BPA_Report/
│       ├── ArchivedVersions/
│       │   ├── README.md
│       │   └── Synapse best practice analyzer_v1.0.pbit
│       ├── ForLargeDBwithCTAS/
│       │   ├── CreateTablesForSynapseAnalyzer.sql
│       │   ├── README.md
│       │   └── Synapse best practice analyzer_with_CTAS.pbit
│       ├── InstallationGuide.md
│       ├── PublishToPowerBIService.md
│       ├── README.md
│       ├── Synapse best practice analyzer.pbit
│       ├── TroubleshootingGuide.md
│       └── UpdatestoSynapseAnalyzerReport.md
├── Synapse_Toolkit/
│   ├── README.md
│   ├── SynapseToolkit.sql
│   ├── SynapseToolkit_beta.sql
│   └── SynapseToolkit_beta.sql.bak
└── TSQL_Queries/
    ├── Current_Activity/
    │   ├── CollectNodeMemoryUsage.sql
    │   ├── CountGrantedConcurrencySlots.sql
    │   ├── DMSHeavyHitters.sql
    │   ├── IdentifyBlocking1.sql
    │   ├── IdentifyBlocking2.sql
    │   ├── IdentifyResourceWaits.sql
    │   ├── MemoryGrantPerDistribution.sql
    │   ├── QueuedQueryTime.sql
    │   ├── RecentQueries.sql
    │   ├── ResourceWaitConsumptionByQuery.sql
    │   └── UsedConcurrencySlotsInfo.sql
    ├── Delta Lake/
    │   ├── README.md
    │   └── delta.sql
    ├── Identity_Columns/
    │   └── IdentityColumns.sql
    ├── Indexes/
    │   ├── CCIHealthByTable.sql
    │   ├── CCIHealthWithTrimReasons
    │   ├── CCITrimReason_BETA.sql
    │   ├── CreateRowgroupHealthView.sql
    │   ├── ReorgOrRebuildColumnstoreByPartition_All.sql
    │   └── ReorgOrRebuildColumnstore_LatestPartitionsOnly.sql
    ├── Partitions/
    │   ├── GetPartitionColumn.sql
    │   ├── MaxPartitionWithData.sql
    │   └── RowsPerPartition.sql
    ├── Permissions/
    │   └── All_Database_Permissions.sql
    ├── Query_Store/
    │   ├── GetApproxTimeRemaining_QueryStore.sql
    │   ├── GetFullQueryText.sql
    │   ├── GetQueriesWithBiggestIOReads.sql
    │   ├── GetQueriesWithMultiplePlans.sql
    │   ├── GetQueryExecutionTime.sql
    │   ├── GetQueryStoreSpaceUsage.sql
    │   ├── GetQueryStoreState.sql
    │   ├── GetRecentlyRegressedQueries.sql
    │   ├── GetTopQueriesByExecutionCount.sql
    │   ├── GetTopQueriesByExecutionTime.sql
    │   ├── PerfRegressionPlanChoiceChange.sql
    │   └── QueriesWithPerfRegression.sql
    ├── Replicated_Tables/
    │   └── RepTablesRebuildNeeded.sql
    ├── SLO-DWU/
    │   ├── ChangeDwuSetting.sql
    │   ├── CheckDwuChangeStatus.sql
    │   ├── CreateColumnstoreDensityView.sql
    │   └── GetDwuSetting.sql
    ├── ServerlessSql/
    │   └── CostPerQuery.sql
    ├── Statistics/
    │   ├── CheckAutoStatsEnabled.sql
    │   ├── CreateSP_CreateStatsAllColumnsAllTables.sql
    │   ├── CreateSP_GenUpdateStatsStatements.sql
    │   ├── CreateStatsAllColumnsAllTables.sql
    │   ├── GetStatsLastUpdateDate.sql
    │   ├── ListAllStats.sql
    │   ├── ListAllStats.sql.bak
    │   └── StatisticsAccuracy.sql
    ├── Table_Information/
    │   ├── CollectTableInformation.sql
    │   ├── CreateTableInfoView.sql
    │   ├── DataTypeMismatch.sql
    │   ├── DistributionSpaceSummary.sql
    │   ├── FindNullableDistColumns.sql
    │   ├── GenerateTableSchemas.sql
    │   ├── IdentifyLargeDataTypes.sql
    │   ├── MostUsedTables_BETA.sql
    │   ├── TableSizeByDistType.sql
    │   ├── TableSizeByIndexType.sql
    │   ├── TableSizeSummary.sql
    │   ├── TableSkew.sql
    │   ├── TableUsageInformation.sql
    │   └── TablesWithMostLargeTypes.sql
    ├── TempDB/
    │   ├── TempDbPerNode.sql
    │   ├── TempDbPerQuery.sql
    │   └── TotalTempDbUsage.sql
    ├── Workarounds/
    │   └── RecursionWorkaround_HierarchicalTableSample.sql
    └── Workload_Management/
        ├── CurrentRoleByUser.sql
        ├── ViewWorkloadGroups.sql
        └── WorkloadManagementMappingsAndUsage.sql

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Visual Studio 2017 auto generated files
Generated\ Files/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# Benchmark Results
BenchmarkDotNet.Artifacts/

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# StyleCop
StyleCopReport.xml

# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# Visual Studio Trace Files
*.e2e

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs

# Including strong name files can present a security risk 
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak

# SQL Server files
*.mdf
*.ldf
*.ndf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Tabs Studio
*.tss

# Telerik's JustMock configuration file
*.jmconfig

# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output 
ASALocalRun/

# MSBuild Binary and Structured Log
*.binlog

# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder 
.mfractor/


================================================
FILE: Archive/Tools/GetObjectsFromExplain.ps1
================================================
<# Get_Objects_From_Explain.ps1
    
    Author: Nick.salch@Microsoft.com (Nicksalc)
    This tool will take in an explain XML, then detect all fo the following
    that are mentioned in the explain plan:
        Databases
        Tables
        Columns
    It will also output update stats statements for all tables invovled in the query. 
    
    Output is placed under c:\temp\Timestamp_Folder
#>
param($ExplainXmlPath)

If(!$ExplainXmlPath)
{
    do
    {

        $ExplainXmlPath = Read-host "Please enter full path to XML"
        if (!(test-path $ExplainXmlPath)) 
        {
            Write-host -foregroundcolor red -backgroundcolor black "path not found"
        }ELSE{$goodPath=$true}
    
    }
    while(!$goodPath)
}


$date = get-date -Format MMddyyyy_hhmmss
$OutputFolder="C:\temp\$date\"
mkdir $OutputFolder -Force | out-null

$explainXml = Get-Content $ExplainXmlPath

#Remove the user query part of the query (this part can be messy so I jsut remove it)
$i=0
while (!($explainXml[$i] | select-string "total_number_operations="))
{
    $i++
}
$explainXml = $explainXml[$i..$explainXml.Length]

#Extract the db.schema.table names 

$objectList = $explainXml | Select-String "\[([^\[]*)\].\[([^\[]*)\].\[([^\[]*)\]" | select-string -NotMatch "qtabledb" |select-string -NotMatch "tempdb"  | % {$_.matches.value}
$objectList = $objectList | select -Unique
$objectList > "$OutputFolder\ObjectList.txt"
$tableList = $objectList | % {$_.split(".")[1] + "." +  $_.split(".")[2]}

#Extract Shuffle Columns
$shuffleColumnLines = ($explainXml | select-string "shuffle_columns")
$ShuffleColumns = @()
Foreach ($column in $shuffleColumnLines)
{
    $column = $column.ToString()
    $ShuffleColumns += $column.Substring($column.IndexOf(">")+1,$column.IndexOf(";")-$column.IndexOf(">")-1)
    
}
$ShuffleColumns = $ShuffleColumns | select -Unique |sort
$ShuffleColumns > "$OutputFolder\ShuffleColumns.txt"


#Extract the columns used
$involvedColumns=@()
Foreach ($string in (($explainXml | select-string " AND "," OR "," WHERE "," WHEN "," GROUP BY "," ELSE ") ))
{
    $SplitString = $string -split "]\.\["
    #$splitString.Count

    $counter = 1
    While ($counter -lt $splitString.count)
    {
        if($splitString[$counter].indexOf("]") -gt 0)
        {
            $involvedColumns += $splitString[$counter].Substring(0,$splitString[$counter].indexOf("]"))  
        }
        $counter++
    }

}

$involvedColumns += $ShuffleColumns
$involvedColumns = $involvedColumns | select -Unique | sort

#Write-host -foregroundcolor Cyan "`nInvolved Columns`n"
$involvedColumns > "$OutputFolder\involvedColumns.txt"

Write-Host -Foregroundcolor Cyan  "$($tableList.Count) Involved Tables Detected"
Write-host -Foregroundcolor Cyan  "$($ShuffleColumns.count) Shuffle Columns Detected"
Write-Host -Foregroundcolor Cyan  "$($involvedColumns.Count) Involved Columns Detected"

#create the update stats statements
$UpdateStatsStatements = @()

$UpdateStatsStatements += $tableList | % {"UPDATE STATISTICS $_"}
$UpdateStatsStatements > "$OutputFolder\tsql_UpdateStatsCommands.txt"

Write-host -ForegroundColor Cyan "`nOutput folder: $OutputFolder"
#>

================================================
FILE: Azure_Resource_Graph_Queries/Inventory-DedicatedSqlPool.kql
================================================
Resources
| where type == 'microsoft.sql/servers'
| project name, id, resourceGroup, location, subscriptionId, tags
| join kind=inner (Resources
	| where type == 'microsoft.sql/servers/databases'
	| where sku.tier == 'DataWarehouse'
	| extend CurrentServiceObjective = properties.currentServiceObjectiveName
	| extend RequestedServiceObjective = properties.requestedServiceObjectiveName
	| extend IsSynapseWorkspaceAssociated = iff(kind contains 'analytics', true, false)
	| parse CurrentServiceObjective with "DW" CurrentDWU "c"
	| extend status = tostring(properties.status)
	| parse id with ParentSqlServerId "/databases/" Discard) on $left.id == $right.ParentSqlServerId
	| project-rename DatabaseName = name1, ServerName = name, ServerResourceId = id, DatabaseResourceId = id1, ServerTags = tags, DatabaseTags = tags1
	| project-away managedBy, plan, resourceGroup1, subscriptionId1, type, tenantId, sku, identity, zones, Discard, ParentSqlServerId, kind, apiVersion, properties, extendedLocation
| join kind=leftouter (ResourceContainers 
	| where type == 'microsoft.resources/subscriptions' 
	| project SubscriptionName = name, subscriptionId) on subscriptionId
| project-away subscriptionId1
| project-rename SubscriptionId = subscriptionId, ResourceGroup = resourceGroup, Location = location
| project SubscriptionName, SubscriptionId, ResourceGroup, ServerName, ServerResourceId, ServerTags, DatabaseName, DatabaseResourceId, DatabaseTags, Location, CurrentDWU, CurrentServiceObjective, RequestedServiceObjective, IsSynapseWorkspaceAssociated

================================================
FILE: Azure_Resource_Graph_Queries/Inventory-SparkPools.kql
================================================
Resources
| where type == "microsoft.synapse/workspaces/bigdatapools"
| project name, id, resourceGroup, location, subscriptionId, tags, NodeSizeFamily = properties.nodeSizeFamily, NodeSize = properties.nodeSize, SparkVersion = properties.sparkVersion, AutoPause = properties.autoPause.enabled, AutoScale = properties.autoScale.enabled, MinNodeCount = properties.autoScale.minNodeCount, MaxNodeCount = properties.autoScale.maxNodeCount
| parse id with * "/workspaces/" AssociatedSynapseWorkspaceName "/bigDataPools/" Discard
| join kind=leftouter (Resources 
    | where type == "microsoft.synapse/workspaces"
    | extend WorkspaceResourceId = id
    | extend WorkspaceName = name
    | project WorkspaceName, WorkspaceResourceId) on $left.AssociatedSynapseWorkspaceName == $right.WorkspaceName
| join kind=leftouter (ResourceContainers 
    | where type == 'microsoft.resources/subscriptions' 
    | project SubscriptionName = name, subscriptionId) on subscriptionId
| project-away subscriptionId1, Discard, AssociatedSynapseWorkspaceName
| project-rename SparkPoolName = name, SparkPoolResourceId = id, ResourceGroup = resourceGroup, Location = location, SubscriptionId = subscriptionId, Tags = tags
| project SparkPoolName, SparkPoolResourceId, ResourceGroup, Location, SubscriptionName, SubscriptionId, Tags, NodeSizeFamily, NodeSize, SparkVersion, AutoPause, AutoScale, MinNodeCount, MaxNodeCount, WorkspaceName, WorkspaceResourceId


================================================
FILE: Azure_Resource_Graph_Queries/README.md
================================================
# Azure Synapse Inventory via Azure Resource Graph
The following [Azure Resource Graph](https://azure.microsoft.com/en-us/features/resource-graph/) queries assist with gathering Azure tenant inventory for Azure resources related to Azure Synapse Analytics. They are intended to aid cost optimization, general inventory needs, normalizing or standardization of configuration, and more.

## Pre-Requisites
1. RBAC 'Reader' or equivalent access to Azure Synapse related resources. See [Azure Resource Graph permissions](https://docs.microsoft.com/en-us/azure/governance/resource-graph/overview#permissions-in-azure-resource-graph) documentation for specifics.
2. Access to the Azure Portal or an Azure PowerShell or CLI session. 


## To use these queries:
1. Navigate to the Azure Portal. Search or select the [Azure Resource Graph Explorer](https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-portal) and paste the text of the desired query into the query window. Select run query.
2. Alternatively you may programmatically execute these queries programmatically via CLI or SDKs.
    - Execute Azure Resource Graph queries via [Azure PowerShell](https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-powershell)
    - Execute Azure Resource Graph queries via [Azure CLI](https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-azurecli)
    - Execute Azure Resource Graph queries via language specific [SDK or REST API](https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-rest-api) 

# Sample queries for gathering inventory: 

## Dedicated SQL Pools
[Inventory-DedicatedSqlPool](Inventory-DedicatedSqlPool.kql) - Lists dedicated SQL pools (formerly SQL DW) visible to the executing Azure context returning the subscription, resource group, parent Azure SQL Server, current SKU, standalone or association with Azure Synapse Workspace, and more.

## Serverless SQL Pools
To be completed.

## Spark Pools
[Inventory-SparkPools](Inventory-SparkPools.kql) - Lists Spark pools (Synapse Spark) visible to the executing Azure context returning the subscription, resource group, parent Azure Synapse Analytics workspace, SKU, and more. 

## Kusto Pools
To be completed.

# Troubleshooting

## Runtime errors with Azure Resource Graph

[Checklist to review](https://docs.microsoft.com/en-us/azure/governance/resource-graph/troubleshoot/general) if errors are returned or no data is returned from these queries. If not data is returned the root cause is RBAC access to the Azure Synapse related Azure resources.





================================================
FILE: Distribution_Advisor/CreateDistributionAdvisor_PublicPreview.sql
================================================
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.write_dist_recommendation'))
	DROP PROCEDURE dbo.write_dist_recommendation
go

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.read_dist_recommendation'))
	DROP PROCEDURE dbo.read_dist_recommendation
go

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.format_recommendation'))
	DROP PROCEDURE dbo.format_recommendation
go

CREATE PROCEDURE dbo.format_recommendation @recommendation NVARCHAR(MAX)
AS
BEGIN
    IF (@recommendation IS NULL OR len(@recommendation) = 0)
      BEGIN
          RAISERROR (N'No recommendation was found', 18, - 1);
      END
    ELSE
    BEGIN
        -- Parse the recommendation result
        DECLARE @FirstDistribBegin INT = PATINDEX('%Table Distribution Changes%', @recommendation);
        DECLARE @FirstDistribEnd INT = PATINDEX('%------------------------------------------------------------%', @recommendation);
        DECLARE @JumpPast NVARCHAR(max) = 'Table Distribution Changes';

		SET @FirstDistribBegin = @FirstDistribBegin + LEN(@JumpPast) + 2; -- +1 to eat newline at the beginning
		DECLARE @DistribLength int = @FirstDistribEnd - @FirstDistribBegin - 2; -- extra -2 to remove newlines at the end

        IF (@DistribLength <= 0)
          BEGIN
              RAISERROR (N'No distribution to show. The query does not involve any tables, or the tables do not exist.', 18, - 1);
          END
        ELSE
            DECLARE @FirstDistrib NVARCHAR(max);

        SELECT @FirstDistrib = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(SUBSTRING(@recommendation, @FirstDistribBegin, @DistribLength), CHAR(9), ''), CHAR(13), ''), '->', ''), '  ', ' '), ' ', '","'), CHAR(10), '"],["');

        SELECT @FirstDistrib = REPLACE(REPLACE(@FirstDistrib, 'Distributed', 'Hash'), ':', '');

        SELECT @FirstDistrib = '[["' + @FirstDistrib + '"]]';

        -- Format the recommendation output 
        SELECT y.TableName
            , CurrentDistribution
            , SuggestedDistribution
            , ChangeCommand = CASE 
                WHEN CurrentDistribution = SuggestedDistribution
                    THEN N'<no change>'
                ELSE CONCAT (
                        N'CREATE TABLE ', y.TableName, N'_changed 
                        WITH (DISTRIBUTION=', REPLACE(REPLACE(SuggestedDistribution, 'replicated', 'REPLICATE'), 'Hash', 'HASH'), N', ', i.TableIndex, ') 
                        AS SELECT * FROM ', y.TableName, N';

                        DROP TABLE ', y.TableName, '; 
                        RENAME OBJECT ', y.TableName, N'_changed TO ', i.tableName, ';')
                END
            , Remarks = CASE 
                WHEN PATINDEX('%Hash%', CurrentDistribution) > 0
                    AND CHARINDEX(',', CurrentDistribution) > 0
                    THEN N'MCD tables are not considered by the current DA version.'
                ELSE ''
                END
        FROM (
            SELECT [0] AS TableName
                , [1] AS CurrentDistribution
                , [2] AS SuggestedDistribution
            FROM (
                SELECT pvt.*
                FROM (
                    SELECT row_no = [rows].[key]
                        , col_no = [cols].[key]
                        , cols.[value]
                    FROM (
                        SELECT [json] = @FirstDistrib
                        ) step1
                    CROSS APPLY openjson([json]) [rows]
                    CROSS APPLY openjson([rows].[value]) [cols]
                    ) base
                pivot(max(base.[value]) FOR base.col_no IN ([0], [1], [2])) pvt
                ) x
            WHERE [1] IS NOT NULL
                AND [2] IS NOT NULL
            ) y
        JOIN (
            SELECT CONCAT (
                    DB_NAME()
                    , '.'
                    , OBJECT_SCHEMA_NAME(t.object_id)
                    , '.'
                    , t.name
                    ) AS FullObjectName
                , OBJECT_SCHEMA_NAME(t.object_id) AS schemaName
                , t.name AS tableName
                , i.type
                , CASE i.type
                    WHEN 0
                        THEN 'HEAP'
                    WHEN 1
                        THEN CONCAT ('CLUSTERED INDEX (', STRING_AGG(CAST(c.Name as VARCHAR(MAX)), ', ') WITHIN GROUP (ORDER BY ic.key_ordinal ASC), ')')
                    WHEN 5
                        THEN 'CLUSTERED COLUMNSTORE INDEX'
                    END AS TableIndex
            FROM sys.tables t
            LEFT JOIN sys.indexes i
                ON t.object_id = i.object_id
                    AND i.type IN (0, 1, 5)
            LEFT JOIN sys.index_columns ic
                ON i.index_id = ic.index_id
                    AND i.object_id = ic.object_id
            LEFT JOIN sys.columns c
                ON ic.column_id = c.column_id
                    AND ic.object_id = c.object_id
            GROUP BY t.name
                , t.object_id
                , i.name
                , i.type
            ) i
            ON y.TableName = i.FullObjectName
    END
END
GO

CREATE PROCEDURE write_dist_recommendation
	@NumMaxQueries int, 
	@Queries NVARCHAR(MAX)
AS BEGIN
	DECLARE @sql nvarchar(MAX);
	DECLARE @sessionid nvarchar(max) = SESSION_ID();
	DECLARE @guid nvarchar(100) = REPLACE(NEWID(), '-', '');
	DECLARE @guidpusher nvarchar(max) = CONCAT(N'    --distrib_advisor_correlation_id_', @guid, CHAR(13), CHAR(10));
	DECLARE @recostring nvarchar(max);
	if not exists ( select * from sys.tables where name = 'DistributionAdvisorSelectedQueries')
		create table DistributionAdvisorSelectedQueries(command nvarchar(4000), tot_te bigint) with(clustered columnstore index, distribution = ROUND_ROBIN);

	-- Filter queries that will not be considered by DA.
	IF (@Queries is NULL)
		BEGIN
			if (@NumMaxQueries is NULL or @NumMaxQueries < 1 or @NumMaxQueries > 100)
				BEGIN
					RAISERROR(N'Max queries value must be in [1...100] range, changing to 100.', 0, -1);
					SET @NumMaxQueries = 100;
				END
			SET @sql = 'with topnqueries as 
					(select top(@nmq) command, MIN(total_elapsed_time) AS min_te, AVG(total_elapsed_time) AS avg_te, COUNT(*) AS num_runs, SUM(total_elapsed_time) AS tot_te
					from (select command = case when command2 is null then command else command2 end, total_elapsed_time
					from sys.dm_pdw_exec_requests
					where
						command not like ''%USE [[]DWShellDb%\'' and
						command not like ''%DistributionAdvisor%'' and
						command not like ''--Backing up Logical Azure Database%\'' and
						command not like ''%select % as ConnectionProtocol%'' and
						command like ''%select%'' and
						command not like ''%set recommendations%'' and 
						command not like ''USE [[]%]'' and
						command not like ''%sys.system_sql_modules%'' and
						command not like ''%insert%'' and
						command not like ''%sys.indexes%'' and
						command not like ''%merge%'' and
						command not like ''%CREATE%TABLE%'' and
						command not like ''%dm_pdw_exec_requests%'' and
						command not like ''%sys.databases%'' and
						command not like ''%trancount%'' and 
						command not like ''%spid%'' and total_elapsed_time > 300 and
						command not like ''%SERVERPROPERTY%'' and resource_class != ''NULL'' and
						command not like ''%sys.objects%'' and 
						command not like ''%sys.tables%'' and 
						command not like ''%sys.schemas%'' and 
						command not like ''%sys.dm_pdw_%'' and
						status = ''Completed'') x
					GROUP BY command
					ORDER BY tot_te desc),
				allqueries as (select command, tot_te from topnqueries union all select * from DistributionAdvisorSelectedQueries),
				allqueriesgrouped as (select command, sum(tot_te) as tot_te from allqueries group by command),
				topnqueriesranked as (select REPLACE(command, '''''';'''''', ''CHAR(59)'') as command, tot_te, row_number() over (order by tot_te desc) as rn from allqueriesgrouped)
			select @recostring = 
			''set recommendations on;'' + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) 
			+ ''/****************** Actual queries follow ****************************/'' + CHAR(13) + CHAR(10) +
			STRING_AGG(
				''/************************** Query q'' + cast (rn-1 as nvarchar(max)) + '' ********************************/'' + CHAR(13) + CHAR(10) + 
				(case 
				when charindex('';'', command) > 0 
				then REPLACE(REPLACE(cast(command AS nvarchar(max)), ''--distrib_advisor_correlation_id_'', ''--''), '';'', @guidpusher)
				else concat(command, @guidpusher)
				end),
				'';'' + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)) +
			 + CHAR(13) + CHAR(10) + ''/******************** End actual queries **************************/'' + CHAR(13) + CHAR(10) +
			''set recommendations off;''
			from topnqueriesranked';
			END
	ELSE
		BEGIN
			SET @NumMaxQueries = 100;
			SET @Queries = REPLACE(@Queries, ''';''', 'char(59)');
			SET @sql = 'with userqueries as 
						(select CONCAT(value,'';'') as command, ordinal as tot_te
						from STRING_SPLIT(@customQueries, '';'', 1) where trim(value) <> '''' union all select * from DistributionAdvisorSelectedQueries),
						topnqueriesranked as (select *, row_number() over (order by tot_te desc) as rn from userqueries)
						select @recostring = 
						''set recommendations on;'' + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) 
						+ ''/****************** Actual queries follow ****************************/'' + CHAR(13) + CHAR(10) +
						STRING_AGG(
							''/************************** Query q'' + cast (rn-1 as nvarchar(max)) + '' ********************************/'' + CHAR(13) + CHAR(10) + 
							(case 
							when charindex('';'', command) > 0 
							then REPLACE(REPLACE(cast(command AS nvarchar(max)), ''--distrib_advisor_correlation_id_'', ''--''), '';'', @guidpusher)
							else concat(command, @guidpusher)
							end),
							'';'' + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)) +
						 + CHAR(13) + CHAR(10) + ''/******************** End actual queries **************************/'' + CHAR(13) + CHAR(10) +
						''set recommendations off;''
						from topnqueriesranked';
			END
	EXEC sp_executesql @sql, N'@recostring nvarchar(max) OUTPUT, @guidpusher nvarchar(max), @nmq int, @customQueries nvarchar(max)', @recostring OUTPUT, @guidpusher, @NumMaxQueries, @Queries;

	IF (@recostring is null or len(@recostring) = 0)
	BEGIN
		RAISERROR(N'Cannot construct the set of queries to feed to advisor. This often happens if there are not enough queries in sys.dm_pdw_exec_requests.', 18, -1);
	END
	ELSE
		BEGIN
			-- For debugging purposes.
			SELECT @recostring AS Command_To_Invoke_Distribution_Advisor;

			-- A command to invoke Distribution Advisor with the above string.
			EXEC sp_executesql @recostring;

			RAISERROR(N'Please use ''read_dist_recommendation'' stored procedure after recommendation is created to retrieve it', 0, -1);
		END
END
GO

-- This stored procedure reads the recommendation advice generated in write_dist_recommendation.
CREATE PROCEDURE read_dist_recommendation
AS BEGIN

	DECLARE @sessionid nvarchar(max) = SESSION_ID();

	-- get the answer from ring buffer; we may have to wait a bit, so we do a few tries for the ring buffer to get ready
	DECLARE @recommendation nvarchar(max);
	DECLARE @readrecommendation nvarchar(max) = N'select @recommendation = recommendation from sys.dm_pdw_distrib_advisor_results where @sessionid = session_id ';
	DECLARE @DelayStart datetime = GETDATE();

	-- Retrying for 10 seconds
	WHILE (@recommendation is null or len(@recommendation) = 0) and  DATEDIFF(second, @DelayStart, GETDATE()) < 10
	BEGIN
		EXEC sp_executesql @readrecommendation, N'@recommendation nvarchar(max) OUTPUT, @sessionid nvarchar(max)', @recommendation OUTPUT, @sessionid;
		if (@recommendation is null or len(@recommendation) = 0)
		BEGIN
			RAISERROR(N'No recommendation yet in ring buffer; waiting...', 0, -1);
		END
	END

	-- parsing and formatting the recommendation
	EXEC dbo.format_recommendation @recommendation;
END
GO


================================================
FILE: Distribution_Advisor/README.md
================================================
# Distirbution Advisor

Please follow [these instructions](https://docs.microsoft.com/en-us/azure/synapse-analytics/sql/distribution-advisor) to run Distribution Advisor.


================================================
FILE: Distribution_Advisor/RunDistributionAdvisor.sql
================================================

-- *******************************************************************************************
-- This portion is for a user input queries. 
-- PDW doesn't allow default values for stored procedures. So the input queries needs to be single string divided by a semicolon between each queries.
-- This can be simply done by declaring a variable for each query string, and then combine them by using CONCAT() function.
-- Max query number parameter is ignored in this scenario.
EXEC dbo.write_dist_recommendation NULL, 'select count (*) from t1; select * from t1 join t2 on t1.a1 = t2.a1; select count (*) from t1; select * from t1 join t2 on t1.a1 = t2.a1;';
go
-- Notice that the read_dist_recommendation and write_dist_recommendation stored procs need to be called together and seperated by go.
EXEC dbo.read_dist_recommendation;
go

-- *******************************************************************************************
-- This portion is for running DA on top @MaxNumQueries queries.
-- @MaxNumQueries parameter value can be in [1...100] range.
-- if both parameters passed as NULL, the stored procedure will generate recommendation for top 100 queries.
EXEC dbo.write_dist_recommendation 100, NULL
go
EXEC dbo.read_dist_recommendation;
go

-- *******************************************************************************************
-- The below is an example usage of format_recommendation stored procedure.
-- It takes the recommendation result as a parameter and displays in a formatted readable manner.
set recommendations on;
go

select 1;

set recommendations off;
go

DECLARE @sessionid nvarchar(100);
DECLARE @recommendation nvarchar(MAX);
select @sessionid = SESSION_ID();
select @recommendation = recommendation from sys.dm_pdw_distrib_advisor_results where session_id = @sessionid
EXEC dbo.format_recommendation @recommendation;

================================================
FILE: Distribution_Advisor/e2e_queries_used_for_recommendations.sql
================================================
DECLARE @NumMaxQueries int = 100; -- change this to match the variable in mvp script; looks at different numbers of queries.

-- the below where clauses should match those in the mvp script

with topnqueries as 
		(select top(@NumMaxQueries) command, COUNT(*) AS number_of_runs, SUM(total_elapsed_time) AS total_execution_time
		from sys.dm_pdw_exec_requests
		where
		command like '%select%' and
		command not like '%insert%' and 
		command not like '%USE [[]DWShellDb%\' and
		command not like '--Backing up Logical Azure Database%\' and
		command not like '%select % as ConnectionProtocol%' and
		command not like '%set recommendations on%' and 
		command not like '%set recommendations off%' and
		command not like 'USE [[]%]' and
		command not like '%sys.system_sql_modules%' and
		command not like '%sys.indexes%' and
		command not like '%merge%' and
		command not like '%CREATE%TABLE%' and
		command not like '%dm_pdw_exec_requests%' and
		command not like '%sys.databases%' and
		command not like '%trancount%' and command not like '%spid%' and
		total_elapsed_time > 300 and
		command not like '%SERVERPROPERTY%' and 
		resource_class != 'NULL' and
		command not like '%sys.objects%' and command not like '%sys.tables%' and command not like '%sys.schemas%' and command not like '%sys.dm_pdw_%' and
		status = 'Completed'
		GROUP BY command
		ORDER BY total_execution_time desc)
		select * from topnqueries;

================================================
FILE: LICENSE
================================================
    MIT License

    Copyright (c) Microsoft Corporation. All rights reserved.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE


================================================
FILE: Log_Analytics_queries/Pipelines/CompletedPipelineDurationInSeconds.kql
================================================
// Pipeline Durations in Seconds
SynapseIntegrationPipelineRuns
| where Status in ('Succeeded', 'Failed')
| extend PipelineDuration = iif(Status in ('Succeeded', 'Failed'),datetime_diff('second', End, Start),0)
| extend TriggerId = tostring(parse_json(Predecessors)[0].Id)
| join kind = leftouter (
            SynapseIntegrationTriggerRuns
                | project TriggerId, TriggerName
        ) on $left.TriggerId == $right.TriggerId
| project Start, TriggerName, TriggerId, PipelineName, RunId, PipelineDuration, Status

================================================
FILE: Log_Analytics_queries/Pipelines/TopNLongestRunningPipelines.kql
================================================
// Synapse Pipelines - Chart - Top N Longest Running Pipelines
// N == 5 
SynapseIntegrationActivityRuns 
| extend e_Resource = tostring(array_reverse(split(tolower(_ResourceId), '/'))[0])
| join kind = leftouter (
    SynapseIntegrationPipelineRuns    
    | extend TriggerId = tostring(parse_json(Predecessors)[0].Id)
    | join kind = leftouter (
        SynapseIntegrationTriggerRuns
        | project TriggerId, TriggerName
        )
        on $left.TriggerId == $right.TriggerId
    | project TriggerName, TriggerId, RunId
    )
    on $left.PipelineRunId == $right.RunId
| extend ActivityDuration = iif(Status in ('Succeeded', 'Failed'), datetime_diff('second', End, Start), 0)
| project
    e_Resource,
    ActivityName,
    Start,
    End,
    ActivityDuration,
    PipelineName,
    TriggerName,
    ActivityType
| summarize Avg_Duration = avg(ActivityDuration), Max_Duration = max(ActivityDuration) by e_Resource, TriggerName, PipelineName, ActivityName, ActivityType
| order by Max_Duration, Avg_Duration
| limit 5


================================================
FILE: Log_Analytics_queries/ServerlessSql/CostPerQuery.txt
================================================
//Cost per query
SynapseBuiltinSqlPoolRequestsEnded
//| where _ResourceId has 'contosoprod'
| project 
    BytesProcessed=Properties.dataProcessedBytes,
    tostring(Identity),
    QueryHash=tostring(Properties.queryHash),
    QueryText=tostring(Properties.queryText),
    _ResourceId
| extend MbProcessed = case (BytesProcessed < 10000000,10000000,
							BytesProcessed)/1000/1000
| summarize 
    MaxSingleQueryMBProcessed=max(toint(MbProcessed)),
    TotalMBProcessed=sum(toint(MbProcessed)),
    QueryCount=count(),
    QueryHash=any(QueryHash) ,
    Resource=any(_ResourceId)
    by QueryText //using queryText because queryHash doesn’t change if only literals are different
| extend Approx_Accumulated_Cost=((TotalMBProcessed)*5.0/100000.0)/100 
| extend Approx_Cost_Per_Execution=((TotalMBProcessed)*5.0/100000.0)/100/QueryCount
| order by TotalMBProcessed

================================================
FILE: Log_Analytics_queries/ServerlessSql/CostPerQuery.txt.bak
================================================
//Cost per query
SynapseBuiltinSqlPoolRequestsEnded
//| where _ResourceId has 'contosoprod'
| project 
    BytesProcessed=Properties.dataProcessedBytes,
    tostring(Identity),
    QueryHash=tostring(Properties.queryHash),
    QueryText=tostring(Properties.queryText),
    _ResourceId
| summarize 
    MaxSingleQueryMBProcessed=max(toint(BytesProcessed)/1024/1024),
    TotalMBProcessed=sum(toint(BytesProcessed)/1024/1024),
    QueryCount=count(),
    QueryHash=any(QueryHash) ,
    Resource=any(_ResourceId)
    by QueryText //using queryText because queryHash doesn’t change if only literals are different
| extend Approx_Accumulated_Cost=((TotalMBProcessed)*0.000476837158203125)/100 //multiply by price per mb ($5 per TB from Microsoft Docs: https://azure.microsoft.com/en-us/pricing/details/synapse-analytics/)
| extend Approx_Cost_Per_Execution=((TotalMBProcessed)*0.000476837158203125)/100/QueryCount
| order by TotalMBProcessed


================================================
FILE: Log_Analytics_queries/ServerlessSql/CostPerUser.txt
================================================
//Query cost by User
SynapseBuiltinSqlPoolRequestsEnded
//| where _ResourceId has 'contosoprod'
| project BytesProcessed=Properties.dataProcessedBytes
		, tostring(Identity)
| extend MbProcessed = case (BytesProcessed < 10000000,10000000,
                            BytesProcessed)/1000/1000
| summarize
    TotalMBProcessed=sum(toint(MbProcessed)),
    QueryCount=count(),
    MaxSingleQueryMBProcessed=max(toint(MbProcessed) )
    by Identity
| extend Approx_Cost=((TotalMBProcessed) *5.0/100000.0) / 100 
| order by TotalMBProcessed

================================================
FILE: Log_Analytics_queries/ServerlessSql/CostPerUser.txt.bak
================================================
//Query cost by User
SynapseBuiltinSqlPoolRequestsEnded
//| where _ResourceId has 'contosoprod'
| project BytesProcessed=Properties.dataProcessedBytes,tostring(Identity),_ResourceId
| summarize TotalMBProcessed=sum(toint(BytesProcessed)/1024/1024),QueryCount=count(),MaxSingleQueryMBProcessed=max(toint(BytesProcessed)/1024/1024),Resource=any(_ResourceId) by Identity
| extend Approx_Cost=((TotalMBProcessed)*0.000476837158203125)/100 //multiply by price per mb ($5 per TB from Microsoft Docs: https://azure.microsoft.com/en-us/pricing/details/synapse-analytics/)
| order by TotalMBProcessed


================================================
FILE: Log_Analytics_queries/Spark/CoresAndMemoryByApplication.kql
================================================
SparkListenerEvent_CL
| summarize Total_vCores_Used=sum(Executor_Info_Total_Cores_d), Total_Memory_Used_GB=sum(Maximum_Memory_d)/(1024*1024*1024) by applicationId_s, clusterName_s, livyId_s;


================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/DedicatedSqlPoolUsage.kql
================================================
// Intended to aid cost management of dedicated SQL pools
// Set the UsageBucket to the level of granularity desired e.g. 1 hour, 4 hours, 1 day
// Set the Lookback window to the duration of history to look back
// Essentially this is a simple % of total usage bucketed by UsageBucket. If the values
// are consistently low for PercentOfMaxDTU_Used the dedicated SQL pool may be a candidate
// for scale down and/or for dynamic scaling by ETL/ELT orchestration.
let UsageBucket = 1d;
let Lookback = 14d;
AzureMetrics
| where TimeGenerated > ago(Lookback)
| where MetricName == 'dwu_used'
| summarize Max_DWU_Used = max(Maximum) by bin(TimeGenerated, UsageBucket), MetricName, Resource
| join kind=inner (
    AzureMetrics
    | where TimeGenerated > ago(Lookback)
    | where MetricName == 'dwu_limit'
    | summarize DWU_Limit = max(Maximum) by bin(TimeGenerated, UsageBucket), MetricName, Resource)
        on (($left.TimeGenerated == $right.TimeGenerated) and ($left.Resource == $right.Resource))
| project-away MetricName, MetricName1, Resource1
| extend PercentOfMaxDTU_Used = ((1.0 * Max_DWU_Used) / (1.0 * DWU_Limit)) * 100.0
| project TimeGenerated, Resource, Max_DWU_Used, DWU_Limit, PercentOfMaxDTU_Used

================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/LargestBroadcastSteps.kql
================================================
let databaseName="<databaseNameAllCaps>";
AzureDiagnostics
| where Resource == databaseName
| where Category == 'RequestSteps'
| where OperationType_s == 'BroadcastMoveOperation'
| summarize rowcount=max(RowCount_d),max(TimeGenerated) by RequestId_s,StepIndex_d
| order by rowcount


================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/LargestDataMovementSteps.kql
================================================
//Most Rows Moved by step
// These are the largest data movement steps. Use this to identify a request ID to investigate
let databaseName = '<databaseName_ALL_CAPS>';
AzureDiagnostics
| where Category  == 'RequestSteps'
| where Resource  == databaseName
| extend elapsedTime = EndTime_t - StartTime_t
| extend elapsedTime_min = elapsedTime/1m
| order by RowCount_d desc
| project RequestId_s,OperationType_s, RowCount_d,elapsedTime_min , StartTime_t, EndTime_t, Status_s
//| limit 20


================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/LogAnalyticsBasicQueries.sql
================================================
//List all queries 
AzureDiagnostics
| where Category  == "ExecRequests"
| project TimeGenerated , ErrorId_g , RequestId_s , SessionId_s , Status_s , SubmitTime_t , StartTime_t , EndCompileTime_t , EndTime_t , Label_s , DatabaseId_d , Command_s , ResourceClass_s , StatementType_s

//Chart the most active resource classes
AzureDiagnostics
| where Category contains "ExecRequests"
| where Status_s == "Completed"
| summarize totalQueries = dcount(RequestId_s) by ResourceClass_s
| render barchart

//Count of all queued queries
AzureDiagnostics
| where Category contains "waits" 
| where Type_s == "UserConcurrencyResourceType"
| summarize totalQueuedQueries = dcount(RequestId_s)

//Longest Running Query Steps
AzureDiagnostics
| where Category == "RequestSteps"
| where OperationType_s in ("ShuffleMoveOperation", "BroadcastMoveOperation", "PartitionMoveOperation", "RoundRobinMoveOperation", "SingleSourceRoundRobinMoveOperation", "MoveOperation", "TrimMoveOperation")
| where Status_s == "Complete"
| project RequestId_s, OperationType_s, duration_ms=datetime_diff('millisecond',EndTime_t, StartTime_t), RowCount_d , TimeGenerated  
| order by duration_ms desc

//Request Steps
AzureDiagnostics
| where Category  == "RequestSteps"
| project TimeGenerated , ErrorId_g , OperationType_s , DistributionType_s , LocationType_s , StepIndex_d , RowCount_d , RequestId_s , Status_s , StartTime_t  , EndTime_t , Command_s 

//SQL Requests
AzureDiagnostics
| where Category  == "SqlRequests"
| project TimeGenerated , StepIndex_d , PdwNodeId_d , DistributionId_d , RowCount_d , Spid_d ,  RequestId_s , Status_s , StartTime_t , EndTime_t , Command_s 

//Blocked By Firewall
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="blocked_by_firewall"
| project MetricName , Maximum, TimeGenerated 

//Cache Hit Percent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="cache_hit_percent"
| project MetricName , Maximum, TimeGenerated 

//Connection Failed
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="connection_failed"
| project MetricName , Maximum, TimeGenerated  

//Connection Success
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="connection_successful"
| project MetricName , Maximum, TimeGenerated  

//CPU Percent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="cpu_percent"
| project MetricName , Maximum, TimeGenerated

//DWU Consumption Percent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="dwu_consumption_percent"

//Tempdb ConsumptionPercent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="local_tempdb_usage_percent"
| project MetricName , Maximum, TimeGenerated

//Memory Usage Percent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="memory_usage_percent"
| project MetricName , Maximum, TimeGenerated

//Physical Data Read Percent
AzureMetrics 
| where ResourceProvider  == "MICROSOFT.SQL"
| where Resource == "NICKSALCSQLDW1"
| where MetricName =="physical_data_read_percent"
| project MetricName , Maximum, TimeGenerated

//Current DWU
AzureMetrics | where MetricName == 'dwu_limit' 
| where Resource == 'NICKSALCSQLDW1'
| project TimeGenerated , MetricName , Maximum 
| sort by TimeGenerated  
| limit 1
| project MetricName , Maximum, TimeGenerated

================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/LongestBuildReplicatedTableCache
================================================
let databaseName = '<database_name>';
//Longest running BuildReplicatedTableCache
AzureDiagnostics
| where Category  == 'ExecRequests'
| where Resource  == databaseName
| where StatementType_s !in ('Batch','Execute')
| summarize Session_ID=max(SessionId_s),      Request_ID=max(RequestId_s),      Submit_Time=max(SubmitTime_t),      Start_Time=max(StartTime_t),      End_Time=max(EndTime_t),      Command=max(Command_s),       Statement_Type=max(StatementType_s),     Resource_class=max(ResourceClass_s)      by RequestId_s
| join kind= inner
(
    AzureDiagnostics
    | where Category  == 'ExecRequests'
    | where Resource  == databaseName
    //| where StatementType_s !in ('Batch','Execute')
    | where StatementType_s == 'BuildReplicatedTableCache'
    | where EndTime_t > ago(7d)
    | where StartTime_t > ago(7d)
    | extend elapsedTime = EndTime_t - StartTime_t
    | extend elapsedTime_min = elapsedTime/1m
    | order by elapsedTime_min desc
    | project Request_ID=RequestId_s,elapsedTime_min
)
on Request_ID
| order by elapsedTime_min desc
| project Session_ID,Request_ID,Submit_Time,Start_Time,End_Time,Elapsed_Time=elapsedTime_min,Command
| limit 10

/////////////////////////////////////////////////////////////////
// Uncomment these sections to investigate further             //
// To comment lines in bulk - select multiple lines and press  //
// Uncomment block: ctrl+k then ctrl+u                         //
// Comment block:   ctrl+k then ctrl+c                         //
/////////////////////////////////////////////////////////////////


// let databaseName = '<database_name>';
// //Get Query Text snippet
// AzureDiagnostics
// | where Category  == 'ExecRequests'
// | where Resource  == databaseName
// | where RequestId_s == 'QID117009708' //Put your QueryID here
// | order by TimeGenerated asc
// | project TimeGenerated,SubmitTime_t,EndCompileTime_t,StartTime_t,EndTime_t,StatementType_s,ResourceClass_s,SessionId_s,RequestId_s,RootQueryId_s,Command_s,Status_s


// let databaseName = '<database_name>';
// //View the query steps with rowcounts
// AzureDiagnostics
// | where Category  == 'RequestSteps'
// | where Resource  == databaseName
// | where RequestId_s == 'QID117009708' //Put your QueryID here
// | where Status_s != 'Running'
// | summarize max(StartTime_t),max(EndTime_t),max(RequestId_s),max(OperationType_s),max(RowCount_d),max(Command_s),max(Status_s) by StepIndex_d
// | order by StepIndex_d asc


================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/MostReplicatedTableRebuilds.txt
================================================
let databaseName = '<database_name>';
AzureDiagnostics
| where Category == 'ExecRequests'
| where Resource == databaseName
| where StatementType_s == 'BuildReplicatedTableCache'
| where Command_s != ""
| where ResourceClass_s != ""
| project Command_s, TimeGenerated, RequestId_s
| summarize LastRebuild=max(TimeGenerated), RebuildCount_7Days=count(RequestId_s), AvgRebuildsPerDay=count(RequestId_s) / 7 by Command_s
| order by RebuildCount_7Days desc
| limit 20



================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/QueriesByExecutionTime.kql
================================================
//Queries by Execution Time
let databaseName = '<databaseName_ALL_CAPS>';
AzureDiagnostics 
| where Category  == 'ExecRequests'
| where Resource  == databaseName
| where StatementType_s !in ('Batch','Execute')
| summarize Session_ID=max(SessionId_s), 
    Request_ID=max(RequestId_s), 
    Submit_Time=min(SubmitTime_t), 
    Start_Time=max(StartTime_t), 
    End_Time=max(EndTime_t), 
    Command=max(Command_s), 
    Last_Status=min(Status_s),
    Statement_Type=max(StatementType_s),
    Resource_class=max(ResourceClass_s) 
    by RequestId_s
| extend elapsedTime_min = (End_Time - Submit_Time)/1m
//| where Command contains "<query text snippet" //Uncomment to search by query text
| order by elapsedTime_min
//| limit 50



================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/RepTableBuildCacheExecutionCount
================================================
let databaseName = '<database_name>';
//Build cache count by day
AzureDiagnostics
| where Category  == 'ExecRequests'
| where Resource  == databaseName 
| where StatementType_s == 'BuildReplicatedTableCache'
| where Command_s != ""
| where ResourceClass_s != ""
| project Command_s,TimeGenerated,RequestId_s
| summarize LastRebuild=max(TimeGenerated),RebuildCount_7Days=count(RequestId_s), AvgRebuildsPerDay=count(RequestId_s)/7 by Command_s
| order by RebuildCount_7Days desc
| limit 20

================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/RowsProcessedPerHour
================================================
let databaseName = '<database_name>';
//rows processed per hour
AzureDiagnostics
| where Category  == 'RequestSteps'
| where Resource  == databaseName
| where RowCount_d > 0
| summarize Rows_Processed=sum(RowCount_d) by bin(TimeGenerated, 1hr)
| limit 50


================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/SingletonInserts.kql
================================================
//This query identifies Sessions with large numbers of insert statements, including the max rows inserted. It is mainly used to identify singleton or small inserts. 
let databaseName="<databaseNameAllCaps>";
AzureDiagnostics
| where Resource == databaseName
| where Category == 'ExecRequests'
| where StatementType_s in ('InsertIntoValues')
| summarize SessionId_s=max(SessionId_s),max(StatementType_s),max(SessionId_s),min(Status_s),max(Command_s) by RequestId_s
| join (AzureDiagnostics
    | where Resource == databaseName
    | where Category == 'RequestSteps' 
    | summarize max(RowCount_d) by RequestId_s
) on RequestId_s
| join (AzureDiagnostics
    | where Resource == databaseName
    | where Category == 'ExecRequests'
    | where StatementType_s in ('InsertIntoValues')
    | summarize count() by SessionId_s
) on SessionId_s
| order by count_
| project SessionId=SessionId_s,RequestId=RequestId_s,StatementType=max_StatementType_s,StatementsFound=count_,MaxRowcount=max_RowCount_d,Status=min_Status_s,Command=max_Command_s
| limit 100

================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/TempTablesNotCreatedAsHeap.kql
================================================
let databaseName = 'DatabaseName_AllCaps';
//Long-Running Queries - Just Actual Queries
//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window
AzureDiagnostics
| where Category  == 'ExecRequests'
| where Resource  == databaseName
| where StatementType_s !in ('Batch','Execute')
| where tolower(Command_s) contains "create table #"
 and tolower(Command_s) !contains "HEAP"
 | summarize Session_ID=any(SessionId_s),
    Request_ID=any(RequestId_s),
    Submit_Time=max(SubmitTime_t),
    Start_Time=max(StartTime_t),
    End_Time=max(EndTime_t),
    Command=any(Command_s),
    Status=min(Status_s), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status
    Statement_Type=any(StatementType_s),
    Resource_class=any(ResourceClass_s)
    by RequestId_s
| summarize ElapsedTime_min=anyif((End_Time - Start_Time)/1m,Start_Time > ago(30d)),Session_ID=any(Session_ID), Submit_Time=any(Submit_Time) ,Start_Time=any(Start_Time), End_Time=any(End_Time),Command=any(Command),Status=any(Status),Statement_Type=any(Statement_Type),Resource_class=any(Resource_class) by Request_ID
| order by ElapsedTime_min desc

================================================
FILE: Log_Analytics_queries/StandaloneSQLPool/UnionVsUnionAll.kql
================================================
let databaseName = '<databaseNameAllCaps>';
//Usage of Union vs Union ALL - this query is approximate since query text is limited to 4000 characters
AzureDiagnostics 
| where Category  == 'ExecRequests'
| where Resource  == databaseName
| where StatementType_s !in ('Batch','Execute')
| summarize Session_Id=max(SessionId_s), 
    Request_Id=max(RequestId_s), 
    Submit_Time=max(SubmitTime_t), 
    Start_Time=max(StartTime_t), 
    End_Time=max(EndTime_t), 
    Command=max(Command_s), 
    Status=min(Status_s),
    Statement_Type=max(StatementType_s),
    Resource_class=max(ResourceClass_s) 
    by RequestId_s
| extend elapsedTime_min = (End_Time - Submit_Time)/1m
| where Command has 'Union' and Command !has 'union all'
| order by elapsedTime_min
| project Session_Id,Request_Id,Submit_Time,Start_Time,End_Time,elapsedTime_min,Command,Status,Statement_Type,Resource_class
| limit 50

================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/FindLargeBroadcasts.kql
================================================
let databaseName="<database_name>";
SynapseSqlPoolRequestSteps
| where _ResourceId endswith databaseName
| where OperationType == 'BroadcastMoveOperation'
| summarize rowcount=max(RowCount),max(TimeGenerated),max(OperationType) by RequestId,StepIndex
| order by rowcount



================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/IdentifySingletonInserts.kql
================================================
//This query identifies Sessions with large numbers of insert statements, including the max rows inserted. It is mainly used to identify singleton or small inserts. 
let databaseName="<Database_name>";
SynapseSqlPoolExecRequests
| where _ResourceId endswith databaseName
| where StatementType in ('InsertIntoValues')
| summarize max(StatementType),min(Status),max(Command) by RequestId
| join (SynapseSqlPoolRequestSteps
    | where _ResourceId endswith databaseName
    | summarize max(RowCount) by RequestId
    | where max_RowCount == 1
) on RequestId
| limit 100



================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/LongestRunningQueriesByExecutionTime.kql
================================================
//Long-Running Queries
let databaseName = '1';
SynapseSqlPoolExecRequests
| where _ResourceId  endswith databaseName
| where StatementType !in ('Batch','Execute')
| summarize 
    Request_ID=any(RequestId),
    Submit_Time=min(TimeGenerated),
    Start_Time=max(StartTime),
    End_Time=max(EndTime),
    Command=any(Command),
    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status
    Statement_Type=any(StatementType),
    Resource_class=any(ResourceClass)
    by RequestId
| summarize ElapsedTime_min=anyif((End_Time - Start_Time)/1m,Start_Time > ago(30d)),Submit_Time=any(Submit_Time) ,Start_Time=any(Start_Time), End_Time=any(End_Time),Command=any(Command),Status=any(Status),Statement_Type=any(Statement_Type),Resource_class=any(Resource_class) by Request_ID
| order by ElapsedTime_min desc
| limit 20

//paste the request ID into teh 'query investigation' tab of the monitoring workbook if you want to investigate a query further



================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/QueriesWithResourceGrant.kql
================================================
//Queries including SLO and resource grant % until the resource grant % field is avaialble in log analytics covers DW500-DW6000
let snapshotTelemetryInterval = 1s;//1h;//30m;//Do not change
SynapseSqlPoolExecRequests 
| where StatementType !in ('Batch','Execute')
| where ResourceClass != ''
| summarize //Session_ID=any(SessionId),
    Request_ID=any(RequestId),
    //Submit_Time=max(SubmitTime),
    Start_Time=max(StartTime),
    End_Time=max(EndTime),
    Command=take_any(Command),
    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status
    Statement_Type=any(StatementType),
    Resource_Class=max(ResourceClass),
Context=max(ClientCorrelationId),
MinTimeGenerated=min(TimeGenerated),
MaxTimeGenerated=max(TimeGenerated),
   TimeGenerated=max(TimeGenerated),
   ExplainOutput=max(ExplainOutput)
   by RequestId
| extend NumberNodes=split(split(ExplainOutput,"number_nodes=")[1],"'")[1] //parse out how many nodes are used in dsql plan
| extend SLO = (NumberNodes* 500)
| extend Resource_Grant = todecimal(
    case(SLO==500,
        case(Resource_Class == 'smallrc', 5.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 4.8,
            Resource_Class == 'staticrc20', 9.6,
            Resource_Class == 'staticrc30', 19.2,
            Resource_Class == 'staticrc40', 38.4,
            Resource_Class == 'staticrc50', 76.8,
            Resource_Class == 'staticrc60', 100.0,
            Resource_Class == 'staticrc70', 100.0,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 5.0,
            0.0)
        ,SLO==1000,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 2.4,
            Resource_Class == 'staticrc20', 4.8,
            Resource_Class == 'staticrc30', 9.6,
            Resource_Class == 'staticrc40', 19.2,
            Resource_Class == 'staticrc50', 38.4,
            Resource_Class == 'staticrc60', 76.8,
            Resource_Class == 'staticrc70', 100.0,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==1500,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 1.6,
            Resource_Class == 'staticrc20', 3.2,
            Resource_Class == 'staticrc30', 6.4,
            Resource_Class == 'staticrc40', 12.8,
            Resource_Class == 'staticrc50', 25.6,
            Resource_Class == 'staticrc60', 51.2,
            Resource_Class == 'staticrc70', 100.0,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==2000,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 1.2,
            Resource_Class == 'staticrc20', 2.4,
            Resource_Class == 'staticrc30', 4.8,
            Resource_Class == 'staticrc40', 9.6,
            Resource_Class == 'staticrc50', 19.2,
            Resource_Class == 'staticrc60', 38.4,
            Resource_Class == 'staticrc70', 76.8,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==2500,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 0.96,
            Resource_Class == 'staticrc20', 1.92,
            Resource_Class == 'staticrc30', 3.84,
            Resource_Class == 'staticrc40', 7.68,
            Resource_Class == 'staticrc50', 16.36,
            Resource_Class == 'staticrc60', 30.72,
            Resource_Class == 'staticrc70', 61.44,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==3000,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 0.8,
            Resource_Class == 'staticrc20', 1.6,
            Resource_Class == 'staticrc30', 3.2,
            Resource_Class == 'staticrc40', 6.4,
            Resource_Class == 'staticrc50', 12.8,
            Resource_Class == 'staticrc60', 25.6,
            Resource_Class == 'staticrc70', 51.2,
            Resource_Class == 'staticrc80', 100.0,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==5000,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 0.48,
            Resource_Class == 'staticrc20', 0.96,
            Resource_Class == 'staticrc30', 1.92,
            Resource_Class == 'staticrc40', 3.84,
            Resource_Class == 'staticrc50', 7.68,
            Resource_Class == 'staticrc60', 15.36,
            Resource_Class == 'staticrc70', 30.72,
            Resource_Class == 'staticrc80', 61.44,
            Resource_Class == 'default', 3.0,
            0.0)
        ,SLO==6000,
            case(Resource_Class == 'smallrc', 3.0,
            Resource_Class == 'mediumrc', 10.0,
            Resource_Class == 'largerc', 22.0,
            Resource_Class == 'xlargerc', 70.0,
            Resource_Class == 'staticrc10', 0.4,
            Resource_Class == 'staticrc20', 0.8,
            Resource_Class == 'staticrc30', 1.6,
            Resource_Class == 'staticrc40', 3.2,
            Resource_Class == 'staticrc50', 6.4,
            Resource_Class == 'staticrc60', 12.8,
            Resource_Class == 'staticrc70', 25.6,
            Resource_Class == 'staticrc80', 51.2,
            Resource_Class == 'default', 3.0,
            0.0)
        ,0.0)
        ) //if no match

================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/QueryList_withResultSetCacheData.kql
================================================
//Query List with ResultSetCache data
let databaseName = 'syntheticworkload';
SynapseSqlPoolExecRequests
| where _ResourceId  endswith databaseName
| where StatementType !in ('Batch','Execute')
| summarize 
    Request_ID=any(RequestId),
    Submit_Time=min(TimeGenerated),
    Start_Time=max(StartTime),
    End_Time=max(EndTime),
    Command=any(Command),
    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status
    Statement_Type=any(StatementType),
    Resource_class=any(ResourceClass),
    ResultCacheHit=min(ResultCacheHit)
    by RequestId
| summarize ResultCacheHit=min(ResultCacheHit),ElapsedTime_min=anyif((End_Time - Start_Time)/1m,Start_Time > ago(30d)),Submit_Time=any(Submit_Time) ,Start_Time=any(Start_Time), End_Time=any(End_Time),Command=any(Command),Status=any(Status),Statement_Type=any(Statement_Type),Resource_class=any(Resource_class) by Request_ID
| order by ElapsedTime_min desc

================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/TempTableASHeap.kql
================================================
let databaseName = '<database_name>';
//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window
SynapseSqlPoolExecRequests
| where _ResourceId  endswith databaseName
| where StatementType !in ('Batch','Execute')
| where tolower(Command) contains "create table #" and tolower(Command) !has 'heap'
 | summarize 
    Request_ID=any(RequestId),
    Submit_Time=min(TimeGenerated),
    Start_Time=max(StartTime),
    End_Time=max(EndTime),
    Command=any(Command),
    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status
    Statement_Type=any(StatementType),
    Resource_class=any(ResourceClass)
    by RequestId
| summarize 
    ElapsedTime_min=anyif((End_Time - Start_Time)/1m,Start_Time > ago(30d))
    , Submit_Time=any(Submit_Time) 
    ,Start_Time=any(Start_Time)
    , End_Time=any(End_Time)
    ,Command=any(Command)
    ,Status=any(Status)
    ,Statement_Type=any(Statement_Type)
    ,Resource_class=any(Resource_class) 
    by Request_ID
| order by ElapsedTime_min desc

================================================
FILE: Log_Analytics_queries/WorkspacesSQLPool/UnionVsUnionAll.kql
================================================
//Usage of Union vs Union ALL
let databaseName = '<database_name>';
SynapseSqlPoolExecRequests
| where _ResourceId  endswith databaseName
| where StatementType !in ('Batch','Execute')
| summarize 
    Request_Id=max(RequestId), 
    Submit_Time=min(TimeGenerated), 
    Start_Time=max(StartTime), 
    End_Time=max(EndTime), 
    Command=max(Command), 
    Status=min(Status),
    Statement_Type=max(StatementType),
    Resource_class=max(ResourceClass) 
    by RequestId
| extend elapsedTime_min = (End_Time - Submit_Time)/1m
| where Command has 'Union' and Command !has 'union all'
| order by elapsedTime_min
| project Request_Id,Submit_Time,Start_Time,End_Time,elapsedTime_min,Command,Status,Statement_Type,Resource_class
| limit 50


================================================
FILE: Monitor_Workbooks/DW_Summary_v1.1.workbook
================================================
{
  "version": "Notebook/1.0",
  "items": [
    {
      "type": 9,
      "content": {
        "version": "KqlParameterItem/1.0",
        "crossComponentResources": [
          "{Subscriptions}"
        ],
        "parameters": [
          {
            "id": "15a2c4b1-1223-428f-80a0-53ec8e8e86a5",
            "version": "KqlParameterItem/1.0",
            "name": "TimeRange",
            "type": 4,
            "isRequired": true,
            "value": {
              "durationMs": 604800000
            },
            "typeSettings": {
              "selectableValues": [
                {
                  "durationMs": 300000
                },
                {
                  "durationMs": 900000
                },
                {
                  "durationMs": 1800000
                },
                {
                  "durationMs": 3600000
                },
                {
                  "durationMs": 14400000
                },
                {
                  "durationMs": 43200000
                },
                {
                  "durationMs": 86400000
                },
                {
                  "durationMs": 172800000
                },
                {
                  "durationMs": 259200000
                },
                {
                  "durationMs": 604800000
                },
                {
                  "durationMs": 1209600000
                },
                {
                  "durationMs": 2419200000
                },
                {
                  "durationMs": 2592000000
                },
                {
                  "durationMs": 5184000000
                },
                {
                  "durationMs": 7776000000
                }
              ],
              "allowCustom": true
            }
          },
          {
            "id": "bc3b3200-d39a-4d72-adc3-8473457d9b30",
            "version": "KqlParameterItem/1.0",
            "name": "Subscriptions",
            "type": 6,
            "isRequired": true,
            "multiSelect": true,
            "quote": "'",
            "delimiter": ",",
            "value": [
              "value::all"
            ],
            "typeSettings": {
              "additionalResourceOptions": [
                "value::1",
                "value::all"
              ],
              "includeAll": false
            }
          }
        ],
        "style": "pills",
        "queryType": 1,
        "resourceType": "microsoft.resourcegraph/resources"
      },
      "name": "parameters - 1"
    },
    {
      "type": 11,
      "content": {
        "version": "LinkItem/1.0",
        "style": "tabs",
        "links": [
          {
            "id": "d29d564f-9326-433b-8b87-678461724323",
            "cellValue": "objectType",
            "linkTarget": "parameter",
            "linkLabel": "Dedicated Pools",
            "subTarget": "dedicated",
            "style": "link"
          }
        ]
      },
      "name": "links - 6"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 11,
            "content": {
              "version": "LinkItem/1.0",
              "style": "tabs",
              "links": [
                {
                  "id": "933d2413-fcd3-4a62-827d-de0aeefd2632",
                  "cellValue": "selectedTab",
                  "linkTarget": "parameter",
                  "linkLabel": "Synapse Dedicated Pools",
                  "subTarget": "synapseDP",
                  "preText": "selec",
                  "style": "link"
                },
                {
                  "id": "e821e971-adcf-4c8b-8cf8-47bf91576670",
                  "cellValue": "selectedTab",
                  "linkTarget": "parameter",
                  "linkLabel": "Standalone Dedicated Pools",
                  "subTarget": "standaloneDP",
                  "style": "link"
                }
              ]
            },
            "name": "links - 3"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "crossComponentResources": [
                "{Subscriptions}"
              ],
              "parameters": [
                {
                  "id": "8998a008-ea1b-4f4b-bcc2-44e15deba715",
                  "version": "KqlParameterItem/1.0",
                  "name": "SQLDWDBs",
                  "label": "Standalone Pools",
                  "type": 5,
                  "isRequired": true,
                  "multiSelect": true,
                  "quote": "'",
                  "delimiter": ",",
                  "query": "resources \r\n| where type =~ 'microsoft.sql/servers/databases'\r\n| where sku has \"DataWarehouse\"\r\n| where resourceGroup !startswith \"synapseworkspace-managedrg-\" \r\n| where resourceGroup !startswith \"workspacemanagedrg-\"\r\n| project id",
                  "crossComponentResources": [
                    "{Subscriptions}"
                  ],
                  "typeSettings": {
                    "additionalResourceOptions": [
                      "value::1",
                      "value::10",
                      "value::all"
                    ],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "defaultValue": "value::all",
                  "queryType": 1,
                  "resourceType": "microsoft.resourcegraph/resources",
                  "value": [
                    "value::all"
                  ]
                }
              ],
              "style": "pills",
              "queryType": 1,
              "resourceType": "microsoft.resourcegraph/resources"
            },
            "conditionalVisibility": {
              "parameterName": "selectedTab",
              "comparison": "isEqualTo",
              "value": "standaloneDP"
            },
            "name": "Parameters - SQL DW"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "crossComponentResources": [
                "{Subscriptions}"
              ],
              "parameters": [
                {
                  "id": "b8eda6e3-e18a-47bc-9d3f-8df41a29a95c",
                  "version": "KqlParameterItem/1.0",
                  "name": "SynapseDedicatedPools",
                  "type": 5,
                  "multiSelect": true,
                  "quote": "'",
                  "delimiter": ",",
                  "query": "resources\r\n| where type == \"microsoft.synapse/workspaces/sqlpools\"\r\n| project id",
                  "crossComponentResources": [
                    "{Subscriptions}"
                  ],
                  "typeSettings": {
                    "additionalResourceOptions": [
                      "value::10",
                      "value::all"
                    ],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "defaultValue": "value::all",
                  "queryType": 1,
                  "resourceType": "microsoft.resourcegraph/resources",
                  "value": [
                    "value::all"
                  ]
                }
              ],
              "style": "pills",
              "queryType": 1,
              "resourceType": "microsoft.resourcegraph/resources"
            },
            "conditionalVisibility": {
              "parameterName": "selectedTab",
              "comparison": "isEqualTo",
              "value": "synapseDP"
            },
            "name": "Parameters - SQL DW - Copy"
          },
          {
            "type": 12,
            "content": {
              "version": "NotebookGroup/1.0",
              "groupType": "editable",
              "items": [
                {
                  "type": 10,
                  "content": {
                    "chartId": "workbookf1358ff0-0e10-4ac2-ab2d-2fdfdb74dc2f",
                    "version": "MetricsItem/2.0",
                    "size": 2,
                    "chartType": 0,
                    "resourceType": "microsoft.synapse/workspaces/sqlpools",
                    "metricScope": 0,
                    "resourceParameter": "SynapseDedicatedPools",
                    "resourceIds": [
                      "{SynapseDedicatedPools}"
                    ],
                    "timeContextFromParameter": "TimeRange",
                    "timeContext": {
                      "durationMs": 604800000
                    },
                    "metrics": [
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWULimit",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries",
                        "aggregation": 1
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries",
                        "aggregation": 1
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.synapse/workspaces/sqlpools",
                        "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent",
                        "aggregation": 3
                      }
                    ],
                    "gridSettings": {
                      "formatters": [
                        {
                          "columnMatch": "$gen_group",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Group",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Subscription",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Name",
                          "formatter": 5,
                          "formatOptions": {
                            "linkTarget": "Resource"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWULimit",
                          "formatter": 8,
                          "formatOptions": {
                            "palette": "magenta"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWULimit Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent Timeline",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "blue"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent Timeline",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "yellow"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries",
                          "formatter": 1,
                          "numberFormat": {
                            "unit": 0,
                            "options": null
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries",
                          "formatter": 1,
                          "numberFormat": {
                            "unit": 0,
                            "options": null
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 50,
                            "max": 100,
                            "palette": "redGreen"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          }
                        },
                        {
                          "columnMatch": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent Timeline",
                          "formatter": 5
                        }
                      ],
                      "rowLimit": 10000,
                      "filter": true,
                      "hierarchySettings": {
                        "treeType": 1,
                        "groupBy": [
                          "Subscription"
                        ],
                        "expandTopLevel": true,
                        "finalBy": "Name"
                      },
                      "labelSettings": [
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWULimit",
                          "label": "DWU"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWULimit Timeline",
                          "label": "DWU limit Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent",
                          "label": "DWU (Max)"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent Timeline",
                          "label": "DWU Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent",
                          "label": "CPU (Max)"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent Timeline",
                          "label": "CPU used percentage Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent",
                          "label": "Tempdb (Max)"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent Timeline",
                          "label": "Tempdb Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries",
                          "label": "Total Queries"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries Timeline",
                          "label": "Query Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries",
                          "label": "Total Queued"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries Timeline",
                          "label": "Queued queries Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent",
                          "label": "Cache hit percentage (Max)"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent Timeline",
                          "label": "Adaptive cache hit percentage Timeline"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent",
                          "label": "Cache used percentage (Max)"
                        },
                        {
                          "columnId": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent Timeline",
                          "label": "Adaptive cache used percentage Timeline"
                        }
                      ]
                    },
                    "sortBy": []
                  },
                  "showPin": true,
                  "name": "Metrics - SQL DW DTU/CPU"
                }
              ]
            },
            "conditionalVisibility": {
              "parameterName": "selectedTab",
              "comparison": "isEqualTo",
              "value": "synapseDP"
            },
            "name": "SynapseGroup"
          },
          {
            "type": 12,
            "content": {
              "version": "NotebookGroup/1.0",
              "groupType": "editable",
              "items": [
                {
                  "type": 10,
                  "content": {
                    "chartId": "workbookf1358ff0-0e10-4ac2-ab2d-2fdfdb74dc2f",
                    "version": "MetricsItem/2.0",
                    "size": 2,
                    "chartType": 0,
                    "resourceType": "microsoft.sql/servers/databases",
                    "metricScope": 0,
                    "resourceParameter": "SQLDWDBs",
                    "resourceIds": [
                      "{SQLDWDBs}"
                    ],
                    "timeContextFromParameter": "TimeRange",
                    "timeContext": {
                      "durationMs": 604800000
                    },
                    "metrics": [
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-dwu_limit",
                        "aggregation": 3,
                        "columnName": "DWU"
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-dwu_consumption_percent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-cpu_percent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-physical_data_read_percent",
                        "aggregation": 3
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-local_tempdb_usage_percent",
                        "aggregation": 3,
                        "columnName": "TempDB Usage"
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-active_queries",
                        "aggregation": 1
                      },
                      {
                        "namespace": "microsoft.sql/servers/databases",
                        "metric": "microsoft.sql/servers/databases-Basic-queued_queries",
                        "aggregation": 1
                      }
                    ],
                    "gridSettings": {
                      "formatters": [
                        {
                          "columnMatch": "$gen_group",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Group",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Subscription",
                          "formatter": 13,
                          "formatOptions": {
                            "linkTarget": "Resource",
                            "showIcon": true
                          }
                        },
                        {
                          "columnMatch": "Name",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "DWU",
                          "formatter": 8,
                          "formatOptions": {
                            "palette": "magenta"
                          }
                        },
                        {
                          "columnMatch": "DWU Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-dwu_consumption_percent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          },
                          "numberFormat": {
                            "unit": 1,
                            "options": {
                              "style": "decimal",
                              "useGrouping": false
                            }
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-dwu_consumption_percent Timeline",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "blue"
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-cpu_percent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          },
                          "numberFormat": {
                            "unit": 1,
                            "options": {
                              "style": "decimal"
                            }
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-cpu_percent Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-physical_data_read_percent",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          },
                          "numberFormat": {
                            "unit": 1,
                            "options": {
                              "style": "decimal"
                            }
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-physical_data_read_percent Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "TempDB Usage",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 100,
                            "palette": "greenRed"
                          }
                        },
                        {
                          "columnMatch": "TempDB Usage Timeline",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "red"
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-active_queries",
                          "formatter": 1,
                          "numberFormat": {
                            "unit": 0,
                            "options": null
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-active_queries Timeline",
                          "formatter": 5
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-queued_queries",
                          "formatter": 8,
                          "formatOptions": {
                            "min": 0,
                            "max": 1024,
                            "palette": "yellowOrangeRed"
                          },
                          "numberFormat": {
                            "unit": 0,
                            "options": {
                              "style": "decimal"
                            }
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-queued_queries Timeline",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "yellow"
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-local_tempdb_usage_percent",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "blue"
                          },
                          "numberFormat": {
                            "unit": 1,
                            "options": {
                              "style": "decimal"
                            }
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-local_tempdb_usage_percent Timeline",
                          "formatter": 8,
                          "formatOptions": {
                            "palette": "blue"
                          }
                        },
                        {
                          "columnMatch": "microsoft.sql/servers/databases-Basic-dwu_limit",
                          "formatter": 21,
                          "formatOptions": {
                            "palette": "yellow"
                          },
                          "numberFormat": {
                            "unit": 0,
                            "options": {
                              "style": "decimal"
                            }
                          }
                        }
                      ],
                      "rowLimit": 10000,
                      "filter": true,
                      "hierarchySettings": {
                        "treeType": 1,
                        "groupBy": [
                          "Subscription"
                        ],
                        "expandTopLevel": true,
                        "finalBy": "Name"
                      },
                      "sortBy": [
                        {
                          "itemKey": "$gen_heatmap_DWU_3",
                          "sortOrder": 2
                        }
                      ],
                      "labelSettings": [
                        {
                          "columnId": "DWU",
                          "label": "DWU"
                        },
                        {
                          "columnId": "DWU Timeline",
                          "label": "DWU Timeline"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-dwu_consumption_percent",
                          "label": "DWU (Max)"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-dwu_consumption_percent Timeline",
                          "label": "DWU percentage Timeline"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-cpu_percent",
                          "label": "CPU (Max)"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-cpu_percent Timeline",
                          "label": "CPU percentage Timeline"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-physical_data_read_percent",
                          "label": "Data IO (Max)"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-physical_data_read_percent Timeline",
                          "label": "Data IO percentage Timeline"
                        },
                        {
                          "columnId": "TempDB Usage",
                          "label": "TempDB (Max)"
                        },
                        {
                          "columnId": "TempDB Usage Timeline",
                          "label": "TempDB Usage Timeline"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-active_queries",
                          "label": "Total Queries"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-active_queries Timeline",
                          "label": "Active queries (Sum) Timeline"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-queued_queries",
                          "label": "Total Queued Queries"
                        },
                        {
                          "columnId": "microsoft.sql/servers/databases-Basic-queued_queries Timeline",
                          "label": "Queued queries Timeline"
                        }
                      ]
                    },
                    "sortBy": [
                      {
                        "itemKey": "$gen_heatmap_DWU_3",
                        "sortOrder": 2
                      }
                    ],
                    "showExportToExcel": true
                  },
                  "showPin": true,
                  "name": "Metrics - SQL DW DTU/CPU"
                }
              ]
            },
            "conditionalVisibility": {
              "parameterName": "selectedTab",
              "comparison": "isEqualTo",
              "value": "standaloneDP"
            },
            "name": "standaloneGroup"
          }
        ]
      },
      "conditionalVisibility": {
        "parameterName": "objectType",
        "comparison": "isEqualTo",
        "value": "dedicated"
      },
      "name": "Dedicated Pool Group"
    }
  ],
  "fallbackResourceIds": [
    "Azure Monitor"
  ],
  "$schema": "https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"
}

================================================
FILE: Monitor_Workbooks/DedicatedSQLPool_workspace_v1.2.workbook
================================================
{
  "version": "Notebook/1.0",
  "items": [
    {
      "type": 9,
      "content": {
        "version": "KqlParameterItem/1.0",
        "crossComponentResources": [
          "{LogAnalyticsWorkspace}"
        ],
        "parameters": [
          {
            "id": "f5852627-70ca-4959-8d60-53b48864603f",
            "version": "KqlParameterItem/1.0",
            "name": "TimeRange",
            "type": 4,
            "isGlobal": true,
            "value": {
              "durationMs": 43200000
            },
            "typeSettings": {
              "selectableValues": [
                {
                  "durationMs": 300000
                },
                {
                  "durationMs": 900000
                },
                {
                  "durationMs": 1800000
                },
                {
                  "durationMs": 3600000
                },
                {
                  "durationMs": 14400000
                },
                {
                  "durationMs": 43200000
                },
                {
                  "durationMs": 86400000
                },
                {
                  "durationMs": 172800000
                },
                {
                  "durationMs": 259200000
                },
                {
                  "durationMs": 604800000
                },
                {
                  "durationMs": 1209600000
                },
                {
                  "durationMs": 2419200000
                },
                {
                  "durationMs": 2592000000
                }
              ],
              "allowCustom": true
            },
            "timeContext": {
              "durationMs": 86400000
            }
          },
          {
            "id": "28da10ec-a308-47f5-9819-92ebf810b292",
            "version": "KqlParameterItem/1.0",
            "name": "LogAnalyticsSubscription",
            "type": 6,
            "value": null,
            "typeSettings": {
              "additionalResourceOptions": [],
              "includeAll": true,
              "showDefault": false
            },
            "timeContext": {
              "durationMs": 86400000
            }
          },
          {
            "id": "e383ed24-52ae-447b-9b80-51fd3ab6b919",
            "version": "KqlParameterItem/1.0",
            "name": "LogAnalyticsWorkspace",
            "type": 5,
            "query": "Resources\r\n| where type == 'microsoft.operationalinsights/workspaces'\r\n| project id\r\n",
            "crossComponentResources": [
              "{LogAnalyticsSubscription}"
            ],
            "value": null,
            "typeSettings": {
              "additionalResourceOptions": [],
              "showDefault": false
            },
            "timeContext": {
              "durationMs": 86400000
            },
            "queryType": 1,
            "resourceType": "microsoft.resourcegraph/resources"
          },
          {
            "id": "9b9fe566-0f52-4a75-a35b-a79c50c6a6f0",
            "version": "KqlParameterItem/1.0",
            "name": "DatabaseResourceName",
            "type": 5,
            "query": "SynapseSqlPoolExecRequests \r\n| distinct _ResourceId",
            "crossComponentResources": [
              "{LogAnalyticsWorkspace}"
            ],
            "value": null,
            "typeSettings": {
              "additionalResourceOptions": [],
              "showDefault": false
            },
            "timeContext": {
              "durationMs": 2592000000
            },
            "queryType": 0,
            "resourceType": "microsoft.operationalinsights/workspaces"
          },
          {
            "id": "6da2f63f-45a3-4b37-9108-5e8b7e358d85",
            "version": "KqlParameterItem/1.0",
            "name": "DatabaseName",
            "type": 1,
            "query": "print split (\"{DatabaseResourceName}\",\"/\")[-1]",
            "crossComponentResources": [
              "{LogAnalyticsWorkspace}"
            ],
            "isHiddenWhenLocked": true,
            "timeContext": {
              "durationMs": 0
            },
            "timeContextFromParameter": "TimeRange",
            "queryType": 0,
            "resourceType": "microsoft.operationalinsights/workspaces"
          },
          {
            "id": "8bba835b-f319-43b3-8ec6-4e051fc6d446",
            "version": "KqlParameterItem/1.0",
            "name": "LogicalServerName",
            "type": 1,
            "query": "SynapseSqlPoolExecRequests\r\n| where _ResourceId == '{DatabaseResourceName}'\r\n| distinct LogicalServerName",
            "crossComponentResources": [
              "{LogAnalyticsWorkspace}"
            ],
            "isHiddenWhenLocked": true,
            "timeContext": {
              "durationMs": 0
            },
            "timeContextFromParameter": "TimeRange",
            "queryType": 0,
            "resourceType": "microsoft.operationalinsights/workspaces"
          },
          {
            "id": "b86cd4a2-2303-4288-b48c-1c119cb420ba",
            "version": "KqlParameterItem/1.0",
            "name": "AuditingState",
            "type": 1,
            "query": "let hasNonEmptyTable = (T:string) \r\n{ \r\n   toscalar( \r\n   union isfuzzy=true \r\n   ( table(T) \r\n   | where DatabaseName has '{DatabaseName}'\r\n   | where TimeGenerated > ago(30d)| take 1 | count as Count ),\r\n   (print Count=0) \r\n   | summarize sum(Count) \r\n   ) > 0\r\n};\r\nlet TableName = 'SQLSecurityAuditEvents';\r\nprint  IsPresent=iif(hasNonEmptyTable(TableName ), \"enabled\", \"disabled\")",
            "crossComponentResources": [
              "{LogAnalyticsWorkspace}"
            ],
            "isHiddenWhenLocked": true,
            "timeContext": {
              "durationMs": 604800000
            },
            "queryType": 0,
            "resourceType": "microsoft.operationalinsights/workspaces"
          },
          {
            "id": "4025bcb8-f6d7-4e81-b805-84253835f8fb",
            "version": "KqlParameterItem/1.0",
            "name": "DiagnosticsState",
            "type": 1,
            "query": "let hasNonEmptyTable = (T:string, T2:string) \r\n{ \r\n   toscalar( \r\n   union isfuzzy=true \r\n   ( table(T) | where TimeGenerated > ago(30d) | where _ResourceId endswith '/sqlpools/{DatabaseName}'| take 1 | count as Count ),\r\n   ( table(T2) | where TimeGenerated > ago(30d) | where _ResourceId endswith '/sqlpools/{DatabaseName}'| take 1 | count as Count),\r\n   (print Count=0) \r\n   | summarize sum(Count) \r\n   ) > 1\r\n};\r\nlet TableName = 'SynapseSqlPoolExecRequests';\r\nlet TableName2 = 'SynapseSqlPoolRequestSteps';\r\nprint  IsPresent=iif(hasNonEmptyTable(TableName,TableName2 ), \"enabled\", \"disabled\")",
            "crossComponentResources": [
              "{LogAnalyticsWorkspace}"
            ],
            "isHiddenWhenLocked": true,
            "timeContext": {
              "durationMs": 2592000000
            },
            "queryType": 0,
            "resourceType": "microsoft.operationalinsights/workspaces"
          }
        ],
        "style": "pills",
        "queryType": 0,
        "resourceType": "microsoft.operationalinsights/workspaces"
      },
      "customWidth": "90",
      "name": "parameters - 2"
    },
    {
      "type": 1,
      "content": {
        "json": "Select your Log Analytics Workspace by setting the parameters above from left to right. ",
        "style": "warning"
      },
      "conditionalVisibility": {
        "parameterName": "DatabaseResourceName",
        "comparison": "isEqualTo"
      },
      "customWidth": "30",
      "name": "text - 14"
    },
    {
      "type": 11,
      "content": {
        "version": "LinkItem/1.0",
        "style": "tabs",
        "links": [
          {
            "id": "202cbbc0-8d63-416d-89ed-451d6fe7c4b3",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Overview",
            "subTarget": "Overview",
            "preText": "Workload",
            "style": "link"
          },
          {
            "id": "a7901bd0-a1f4-4491-b953-57555d764e00",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Workload Management",
            "subTarget": "WorkloadManagement",
            "style": "link"
          },
          {
            "id": "45e12a14-8548-4477-aae3-c142b906dc9f",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "TempDB",
            "subTarget": "TempDB",
            "style": "link"
          },
          {
            "id": "9ef8f730-d73d-432b-9b75-55095d1155f2",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Replicated Tables",
            "subTarget": "ReplicatedTables",
            "style": "link"
          },
          {
            "id": "79d10d16-0696-4214-b306-c7a0e46cd64f",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Query Investigation",
            "subTarget": "QueryInvestigation",
            "style": "link"
          },
          {
            "id": "31c1cf1c-74b5-44e2-ba9a-9497834ca3dc",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Query Comparison",
            "subTarget": "QueryComparison",
            "style": "link"
          },
          {
            "id": "db43bb45-1611-47ce-a2ad-517943f2aa1a",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "AutoStats",
            "subTarget": "Statistics",
            "style": "link"
          },
          {
            "id": "482ccc46-8a10-4ace-bfd6-63ac73b380af",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Query Audit",
            "subTarget": "QueryAudit",
            "style": "link"
          },
          {
            "id": "f42ddeea-8cc0-4095-bc90-11eac0b7f94c",
            "cellValue": "GroupSelection",
            "linkTarget": "parameter",
            "linkLabel": "Audit Search",
            "subTarget": "AuditSearch",
            "style": "link"
          }
        ]
      },
      "name": "links - 0"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 10,
            "content": {
              "chartId": "workbook90867bfc-5c33-464f-ac31-2c2e006b97f4",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 2,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 2592000000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-DWUUsedPercent",
                  "aggregation": 3,
                  "splitBy": null,
                  "columnName": "DWU Usaed %"
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-CPUPercent",
                  "aggregation": 3,
                  "columnName": "CPU Used %"
                }
              ],
              "title": "DWU Resource Utilization",
              "showOpenInMe": true,
              "showCreateAlertRule": true,
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "showPin": true,
            "name": "metric - 1"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbookb954d4a0-82ef-4409-88fb-837aaff80c8d",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 0
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ActiveQueries",
                  "aggregation": 1,
                  "splitBy": null
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-QueuedQueries",
                  "aggregation": 1
                }
              ],
              "title": "Active and Queued Queries",
              "showOpenInMe": true,
              "showCreateAlertRule": true,
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "showPin": true,
            "name": "metric - 1"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbookb954d4a0-82ef-4409-88fb-837aaff80c8d",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 3,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 2592000000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent",
                  "aggregation": 3,
                  "splitBy": null,
                  "columnName": "TempDB Utilization Percentage"
                }
              ],
              "title": "TempDB Utilization",
              "showOpenInMe": true,
              "showCreateAlertRule": true,
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "showPin": true,
            "name": "metric - 1 - Copy"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbookb954d4a0-82ef-4409-88fb-837aaff80c8d",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 0
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGAllocationBySystemPercent",
                  "aggregation": 3,
                  "splitBy": null,
                  "columnName": "Workload Group Allocation by System %"
                }
              ],
              "title": "Workload Group Utilization",
              "showOpenInMe": true,
              "showCreateAlertRule": true,
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "showPin": true,
            "name": "Workload Group Utilization"
          },
          {
            "type": 12,
            "content": {
              "version": "NotebookGroup/1.0",
              "groupType": "editable",
              "items": [
                {
                  "type": 3,
                  "content": {
                    "version": "KqlItem/1.0",
                    "query": "//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests \r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where StatementType !in ('Batch','Execute')\r\n| summarize //Session_ID=any(SessionId),\r\n    Request_ID=any(RequestId),\r\n    //Submit_Time=max(SubmitTime),\r\n    Start_Time=max(StartTime),\r\n    End_Time=max(EndTime),\r\n    Command=any(Command),\r\n    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status\r\n    Statement_Type=any(StatementType),\r\n    Resource_class=any(ResourceClass)\r\n    by RequestId\r\n| summarize ElapsedTime_min=bin(anyif(((End_Time - Start_Time)/1m),Start_Time > ago(30d)),1),\r\n    //Session_ID=any(Session_ID), \r\n   // Submit_Time=any(Submit_Time) ,\r\n    Start_Time=any(Start_Time), \r\n    End_Time=any(End_Time),\r\n    Command=any(Command),\r\n    Status=any(Status),\r\n    Statement_Type=any(Statement_Type)\r\n    ,Resource_class=any(Resource_class) \r\n    by Request_ID\r\n| where End_Time > ago(365d)\r\n| summarize count() by Status, bin(End_Time,5m)\r\n| render barchart   \r\n",
                    "size": 0,
                    "showAnalytics": true,
                    "title": "Query Completion Count by End Time - 5m buckets",
                    "color": "redBright",
                    "timeContextFromParameter": "TimeRange",
                    "timeBrushParameterName": "TimeRange",
                    "timeBrushExportOnlyWhenBrushed": true,
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces",
                    "crossComponentResources": [
                      "{LogAnalyticsWorkspace}"
                    ],
                    "chartSettings": {
                      "seriesLabelSettings": [
                        {
                          "seriesName": "Completed",
                          "color": "green"
                        },
                        {
                          "seriesName": "Failed",
                          "color": "red"
                        },
                        {
                          "seriesName": "Cancelled",
                          "color": "yellow"
                        }
                      ]
                    }
                  },
                  "showPin": true,
                  "name": "query - 4"
                },
                {
                  "type": 1,
                  "content": {
                    "json": "Use the buttons below to filter the next chart for Success or Failed queries. In many cases a failed query may not have a 'Command' column populated depending on what stage the query failed in. ",
                    "style": "info"
                  },
                  "customWidth": "25",
                  "name": "text - 3"
                },
                {
                  "type": 9,
                  "content": {
                    "version": "KqlParameterItem/1.0",
                    "parameters": [
                      {
                        "id": "e2a833ac-48b4-4ccd-bbcd-33fccf1dbd75",
                        "version": "KqlParameterItem/1.0",
                        "name": "QueryCompletionType",
                        "type": 1,
                        "isHiddenWhenLocked": true,
                        "timeContext": {
                          "durationMs": 86400000
                        }
                      }
                    ],
                    "style": "pills",
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces"
                  },
                  "name": "parameters - 4"
                },
                {
                  "type": 11,
                  "content": {
                    "version": "LinkItem/1.0",
                    "style": "nav",
                    "links": [
                      {
                        "id": "8e89112f-c67f-42c0-9622-02fa306fb7a5",
                        "cellValue": "QueryCompletionType",
                        "linkTarget": "parameter",
                        "linkLabel": "All Queries",
                        "subTarget": "''",
                        "style": "primary"
                      },
                      {
                        "id": "6abe39c7-4d4e-4c45-aa54-dc9a4c5e876e",
                        "cellValue": "QueryCompletionType",
                        "linkTarget": "parameter",
                        "linkLabel": "Success Only",
                        "subTarget": "Completed",
                        "preText": "",
                        "style": "secondary"
                      },
                      {
                        "id": "e41b4a0b-8464-491e-92be-a57217d6dcac",
                        "cellValue": "QueryCompletionType",
                        "linkTarget": "parameter",
                        "linkLabel": "Failures Only",
                        "subTarget": "Failed",
                        "preText": "",
                        "style": "secondary"
                      }
                    ]
                  },
                  "name": "links - 11"
                },
                {
                  "type": 3,
                  "content": {
                    "version": "KqlItem/1.0",
                    "query": "//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests \r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where StatementType !in ('Batch','Execute')\r\n| summarize //Session_ID=any(SessionId),\r\n    Request_ID=any(RequestId),\r\n    Start_Time=max(StartTime),\r\n    End_Time=max(EndTime),\r\n    Command=any(Command),\r\n    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status\r\n    Statement_Type=any(StatementType),\r\n    Resource_class=any(ResourceClass)\r\n    by RequestId\r\n| summarize ElapsedTime_min=bin(anyif(((End_Time - Start_Time)/1m),Start_Time > ago(30d)),1),\r\n    Start_Time=any(Start_Time), \r\n    End_Time=any(End_Time),\r\n    Command=any(Command),\r\n    Status=any(Status),\r\n    Statement_Type=any(Statement_Type)\r\n    ,Resource_class=any(Resource_class) \r\n    by Request_ID\r\n| where Status has '{QueryCompletionType}'\r\n| order by Start_Time\r\n\r\n",
                    "size": 0,
                    "showAnalytics": true,
                    "title": "Query Completions - use above buttons to filter",
                    "color": "redBright",
                    "timeContextFromParameter": "TimeRange",
                    "timeBrushParameterName": "TimeRange",
                    "timeBrushExportOnlyWhenBrushed": true,
                    "showExportToExcel": true,
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces",
                    "crossComponentResources": [
                      "{LogAnalyticsWorkspace}"
                    ],
                    "gridSettings": {
                      "rowLimit": 100
                    },
                    "chartSettings": {
                      "seriesLabelSettings": [
                        {
                          "seriesName": "Completed",
                          "color": "green"
                        },
                        {
                          "seriesName": "Failed",
                          "color": "red"
                        },
                        {
                          "seriesName": "Cancelled",
                          "color": "yellow"
                        }
                      ]
                    }
                  },
                  "showPin": true,
                  "name": "query - 4 - Copy"
                }
              ]
            },
            "name": "Query Completions",
            "styleSettings": {
              "showBorder": true
            }
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbook1afc57e6-0b32-4968-b299-db319bd21635",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 2592000000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-Connections",
                  "aggregation": 1,
                  "splitBy": null
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-ConnectionsBlockedByFirewall",
                  "aggregation": 1
                }
              ],
              "title": "Successful and Failed Connections",
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "name": "metric - 5"
          },
          {
            "type": 12,
            "content": {
              "version": "NotebookGroup/1.0",
              "groupType": "editable",
              "items": [
                {
                  "type": 3,
                  "content": {
                    "version": "KqlItem/1.0",
                    "query": " SQLSecurityAuditEvents\r\n    | where LogicalServerName == '{LogicalServerName}'\r\n    | where ActionName in ('DATABASE AUTHENTICATION SUCCEEDED','DATABASE AUTHENTICATION FAILED')\r\n    | project SourceSystem,ClientTlsVersion ,Succeeded,SessionId,ClientIp,SessionServerPrincipalName,ServerPrincipalName,DatabasePrincipalName,ApplicationName,HostName,TimeGenerated\r\n    | summarize count() by Succeeded,bin(TimeGenerated,1m)\r\n    | render barchart\r\n\r\n\r\n\r\n",
                    "size": 0,
                    "showAnalytics": true,
                    "title": "Database Authentication success/failure rate",
                    "timeContextFromParameter": "TimeRange",
                    "timeBrushParameterName": "TimeRange",
                    "timeBrushExportOnlyWhenBrushed": true,
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces",
                    "crossComponentResources": [
                      "{LogAnalyticsWorkspace}"
                    ],
                    "chartSettings": {
                      "xAxis": "TimeGenerated",
                      "group": "succeeded_s",
                      "createOtherGroup": null
                    }
                  },
                  "showPin": true,
                  "name": "query - 8"
                },
                {
                  "type": 9,
                  "content": {
                    "version": "KqlParameterItem/1.0",
                    "parameters": [
                      {
                        "id": "f7485a11-48df-4b61-a70e-9f56d6a00ec6",
                        "version": "KqlParameterItem/1.0",
                        "name": "AuthResult",
                        "type": 1,
                        "isHiddenWhenLocked": true,
                        "timeContext": {
                          "durationMs": 86400000
                        }
                      }
                    ],
                    "style": "pills",
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces"
                  },
                  "name": "parameters - 3"
                },
                {
                  "type": 11,
                  "content": {
                    "version": "LinkItem/1.0",
                    "style": "nav",
                    "links": [
                      {
                        "id": "2ed22e0a-2b53-4ed0-8f65-d2c621f34dad",
                        "cellValue": "AuthResult",
                        "linkTarget": "parameter",
                        "linkLabel": "All Authentications",
                        "subTarget": "''",
                        "style": "primary"
                      },
                      {
                        "id": "2789ab13-ae8a-472e-bad4-9c9bdc934d4d",
                        "cellValue": "AuthResult",
                        "linkTarget": "parameter",
                        "linkLabel": "Success Only",
                        "subTarget": "true",
                        "style": "secondary"
                      },
                      {
                        "id": "5cf4ddd4-e189-4b71-b456-0d4f1572a0a3",
                        "cellValue": "AuthResult",
                        "linkTarget": "parameter",
                        "linkLabel": "Failures Only",
                        "subTarget": "false",
                        "style": "secondary"
                      }
                    ]
                  },
                  "name": "links - 10"
                },
                {
                  "type": 3,
                  "content": {
                    "version": "KqlItem/1.0",
                    "query": " SQLSecurityAuditEvents\r\n    | where LogicalServerName == '{LogicalServerName}'\r\n    | where ActionName in ('DATABASE AUTHENTICATION SUCCEEDED','DATABASE AUTHENTICATION FAILED')\r\n    | where Succeeded == '{AuthResult}'\r\n    | project SourceSystem,ClientTlsVersion ,Succeeded,SessionId,ClientIp,SessionServerPrincipalName,ServerPrincipalName,DatabasePrincipalName,ApplicationName,HostName,TimeGenerated\r\n    //| summarize count() by Succeeded,bin(TimeGenerated,1m)\r\n\r\n\r\n\r\n\r\n\r\n",
                    "size": 0,
                    "showAnalytics": true,
                    "title": "Database Authentication success/failure rate",
                    "noDataMessage": "No Results",
                    "timeContextFromParameter": "TimeRange",
                    "queryType": 0,
                    "resourceType": "microsoft.operationalinsights/workspaces",
                    "crossComponentResources": [
                      "{LogAnalyticsWorkspace}"
                    ],
                    "gridSettings": {
                      "rowLimit": 100
                    },
                    "chartSettings": {
                      "xAxis": "TimeGenerated",
                      "group": "succeeded_s",
                      "createOtherGroup": null,
                      "showLegend": true
                    }
                  },
                  "showPin": true,
                  "name": "query - 8 - Copy"
                }
              ]
            },
            "conditionalVisibility": {
              "parameterName": "AuditingState",
              "comparison": "isEqualTo",
              "value": "enabled"
            },
            "name": "Database Authentication Group",
            "styleSettings": {
              "showBorder": true
            }
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbook993837ad-66d6-4cbc-ae1a-7c3f6623236b",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 2,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 2592000000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheUsedPercent",
                  "aggregation": 3,
                  "splitBy": null
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-AdaptiveCacheHitPercent",
                  "aggregation": 3
                }
              ],
              "title": "Adaptive Cache Used vs Hit Percentage",
              "showCreateAlertRule": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "showPin": true,
            "name": "metric - 6"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "Overview"
        },
        {
          "parameterName": "DiagnosticsState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "overviewGroup"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 10,
            "content": {
              "chartId": "workbook4a9cf761-cce2-45b2-8947-8a9428ec7e1c",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 3,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 86400000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-LocalTempDBUsedPercent",
                  "aggregation": 3,
                  "splitBy": null,
                  "columnName": "TempDB Util"
                }
              ],
              "title": "TempDB Max and Avg Utilization",
              "showOpenInMe": true,
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "showPin": true,
            "name": "metric - 0"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "19ee48f5-8f4e-4939-a0ef-c6bf656a93f9",
                  "version": "KqlParameterItem/1.0",
                  "name": "WeightParameter",
                  "type": 1,
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                },
                {
                  "id": "00553ec8-1a41-4dd9-a024-d607639c9bbb",
                  "version": "KqlParameterItem/1.0",
                  "name": "RequestID",
                  "type": 1,
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  },
                  "value": ""
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "name": "parameters - 3"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "let databaseResourceName = '{DatabaseResourceName}';\r\n//Weighted query steps\r\nSynapseSqlPoolRequestSteps \r\n| where _ResourceId == databaseResourceName\r\n| where RowCount > 0\r\n| summarize sum(RowCount) by RequestId, OperationType\r\n| order by sum_RowCount desc\r\n| limit 20\r\n| render columnchart ",
              "size": 0,
              "showAnalytics": true,
              "title": "20 Largest Query Steps by Most Rows Moved",
              "timeContextFromParameter": "TimeRange",
              "exportFieldName": "Request_ID",
              "exportParameterName": "RequestID",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "chartSettings": {
                "xAxis": "RequestId",
                "group": "OperationType",
                "createOtherGroup": 20,
                "showLegend": true
              }
            },
            "showPin": true,
            "name": "query - 1 - Copy"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "8afacdd5-2690-48d0-b125-fb118378e90c",
                  "version": "KqlParameterItem/1.0",
                  "name": "WeightParameter",
                  "type": 1,
                  "value": "Unweighted",
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "name": "parameters - 8"
          },
          {
            "type": 11,
            "content": {
              "version": "LinkItem/1.0",
              "style": "nav",
              "links": [
                {
                  "id": "c98d3722-9907-43ab-9306-1957d6f7f858",
                  "cellValue": "WeightParameter",
                  "linkTarget": "parameter",
                  "linkLabel": "Weighted Rowcounts",
                  "subTarget": "Weighted",
                  "preText": "",
                  "postText": "",
                  "style": "secondary"
                },
                {
                  "id": "a06ae99a-ad62-45e9-8c25-c219b81f59c0",
                  "cellValue": "WeightParameter",
                  "linkTarget": "parameter",
                  "linkLabel": "Unweighted Rowcounts",
                  "subTarget": "Unweighted",
                  "preText": "",
                  "postText": "",
                  "style": "secondary"
                }
              ]
            },
            "name": "links - 3"
          },
          {
            "type": 1,
            "content": {
              "json": "Current Setting: {WeightParameter}",
              "style": "info"
            },
            "customWidth": "25",
            "name": "text - 4"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "let databaseResourceName = '{DatabaseResourceName}';\r\n//Weighted query steps\r\nlet RequestSteps = SynapseSqlPoolRequestSteps\r\n| where _ResourceId == databaseResourceName\r\n//| where RowCount > 10000000\r\n| extend Step_Elapsed_Min = round((EndTime - StartTime) /1m, 2)\r\n| extend Weighted_cnt = iff('{WeightParameter}'=='Weighted',(case(OperationType == 'BroadcastMoveOperation', (RowCount*10), RowCount)),RowCount)\r\n| project-rename StepStatus = Status, StepStart = StartTime, StepEnd = EndTime//, StepResource = Resource\r\n| top 100 by Weighted_cnt desc\r\n| order by Weighted_cnt desc\r\n| project Request_ID=RequestId,OperationType, RowCount,Weighted_cnt,Step_Elapsed_Min, StepStart, StepEnd, StepStatus, StepIndex;\r\nRequestSteps | join (\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId == databaseResourceName\r\n| where StatementType !in ('Batch','Execute')\r\n| summarize //Session_ID=any(SessionId),\r\n    Request_ID=any(RequestId),\r\n    //Submit_Time=max(SubmitTime),\r\n    Start_Time=max(StartTime),\r\n    End_Time=max(EndTime),\r\n    Command=any(Command),\r\n    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status\r\n    Statement_Type=any(StatementType),\r\n    Resource_class=any(ResourceClass)\r\n    by RequestId\r\n| summarize //Session_ID=any(Session_ID), \r\n//Submit_Time=any(Submit_Time) ,\r\nStart_Time=any(Start_Time), End_Time=any(End_Time),Command=any(Command),Status=any(Status),Statement_Type=any(Statement_Type),Resource_class=any(Resource_class) by Request_ID\r\n//| order by Step_Elapsed_Min desc\r\n| extend Request_Elapsed_Min = round((End_Time - Start_Time)/1m, 2)\r\n| project-rename ReqStatus = Status, ReqStart = Start_Time, ReqEnd = End_Time\r\n) on Request_ID\r\n| project-reorder //Session_ID, \r\nRequest_ID, Request_Elapsed_Min, ReqStart, ReqEnd, ReqStatus,StepIndex, OperationType, RowCount,Weighted_cnt,Step_Elapsed_Min, StepStart, StepEnd, StepStatus, Statement_Type, Command, Resource_class\r\n| order by Weighted_cnt desc\r\n| limit 20",
              "size": 3,
              "showAnalytics": true,
              "title": "20 Largest Query Steps by Most Rows Moved",
              "timeContextFromParameter": "TimeRange",
              "exportFieldName": "Request_ID1",
              "exportParameterName": "RequestID",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "sortBy": [
                  {
                    "itemKey": "Weighted_cnt",
                    "sortOrder": 2
                  }
                ]
              },
              "sortBy": [
                {
                  "itemKey": "Weighted_cnt",
                  "sortOrder": 2
                }
              ]
            },
            "showPin": true,
            "name": "query - 1"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "let databaseResourceName = '{DatabaseResourceName}';\r\n//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId  == databaseResourceName\r\n| where StatementType !in ('Batch','Execute')\r\n| summarize //Session_ID=any(SessionId),\r\n    Request_ID=any(RequestId),\r\n    Start_Time=max(StartTime),\r\n    End_Time=max(EndTime),\r\n    Command=any(Command),\r\n    Status=min(Status), //This works because Completed/Failed/Cancelled are all below running, below suspended. This happens to work out where the min is the current status\r\n    Statement_Type=any(StatementType),\r\n    Resource_class=any(ResourceClass)\r\n    by RequestId\r\n| summarize ElapsedTime_min=bin(anyif(((End_Time - Start_Time)/1m),Start_Time > ago(30d)),1),\r\n    Start_Time=any(Start_Time), \r\n    End_Time=any(End_Time),\r\n    Command=any(Command),\r\n    Status=any(Status),\r\n    Statement_Type=any(Statement_Type)\r\n    ,Resource_class=any(Resource_class) \r\n    by Request_ID\r\n| where Request_ID == '{RequestID}' and Request_ID != ''\r\n\r\n",
              "size": 4,
              "showAnalytics": true,
              "title": "Selected Query",
              "noDataMessage": "Select a query above to view details",
              "noDataMessageStyle": 4,
              "timeContextFromParameter": "TimeRange",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "formatters": [
                  {
                    "columnMatch": "Command",
                    "formatter": 0,
                    "formatOptions": {
                      "customColumnWidthSetting": "35%"
                    }
                  }
                ]
              }
            },
            "showPin": true,
            "name": "query - 6"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SynapseSqlPoolRequestSteps \r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where RequestId == '{RequestID}' and RequestId != '' //Put your QueryID here\r\n| where Status != 'Running'\r\n| summarize max(StartTime),max(EndTime),max(RequestId),max(OperationType),max(RowCount),max(Command),max(Status) by StepIndex\r\n| order by StepIndex asc",
              "size": 3,
              "showAnalytics": true,
              "title": "Query Plan",
              "noDataMessage": "Select a query above to view the plan",
              "noDataMessageStyle": 4,
              "timeContextFromParameter": "TimeRange",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ]
            },
            "showPin": true,
            "name": "query - 7"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "TempDB"
        },
        {
          "parameterName": "DiagnosticsState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "TempDBGroup"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 1,
            "content": {
              "json": "## Search Criteria\r\nUse the following fields to search either using a query text snippet or using a Request ID. If using a query text snippet, try to keep it as simple as possible becuase minor changes in formatting may cause your queries not to show up in the results. It's best to pick something like a table name, then choose the proper query from the list that will populate. "
            },
            "customWidth": "50",
            "name": "text - 4"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "4b98dd26-4ccf-420e-a990-8d015f27fb76",
                  "version": "KqlParameterItem/1.0",
                  "name": "SampleQID",
                  "type": 1,
                  "value": "999",
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                },
                {
                  "id": "d5524dd5-cf7e-41cf-beb3-474b3290289e",
                  "version": "KqlParameterItem/1.0",
                  "name": "RequestId",
                  "type": 1,
                  "value": "",
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "name": "initializeQueryInvestigationParameters"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "0c2128d0-d979-4562-a28c-e7ceb955f126",
                  "version": "KqlParameterItem/1.0",
                  "name": "RequestId",
                  "type": 1,
                  "value": "",
                  "label": "Request Id Search"
                },
                {
                  "id": "29880874-2d41-4bd5-bf22-3e47ae8b1145",
                  "version": "KqlParameterItem/1.0",
                  "name": "QueryTextSnippet",
                  "type": 1,
                  "value": "",
                  "timeContext": {
                    "durationMs": 86400000
                  }
                }
              ],
              "style": "formVertical",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "customWidth": "60",
            "name": "parameters - 3"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SynapseSqlPoolExecRequests\r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where StatementType !in ('Batch','Execute')\r\n| summarize \r\n    Request_ID=max(RequestId),  \r\n    Start_Time=max(StartTime),\r\n    End_Compile_Time=max(EndCompileTime), \r\n    End_Time=max(EndTime), \r\n    QueryText = any(Command), \r\n    Last_Status=min(Status),\r\n    Statement_Type=max(StatementType),\r\n    Resource_class=max(ResourceClass) \r\n    by RequestId\r\n| extend Elapsed_Time_s=(End_Time - Start_Time)/1s\r\n| where QueryText has '{QueryTextSnippet}'\r\nand RequestId has '{RequestId}'\r\n| summarize \r\n    Executions = count(),\r\n    SampleQID = any(RequestId),\r\n    Elapsed_Time_s=max(Elapsed_Time_s)\r\n    by QueryText\r\n| order by Elapsed_Time_s\r\n\r\n\r\n\r\n",
              "size": 0,
              "showAnalytics": true,
              "title": "Matching Queries",
              "timeContextFromParameter": "TimeRange",
              "exportedParameters": [
                {
                  "fieldName": "SampleQID",
                  "parameterName": "SampleQID"
                },
                {
                  "fieldName": "SampleQID",
                  "parameterName": "RequestId",
                  "parameterType": 1
                },
                {
                  "fieldName": "QueryText",
                  "parameterName": "QueryText",
                  "parameterType": 1
                }
              ],
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "formatters": [
                  {
                    "columnMatch": "Command",
                    "formatter": 0,
                    "formatOptions": {
                      "customColumnWidthSetting": "50%"
                    }
                  }
                ],
                "sortBy": [
                  {
                    "itemKey": "Elapsed_Time_s",
                    "sortOrder": 2
                  }
                ]
              },
              "sortBy": [
                {
                  "itemKey": "Elapsed_Time_s",
                  "sortOrder": 2
                }
              ]
            },
            "showPin": true,
            "name": "query - 0"
          },
          {
            "type": 1,
            "content": {
              "json": "## DSQL Command "
            },
            "conditionalVisibility": {
              "parameterName": "QueryText",
              "comparison": "isNotEqualTo"
            },
            "name": "text - 8"
          },
          {
            "type": 1,
            "content": {
              "json": "```{QueryText}```\r\n"
            },
            "conditionalVisibility": {
              "parameterName": "QueryText",
              "comparison": "isNotEqualTo"
            },
            "name": "ShowQueryText",
            "styleSettings": {
              "showBorder": true
            }
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SynapseSqlPoolExecRequests\r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where StatementType !in ('Batch','Execute')\r\n| where RequestId == '{SampleQID}'\r\n| summarize  \r\n    Request_ID=max(RequestId),   \r\n    Start_Time=max(StartTime),\r\n    End_Compile_Time=max(EndCompileTime), \r\n    End_Time=max(EndTime), \r\n    Command=max(Command), \r\n    Last_Status=min(Status),\r\n    Statement_Type=max(StatementType),\r\n    Resource_class=max(ResourceClass) \r\n    by RequestId\r\n| extend elapsedTime_sec = iif(End_Time > ago(365d),(End_Time - Start_Time)/1s,real(null)) \r\n| join kind=inner\r\n    (SynapseSqlPoolExecRequests\r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where StatementType !in ('Batch','Execute')\r\n    | summarize \r\n        Request_ID=max(RequestId),   \r\n        Start_Time=max(StartTime),\r\n        End_Compile_Time=max(EndCompileTime), \r\n        End_Time=max(EndTime), \r\n        Command=max(Command), \r\n        Last_Status=min(Status),\r\n        Statement_Type=max(StatementType),\r\n        Resource_class=max(ResourceClass) \r\n        by RequestId\r\n    //| extend elapsedTime_sec = (End_Time - Start_Time)/1s\r\n    | extend elapsedTime_sec = iif(End_Time > ago(365d),(End_Time - Start_Time)/1s,real(null)) \r\n    )\r\non Command \r\n| project Request_ID1,Start_Time1,End_Compile_Time1,End_Time1,Last_Status1,Statement_Type1,Resource_class1,elapsedTime_sec1\r\n",
              "size": 0,
              "showAnalytics": true,
              "title": "All Executions of Selected Query Text",
              "noDataMessage": "Select a query above to see individual executions",
              "noDataMessageStyle": 4,
              "timeContextFromParameter": "TimeRange",
              "exportFieldName": "Request_ID1",
              "exportParameterName": "RequestId",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "sortBy": []
            },
            "showPin": true,
            "name": "query - 0 - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SynapseSqlPoolRequestSteps \r\n| where _ResourceId  == '{DatabaseResourceName}'\r\n| where RequestId == '{RequestId}' and RequestId != ''\r\n| where Status != 'Running'\r\n| summarize max(StartTime),max(EndTime),max(RequestId),max(OperationType),max(RowCount),max(Command),max(Status) by StepIndex\r\n| order by StepIndex asc",
              "size": 3,
              "showAnalytics": true,
              "title": "Query Plan for Selected Query",
              "noDataMessage": "Select a Query Above to See the Query Plan",
              "noDataMessageStyle": 4,
              "timeContextFromParameter": "TimeRange",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ]
            },
            "name": "query - 0 - Copy - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SynapseSqlPoolExecRequests\r\n    | where StatementType =='CreateStatistics'\r\n    | where _ResourceId has '{DatabaseName}'\r\n    | summarize  \r\n        Root_Query_Id=max(RootQueryId),   \r\n        Start_Time=max(StartTime),\r\n        End_Compile_Time=max(EndCompileTime), \r\n        End_Time=max(EndTime), \r\n        Command=max(Command), \r\n        Last_Status=min(Status),\r\n        Statement_Type=max(StatementType),\r\n        Resource_class=max(ResourceClass) \r\n    by RequestId\r\n    | where Root_Query_Id == '{RequestId}'",
              "size": 0,
              "showAnalytics": true,
              "title": "Triggered Auto-Stats Statements",
              "noDataMessage": "No triggered autostats statements found",
              "timeContextFromParameter": "TimeRange",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "formatters": [
                  {
                    "columnMatch": "Submit_Time",
                    "formatter": 0,
                    "numberFormat": {
                      "unit": 0,
                      "options": {
                        "style": "decimal"
                      }
                    }
                  },
                  {
                    "columnMatch": "Command",
                    "formatter": 0,
                    "formatOptions": {
                      "customColumnWidthSetting": "100ch"
                    }
                  }
                ]
              }
            },
            "name": "All triggered auto-stats statements"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "QueryInvestigation"
        },
        {
          "parameterName": "DiagnosticsState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "QueryInvestigationGroup",
      "styleSettings": {
        "showBorder": true
      }
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 1,
            "content": {
              "json": "All Charts on this page are based on the last 7 days of data",
              "style": "info"
            },
            "customWidth": "25",
            "name": "text - 5"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "533ff6bb-97cd-4aaa-9372-171cad378bcd",
                  "version": "KqlParameterItem/1.0",
                  "name": "QueryText",
                  "type": 1,
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                },
                {
                  "id": "99de0056-d4f3-465e-a27e-599d69b23c77",
                  "version": "KqlParameterItem/1.0",
                  "name": "RequestId",
                  "type": 1,
                  "value": "999",
                  "isHiddenWhenLocked": true,
                  "timeContext": {
                    "durationMs": 86400000
                  }
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "name": "initializeTempDBVariables"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "//Build cache count by day\r\nlet databaseResourceName = '{DatabaseResourceName}';\r\n//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId  == databaseResourceName\r\n| where StatementType == 'BuildReplicatedTableCache'\r\n| where Command != \"\"\r\n| where ResourceClass != \"\"\r\n| project Command,TimeGenerated,RequestId\r\n| summarize LastRebuild=max(TimeGenerated),RebuildCount=count(RequestId) by Command\r\n| order by RebuildCount desc\r\n| limit 15\r\n",
              "size": 3,
              "showAnalytics": true,
              "title": "Top 15 Most Rebuilds by Table",
              "noDataMessage": "No replicated table rebuilds found in the last 7 days",
              "noDataMessageStyle": 4,
              "timeContext": {
                "durationMs": 604800000
              },
              "exportFieldName": "Command",
              "exportParameterName": "QueryText",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "formatters": [
                  {
                    "columnMatch": "Command_s",
                    "formatter": 0,
                    "formatOptions": {
                      "customColumnWidthSetting": "40%"
                    }
                  }
                ]
              }
            },
            "showPin": true,
            "name": "query - 0"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "//Build cache count by day\r\nlet databaseResourceName = '{DatabaseResourceName}';\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId  == databaseResourceName\r\n| where StatementType == 'BuildReplicatedTableCache'\r\n| where Command == \"{QueryText}\"\r\n| where ResourceClass != \"\"\r\n| project Command,TimeGenerated,RequestId\r\n| summarize count() by Command,bin(TimeGenerated,24h)\r\n| limit 20\r\n| render timechart",
              "size": 0,
              "showAnalytics": true,
              "title": "Rebuilds per Day for Selected Table",
              "noDataMessage": "Select a query above to see runs by day",
              "noDataMessageStyle": 4,
              "timeContext": {
                "durationMs": 604800000
              },
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "chartSettings": {
                "group": "Command_s",
                "createOtherGroup": 20,
                "ySettings": {
                  "min": 0
                }
              }
            },
            "showPin": true,
            "name": "query - 0 - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "//Build cache count by day\r\nlet databaseResourceName = '{DatabaseResourceName}';\r\n//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId  == databaseResourceName\r\n| where StatementType == 'BuildReplicatedTableCache'\r\n| where Command != \"\"\r\n| where ResourceClass != \"\"\r\n| project Command,TimeGenerated,RequestId\r\n| summarize count() by Command, bin(TimeGenerated,24h)\r\n//| where count_ > 7\r\n| order by count_ desc\r\n\r\n",
              "size": 2,
              "showAnalytics": true,
              "title": "Rebuild Count by Table by Day",
              "noDataMessage": " Only tables with more than 7 total rebuilds will show up. If no talbes with that many rebuilds are found this chart will be empty",
              "noDataMessageStyle": 4,
              "timeContext": {
                "durationMs": 604800000
              },
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "visualization": "categoricalbar",
              "gridSettings": {
                "sortBy": [
                  {
                    "itemKey": "count_",
                    "sortOrder": 1
                  }
                ]
              },
              "sortBy": [
                {
                  "itemKey": "count_",
                  "sortOrder": 1
                }
              ],
              "tileSettings": {
                "showBorder": false,
                "titleContent": {
                  "columnMatch": "Command_s",
                  "formatter": 1
                },
                "leftContent": {
                  "columnMatch": "count_",
                  "formatter": 12,
                  "formatOptions": {
                    "palette": "auto"
                  },
                  "numberFormat": {
                    "unit": 17,
                    "options": {
                      "maximumSignificantDigits": 3,
                      "maximumFractionDigits": 2
                    }
                  }
                }
              },
              "graphSettings": {
                "type": 0,
                "topContent": {
                  "columnMatch": "Command_s",
                  "formatter": 1
                },
                "centerContent": {
                  "columnMatch": "count_",
                  "formatter": 1,
                  "numberFormat": {
                    "unit": 17,
                    "options": {
                      "maximumSignificantDigits": 3,
                      "maximumFractionDigits": 2
                    }
                  }
                }
              },
              "chartSettings": {
                "group": "Command_s",
                "createOtherGroup": 99,
                "showDataPoints": true
              }
            },
            "showPin": true,
            "name": "query - 0 - Copy - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "let databaseResourceName = '{DatabaseResourceName}';\r\n//Long-Running Queries - Just Actual Queries\r\n//If 'Command' is empty - you need to set a bigger time window, the older record with the command is outside of your window\r\nSynapseSqlPoolExecRequests\r\n| where _ResourceId  == databaseResourceName\r\n| where StatementType == 'BuildReplicatedTableCache'\r\n| summarize          Start_Time=max(StartTime),      End_Time=max(EndTime),      Command=max(Command),       Statement_Type=max(StatementType),     Resource_class=max(ResourceClass)      by RequestId\r\n| join kind= inner\r\n(\r\n    SynapseSqlPoolExecRequests\r\n    | where _ResourceId  == databaseResourceName\r\n    | where StatementType == 'BuildReplicatedTableCache'\r\n    | where StatementType == 'BuildReplicatedTableCache'\r\n    | where EndTime > ago(7d)\r\n    | where StartTime > ago(7d)\r\n    | extend elapsedTime_min = (EndTime - StartTime)/1m\r\n    | order by elapsedTime_min desc\r\n    | project RequestId,elapsedTime_min \r\n)\r\non RequestId\r\n| order by elapsedTime_min desc\r\n| project RequestId,Start_Time,End_Time,Elapsed_Time=round(elapsedTime_min,1) ,Command\r\n| limit 15\r\n",
              "size": 3,
              "showAnalytics": true,
              "title": "Top 15 Elapsed Time per Rebuild",
              "noDataMessageStyle": 4,
              "timeContext": {
                "durationMs": 604800000
              },
              "exportFieldName": "RequestId",
              "exportParameterName": "RequestId",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "gridSettings": {
                "formatters": [
                  {
                    "columnMatch": "Command",
                    "formatter": 0,
                    "formatOptions": {
                      "customColumnWidthSetting": "40%"
                    }
                  }
                ]
              }
            },
            "showPin": true,
            "name": "query - 3"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": " let databaseResourceName = '{DatabaseResourceName}';\r\nSynapseSqlPoolRequestSteps \r\n| where _ResourceId  == databaseResourceName\r\n| where RequestId == '{RequestId}'\r\n| where Status != 'Running'\r\n| summarize max(StartTime),max(EndTime),max(RequestId),max(OperationType),max(RowCount),max(Command),max(Status) by StepIndex\r\n| order by StepIndex asc",
              "size": 3,
              "showAnalytics": true,
              "title": "Query Plan for Selected Query",
              "noDataMessage": "Select a query above to view plan",
              "noDataMessageStyle": 4,
              "timeContext": {
                "durationMs": 604800000
              },
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ]
            },
            "showPin": true,
            "name": "query - 4"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "ReplicatedTables"
        },
        {
          "parameterName": "DiagnosticsState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "ReplicatedTablesGroup"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 10,
            "content": {
              "chartId": "workbook72446028-6edb-4cb0-8952-e0c13bda488f",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 14400000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGAllocationBySystemPercent",
                  "aggregation": 3,
                  "splitBy": "WorkloadGroup"
                }
              ],
              "title": "Workload Group Allocation By System Percent",
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "name": "metric - 0"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbookc898119a-7381-469d-b51a-d505b4f80e73",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 14400000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGActiveQueries",
                  "aggregation": 1,
                  "splitBy": "WorkloadGroup"
                }
              ],
              "title": "Query Count by Workload Group",
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "customWidth": "50",
            "name": "metric - 1"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbook8d175f6c-427b-47fc-85ea-37edd0be707c",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 1,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 14400000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool-WLGQueuedQueries",
                  "aggregation": 1,
                  "splitBy": "WorkloadGroup"
                }
              ],
              "title": "Queued Queries by Workload Group",
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "name": "Queued Queries by Workload Group"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "parameters": [
                {
                  "id": "6f50577d-7b00-4e4a-acf9-d45c7a5ee813",
                  "version": "KqlParameterItem/1.0",
                  "name": "WorkloadGroupName",
                  "type": 2,
                  "multiSelect": true,
                  "quote": "'",
                  "delimiter": ",",
                  "query": "SynapseSqlPoolExecRequests \r\n| where _ResourceId == '{DatabaseResourceName}'\r\n and ResourceClass != \"\"\r\n| distinct ResourceClass",
                  "crossComponentResources": [
                    "{LogAnalyticsWorkspace}"
                  ],
                  "typeSettings": {
                    "additionalResourceOptions": [
                      "value::all"
                    ],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "defaultValue": "value::all",
                  "queryType": 0,
                  "resourceType": "microsoft.operationalinsights/workspaces"
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "name": "parameters - 2"
          },
          {
            "type": 10,
            "content": {
              "chartId": "workbook3da1d18a-1bf5-46c5-b3b7-211f71d329cc",
              "version": "MetricsItem/2.0",
              "size": 0,
              "chartType": 2,
              "resourceType": "microsoft.synapse/workspaces/sqlpools",
              "metricScope": 0,
              "resourceParameter": "DatabaseResourceName",
              "resourceIds": [
                "{DatabaseResourceName}"
              ],
              "timeContextFromParameter": "TimeRange",
              "timeContext": {
                "durationMs": 14400000
              },
              "metrics": [
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGEffectiveCapResourcePercent",
                  "aggregation": 3,
                  "splitBy": null
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGEffectiveMinResourcePercent",
                  "aggregation": 3
                },
                {
                  "namespace": "microsoft.synapse/workspaces/sqlpools",
                  "metric": "microsoft.synapse/workspaces/sqlpools-SQL dedicated pool  Workload management-WLGAllocationBySystemPercent",
                  "aggregation": 3
                }
              ],
              "filters": [
                {
                  "id": "5",
                  "key": "WorkloadGroup",
                  "operator": 0,
                  "valueParam": "WorkloadGroupName"
                }
              ],
              "timeBrushParameterName": "TimeRange",
              "timeBrushExportOnlyWhenBrushed": true,
              "gridSettings": {
                "rowLimit": 10000
              }
            },
            "name": "metric - 3"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "WorkloadManagement"
        },
        {
          "parameterName": "DiagnosticsState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "WorkloadManagementGroup"
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 1,
            "content": {
              "json": "## Select a Principal or Application name to filter results - leave to 'unset' to view all results\r\nSQL Auditing must be enabled and sending to the same Log Analytics Workspace for this page to work. "
            },
            "name": "text - 5"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "parameters": [
                {
                  "id": "8d25c043-d1ff-4546-a1fa-f4bcbfdab8af",
                  "version": "KqlParameterItem/1.0",
                  "name": "User",
                  "type": 2,
                  "description": "User to filter subsequent queries - leave to 'unset' for all users",
                  "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| summarize by ServerPrincipalName",
                  "crossComponentResources": [
                    "{LogAnalyticsWorkspace}"
                  ],
                  "value": null,
                  "typeSettings": {
                    "additionalResourceOptions": [],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "queryType": 0,
                  "resourceType": "microsoft.operationalinsights/workspaces"
                },
                {
                  "id": "aa766d64-693f-4024-b4a4-b5b56b28376b",
                  "version": "KqlParameterItem/1.0",
                  "name": "Application",
                  "type": 2,
                  "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| summarize by ApplicationName",
                  "crossComponentResources": [
                    "{LogAnalyticsWorkspace}"
                  ],
                  "value": null,
                  "typeSettings": {
                    "additionalResourceOptions": [],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "queryType": 0,
                  "resourceType": "microsoft.operationalinsights/workspaces"
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "customWidth": "30",
            "name": "parameters - 1"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| where DurationMs > 0\r\n| extend duration_seconds = DurationMs /1000.0\r\n| where Statement != 'select @@version'\r\n| where Statement != 'SELECT @@SPID;'\r\n| where ServerPrincipalName has '{User}'\r\n| where ApplicationName has '{Application}'\r\n| project ServerPrincipalName, EventTime, LogicalServerName, DurationMs, duration_seconds, AffectedRows, Statement, ApplicationName\r\n| summarize duration_seconds = round(sum(duration_seconds)) , query_count = count() by EventDay = bin(EventTime,1d), UserName = ServerPrincipalName, Application = ApplicationName \r\n| order by EventDay, duration_seconds desc",
              "size": 0,
              "showAnalytics": true,
              "title": "Query Summary for Selected User {User} {Application}",
              "noDataMessage": "Select a user to see query activity",
              "timeContextFromParameter": "TimeRange",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ]
            },
            "showPin": true,
            "name": "query - 0 - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| where DurationMs > 0\r\n| extend duration_seconds = DurationMs /1000.0\r\n| where Statement != 'select @@version'\r\n| where Statement != 'SELECT @@SPID;'\r\n| where ServerPrincipalName has '{User}'\r\n| where ApplicationName has '{Application}'\r\n| project ServerPrincipalName, EventTime, LogicalServerName, DurationMs, duration_seconds, AffectedRows, Statement, ApplicationName\r\n| summarize duration_seconds = round(sum(duration_seconds)) , query_count = count() by EventDay = bin(EventTime,1d), UserName = ServerPrincipalName, Application = ApplicationName \r\n| order by EventDay, duration_seconds desc",
              "size": 0,
              "showAnalytics": true,
              "title": "Query Summary for Selected User {User} {Application}",
              "noDataMessage": "Select a user to see query activity",
              "timeContextFromParameter": "TimeRange",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "visualization": "unstackedbar",
              "tileSettings": {
                "showBorder": false,
                "titleContent": {
                  "columnMatch": "UserName",
                  "formatter": 1
                },
                "leftContent": {
                  "columnMatch": "duration_seconds",
                  "formatter": 12,
                  "formatOptions": {
                    "palette": "auto"
                  },
                  "numberFormat": {
                    "unit": 17,
                    "options": {
                      "maximumSignificantDigits": 3,
                      "maximumFractionDigits": 2
                    }
                  }
                }
              },
              "graphSettings": {
                "type": 0,
                "topContent": {
                  "columnMatch": "UserName",
                  "formatter": 1
                },
                "centerContent": {
                  "columnMatch": "duration_seconds",
                  "formatter": 1,
                  "numberFormat": {
                    "unit": 17,
                    "options": {
                      "maximumSignificantDigits": 3,
                      "maximumFractionDigits": 2
                    }
                  }
                }
              },
              "chartSettings": {
                "xAxis": "UserName"
              },
              "mapSettings": {
                "locInfo": "LatLong",
                "sizeSettings": "duration_seconds",
                "sizeAggregation": "Sum",
                "legendMetric": "duration_seconds",
                "legendAggregation": "Sum",
                "itemColorSettings": {
                  "type": "heatmap",
                  "colorAggregation": "Sum",
                  "nodeColorField": "duration_seconds",
                  "heatmapPalette": "greenRed"
                }
              }
            },
            "showPin": true,
            "name": "query - 0 - Copy - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SQLSecurityAuditEvents \r\n    | where  LogicalServerName == \"{LogicalServerName}\"\r\n    | where DurationMs > 0\r\n    | extend duration_seconds = DurationMs /1000.0\r\n    | where Statement != 'select @@version'\r\n    | where Statement != 'SELECT @@SPID;'\r\n    | where ServerPrincipalName has '{User}'\r\n    | where ApplicationName has '{Application}'\r\n    | project DatabaseName= DatabaseName, UserName= ServerPrincipalName, EventTime= EventTime, Host= HostName, duration_seconds = round(duration_seconds), Statement, QuerySource = ApplicationName , AffectedRows\r\n    | project-reorder DatabaseName, UserName, Host, EventTime, duration_seconds, Statement, QuerySource\r\n\r\n\r\n\r\n\r\n\r\n",
              "size": 0,
              "showAnalytics": true,
              "title": "Queries {User} {Application}",
              "noDataMessage": "Select a user to see query activity",
              "timeContextFromParameter": "TimeRange",
              "showExportToExcel": true,
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ]
            },
            "showPin": true,
            "name": "query - 0 - Copy - Copy"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SQLSecurityAuditEvents \r\n    | where  LogicalServerName == \"{LogicalServerName}\"\r\n    | where DurationMs > 0\r\n    | extend duration_seconds = DurationMs /1000.0\r\n    | where Statement != 'select @@version'\r\n    | where Statement != 'SELECT @@SPID;'\r\n    | where ServerPrincipalName has '{User}'\r\n    | where ApplicationName has '{Application}'\r\n    | project DatabaseName= DatabaseName, UserName= ServerPrincipalName, EventTime= EventTime, Host= HostName, duration_seconds = round(duration_seconds), Statement, QuerySource = ApplicationName , AffectedRows\r\n    | project-reorder AffectedRows,DatabaseName, UserName, Host, EventTime, duration_seconds, Statement, QuerySource\r\n\r\n\r\n\r\n\r\n\r\n",
              "size": 0,
              "showAnalytics": true,
              "timeContextFromParameter": "TimeRange",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "visualization": "barchart",
              "chartSettings": {
                "xAxis": "Host",
                "group": "UserName",
                "createOtherGroup": null,
                "showLegend": true
              }
            },
            "showPin": true,
            "name": "query - 6"
          },
          {
            "type": 3,
            "content": {
              "version": "KqlItem/1.0",
              "query": "SQLSecurityAuditEvents\r\n| where  LogicalServerName == \"{LogicalServerName}\"\r\n    | where DurationMs > 0\r\n| extend Duration = round(DurationMs /1000.0)\r\n| extend TimeBin = case (datetime_part(\"Hour\",TimeGenerated) in (6,7,8,9,10,11,12), \"Morning_6-12\", datetime_part(\"Hour\",TimeGenerated) in (13,14,15,16,17,18), \"Afternoon_12-18\", \"Overnight_18-6\")\r\n| where ServerPrincipalName has '{User}'\r\n| where ApplicationName has '{Application}'\r\n| summarize QueryDuration = sum(Duration) by EventTime = bin(EventTime, 1d), TimeBin",
              "size": 0,
              "showAnalytics": true,
              "title": "Query Activity by time - sum(Duration) {User} {Application}",
              "noDataMessage": "Select a user to see query activity",
              "timeContextFromParameter": "TimeRange",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "visualization": "barchart"
            },
            "showPin": true,
            "name": "query - 0 - Copy"
          }
        ]
      },
      "conditionalVisibilities": [
        {
          "parameterName": "GroupSelection",
          "comparison": "isEqualTo",
          "value": "QueryAudit"
        },
        {
          "parameterName": "AuditingState",
          "comparison": "isEqualTo",
          "value": "enabled"
        }
      ],
      "name": "QueryAuditGroup",
      "styleSettings": {
        "showBorder": true
      }
    },
    {
      "type": 12,
      "content": {
        "version": "NotebookGroup/1.0",
        "groupType": "editable",
        "items": [
          {
            "type": 1,
            "content": {
              "json": "# Use this page to search the audit logs for a particular query\r\nYou can search using a combination of: \r\n* Date: Set the time range using the parameter at the top of the workbook\r\n* User: only show queries for the specified user\r\n* Application: only show queries submitted by the specified application\r\n* Query Text Snippet(s) - mutliple fields are provided, if you enter data into multiple fields then it will look for all of those values combined in the results\r\nYou can then sort your results in teh chart below by duration or affected rows to find what you are looking for.\r\n\r\nNOTE: query text is limited to the first 4,000 characters"
            },
            "name": "text - 3"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "crossComponentResources": [
                "{LogAnalyticsWorkspace}"
              ],
              "parameters": [
                {
                  "id": "8d25c043-d1ff-4546-a1fa-f4bcbfdab8af",
                  "version": "KqlParameterItem/1.0",
                  "name": "User",
                  "type": 2,
                  "description": "User to filter subsequent queries - leave to 'unset' for all users",
                  "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| summarize by ServerPrincipalName",
                  "crossComponentResources": [
                    "{LogAnalyticsWorkspace}"
                  ],
                  "value": null,
                  "typeSettings": {
                    "additionalResourceOptions": [],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "queryType": 0,
                  "resourceType": "microsoft.operationalinsights/workspaces"
                },
                {
                  "id": "aa766d64-693f-4024-b4a4-b5b56b28376b",
                  "version": "KqlParameterItem/1.0",
                  "name": "Application",
                  "type": 2,
                  "query": "SQLSecurityAuditEvents \r\n| where LogicalServerName == '{LogicalServerName}'\r\n| summarize by ApplicationName",
                  "crossComponentResources": [
                    "{LogAnalyticsWorkspace}"
                  ],
                  "value": null,
                  "typeSettings": {
                    "additionalResourceOptions": [],
                    "showDefault": false
                  },
                  "timeContext": {
                    "durationMs": 0
                  },
                  "timeContextFromParameter": "TimeRange",
                  "queryType": 0,
                  "resourceType": "microsoft.operationalinsights/workspaces"
                }
              ],
              "style": "pills",
              "queryType": 0,
              "resourceType": "microsoft.operationalinsights/workspaces"
            },
            "customWidth": "30",
            "name": "parameters - 1"
          },
          {
            "type": 9,
            "content": {
              "version": "KqlParameterItem/1.0",
              "parameters": [
                {
                  "id": "add4bc9a-505f-4d22-9ba2-882be91adde0",
                  "version": "KqlParameterItem/1.0",
                  "name": "QueryTextSnippet",
                  "type": 1,
                  "timeContext": {
                    "durationMs": 86400000
                  },
                  "value": ""
                },
                {
                  "id": "b78f8
Download .txt
gitextract_s92epeuo/

├── .gitignore
├── Archive/
│   └── Tools/
│       └── GetObjectsFromExplain.ps1
├── Azure_Resource_Graph_Queries/
│   ├── Inventory-DedicatedSqlPool.kql
│   ├── Inventory-SparkPools.kql
│   └── README.md
├── Distribution_Advisor/
│   ├── CreateDistributionAdvisor_PublicPreview.sql
│   ├── README.md
│   ├── RunDistributionAdvisor.sql
│   └── e2e_queries_used_for_recommendations.sql
├── LICENSE
├── Log_Analytics_queries/
│   ├── Pipelines/
│   │   ├── CompletedPipelineDurationInSeconds.kql
│   │   └── TopNLongestRunningPipelines.kql
│   ├── ServerlessSql/
│   │   ├── CostPerQuery.txt
│   │   ├── CostPerQuery.txt.bak
│   │   ├── CostPerUser.txt
│   │   └── CostPerUser.txt.bak
│   ├── Spark/
│   │   └── CoresAndMemoryByApplication.kql
│   ├── StandaloneSQLPool/
│   │   ├── CreateAnAzureSynapseDashboard.docx
│   │   ├── DedicatedSqlPoolUsage.kql
│   │   ├── LargestBroadcastSteps.kql
│   │   ├── LargestDataMovementSteps.kql
│   │   ├── LogAnalyticsBasicQueries.sql
│   │   ├── LongestBuildReplicatedTableCache
│   │   ├── MostReplicatedTableRebuilds.txt
│   │   ├── QueriesByExecutionTime.kql
│   │   ├── RepTableBuildCacheExecutionCount
│   │   ├── RowsProcessedPerHour
│   │   ├── SingletonInserts.kql
│   │   ├── TempTablesNotCreatedAsHeap.kql
│   │   └── UnionVsUnionAll.kql
│   └── WorkspacesSQLPool/
│       ├── FindLargeBroadcasts.kql
│       ├── IdentifySingletonInserts.kql
│       ├── LongestRunningQueriesByExecutionTime.kql
│       ├── QueriesWithResourceGrant.kql
│       ├── QueryList_withResultSetCacheData.kql
│       ├── TempTableASHeap.kql
│       └── UnionVsUnionAll.kql
├── Monitor_Workbooks/
│   ├── DW_Summary_v1.1.workbook
│   ├── DedicatedSQLPool_workspace_v1.2.workbook
│   ├── DedicatedSqlPool_Non-Workspace_v1.4.workbook
│   ├── README.md
│   ├── SynapsePipelines_v1.1.workbook
│   ├── SynapseServerlessWorkbook.workbook
│   └── archive/
│       ├── DW_Summary.workbook.bak
│       ├── DedicatedSQLPool_workspace_v1.0.workbook
│       ├── DedicatedSQLPool_workspace_v1.1.workbook
│       ├── DedicatedSQLPool_workspace_v1.1.workbook.bak
│       ├── DedicatedSqlPool_Non-Workspace_v1.32.workbook
│       ├── StandaloneSqlPoolWorkbook_v1.31.json
│       ├── SynapsePipelines.workbook
│       ├── SynapsePipelines.workbook.bak
│       ├── SynapsePipelines_v1.1.workbook.bak
│       ├── SynapseServerlessWorkbook.workbook
│       ├── SynapseServerlessWorkbook.workbook.bak
│       ├── SynapseWorkbook_WIP_v01.json
│       ├── SynapseWorkbook_WIP_v02.json
│       ├── SynapseWorkbook_v1.00.json
│       ├── SynapseWorkbook_v1.01.json
│       ├── SynapseWorkbook_v1.1.json
│       ├── SynapseWorkbook_v1.3.json
│       ├── WorkspaceSQLPoolWorkbook_WIP_v0.60.JSON
│       ├── WorkspaceSQLPoolWorkbook_WIP_v0.73.JSON
│       └── WorkspaceSQLPoolWorkbook_WIP_v0.77.JSON
├── PowerBI/
│   ├── README.md
│   └── Templates/
│       ├── AzureSynapse_DbHealth_08_21_20.pbit
│       ├── AzureSynapse_Permissions_07172020.pbit
│       └── AzureSynapse_Realtime_07172020.pbit
├── README.md
├── SECURITY.md
├── Synapse_Analyzer/
│   ├── README.md
│   └── Synapse_BPA_Report/
│       ├── ArchivedVersions/
│       │   ├── README.md
│       │   └── Synapse best practice analyzer_v1.0.pbit
│       ├── ForLargeDBwithCTAS/
│       │   ├── CreateTablesForSynapseAnalyzer.sql
│       │   ├── README.md
│       │   └── Synapse best practice analyzer_with_CTAS.pbit
│       ├── InstallationGuide.md
│       ├── PublishToPowerBIService.md
│       ├── README.md
│       ├── Synapse best practice analyzer.pbit
│       ├── TroubleshootingGuide.md
│       └── UpdatestoSynapseAnalyzerReport.md
├── Synapse_Toolkit/
│   ├── README.md
│   ├── SynapseToolkit.sql
│   ├── SynapseToolkit_beta.sql
│   └── SynapseToolkit_beta.sql.bak
└── TSQL_Queries/
    ├── Current_Activity/
    │   ├── CollectNodeMemoryUsage.sql
    │   ├── CountGrantedConcurrencySlots.sql
    │   ├── DMSHeavyHitters.sql
    │   ├── IdentifyBlocking1.sql
    │   ├── IdentifyBlocking2.sql
    │   ├── IdentifyResourceWaits.sql
    │   ├── MemoryGrantPerDistribution.sql
    │   ├── QueuedQueryTime.sql
    │   ├── RecentQueries.sql
    │   ├── ResourceWaitConsumptionByQuery.sql
    │   └── UsedConcurrencySlotsInfo.sql
    ├── Delta Lake/
    │   ├── README.md
    │   └── delta.sql
    ├── Identity_Columns/
    │   └── IdentityColumns.sql
    ├── Indexes/
    │   ├── CCIHealthByTable.sql
    │   ├── CCIHealthWithTrimReasons
    │   ├── CCITrimReason_BETA.sql
    │   ├── CreateRowgroupHealthView.sql
    │   ├── ReorgOrRebuildColumnstoreByPartition_All.sql
    │   └── ReorgOrRebuildColumnstore_LatestPartitionsOnly.sql
    ├── Partitions/
    │   ├── GetPartitionColumn.sql
    │   ├── MaxPartitionWithData.sql
    │   └── RowsPerPartition.sql
    ├── Permissions/
    │   └── All_Database_Permissions.sql
    ├── Query_Store/
    │   ├── GetApproxTimeRemaining_QueryStore.sql
    │   ├── GetFullQueryText.sql
    │   ├── GetQueriesWithBiggestIOReads.sql
    │   ├── GetQueriesWithMultiplePlans.sql
    │   ├── GetQueryExecutionTime.sql
    │   ├── GetQueryStoreSpaceUsage.sql
    │   ├── GetQueryStoreState.sql
    │   ├── GetRecentlyRegressedQueries.sql
    │   ├── GetTopQueriesByExecutionCount.sql
    │   ├── GetTopQueriesByExecutionTime.sql
    │   ├── PerfRegressionPlanChoiceChange.sql
    │   └── QueriesWithPerfRegression.sql
    ├── Replicated_Tables/
    │   └── RepTablesRebuildNeeded.sql
    ├── SLO-DWU/
    │   ├── ChangeDwuSetting.sql
    │   ├── CheckDwuChangeStatus.sql
    │   ├── CreateColumnstoreDensityView.sql
    │   └── GetDwuSetting.sql
    ├── ServerlessSql/
    │   └── CostPerQuery.sql
    ├── Statistics/
    │   ├── CheckAutoStatsEnabled.sql
    │   ├── CreateSP_CreateStatsAllColumnsAllTables.sql
    │   ├── CreateSP_GenUpdateStatsStatements.sql
    │   ├── CreateStatsAllColumnsAllTables.sql
    │   ├── GetStatsLastUpdateDate.sql
    │   ├── ListAllStats.sql
    │   ├── ListAllStats.sql.bak
    │   └── StatisticsAccuracy.sql
    ├── Table_Information/
    │   ├── CollectTableInformation.sql
    │   ├── CreateTableInfoView.sql
    │   ├── DataTypeMismatch.sql
    │   ├── DistributionSpaceSummary.sql
    │   ├── FindNullableDistColumns.sql
    │   ├── GenerateTableSchemas.sql
    │   ├── IdentifyLargeDataTypes.sql
    │   ├── MostUsedTables_BETA.sql
    │   ├── TableSizeByDistType.sql
    │   ├── TableSizeByIndexType.sql
    │   ├── TableSizeSummary.sql
    │   ├── TableSkew.sql
    │   ├── TableUsageInformation.sql
    │   └── TablesWithMostLargeTypes.sql
    ├── TempDB/
    │   ├── TempDbPerNode.sql
    │   ├── TempDbPerQuery.sql
    │   └── TotalTempDbUsage.sql
    ├── Workarounds/
    │   └── RecursionWorkaround_HierarchicalTableSample.sql
    └── Workload_Management/
        ├── CurrentRoleByUser.sql
        ├── ViewWorkloadGroups.sql
        └── WorkloadManagementMappingsAndUsage.sql
Download .txt
SYMBOL INDEX (8 symbols across 7 files)

FILE: TSQL_Queries/Delta Lake/delta.sql
  type last_checkpoint (line 80) | create table #last_checkpoint

FILE: TSQL_Queries/Indexes/CreateRowgroupHealthView.sql
  type dbo (line 10) | create view dbo.vCS_rg_physical_stats

FILE: TSQL_Queries/SLO-DWU/CreateColumnstoreDensityView.sql
  type dbo (line 11) | CREATE VIEW dbo.vColumnstoreDensity

FILE: TSQL_Queries/Statistics/CreateSP_CreateStatsAllColumnsAllTables.sql
  type stats_ddl (line 51) | CREATE TABLE #stats_ddl

FILE: TSQL_Queries/Statistics/CreateStatsAllColumnsAllTables.sql
  type stats_ddl (line 38) | CREATE TABLE #stats_ddl

FILE: TSQL_Queries/Table_Information/CreateTableInfoView.sql
  type dbo (line 4) | CREATE VIEW dbo.vTableSizes

FILE: TSQL_Queries/Workarounds/RecursionWorkaround_HierarchicalTableSample.sql
  type dbo (line 7) | CREATE TABLE dbo.Employee (
  type employee (line 87) | CREATE TABLE #employee
Condensed preview — 156 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (2,824K chars).
[
  {
    "path": ".gitignore",
    "chars": 5582,
    "preview": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n##\n## G"
  },
  {
    "path": "Archive/Tools/GetObjectsFromExplain.ps1",
    "chars": 3153,
    "preview": "<# Get_Objects_From_Explain.ps1\n    \n    Author: Nick.salch@Microsoft.com (Nicksalc)\n    This tool will take in an expl"
  },
  {
    "path": "Azure_Resource_Graph_Queries/Inventory-DedicatedSqlPool.kql",
    "chars": 1552,
    "preview": "Resources\n| where type == 'microsoft.sql/servers'\n| project name, id, resourceGroup, location, subscriptionId, tags\n| jo"
  },
  {
    "path": "Azure_Resource_Graph_Queries/Inventory-SparkPools.kql",
    "chars": 1439,
    "preview": "Resources\n| where type == \"microsoft.synapse/workspaces/bigdatapools\"\n| project name, id, resourceGroup, location, subsc"
  },
  {
    "path": "Azure_Resource_Graph_Queries/README.md",
    "chars": 2598,
    "preview": "# Azure Synapse Inventory via Azure Resource Graph\nThe following [Azure Resource Graph](https://azure.microsoft.com/en-u"
  },
  {
    "path": "Distribution_Advisor/CreateDistributionAdvisor_PublicPreview.sql",
    "chars": 12329,
    "preview": "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.write_dist_recommendation'))\r\n\tDROP PROCEDURE dbo"
  },
  {
    "path": "Distribution_Advisor/README.md",
    "chars": 171,
    "preview": "# Distirbution Advisor\n\nPlease follow [these instructions](https://docs.microsoft.com/en-us/azure/synapse-analytics/sql/"
  },
  {
    "path": "Distribution_Advisor/RunDistributionAdvisor.sql",
    "chars": 1853,
    "preview": "\n-- *******************************************************************************************\n-- This portion is for a"
  },
  {
    "path": "Distribution_Advisor/e2e_queries_used_for_recommendations.sql",
    "chars": 1415,
    "preview": "DECLARE @NumMaxQueries int = 100; -- change this to match the variable in mvp script; looks at different numbers of quer"
  },
  {
    "path": "LICENSE",
    "chars": 1162,
    "preview": "    MIT License\n\n    Copyright (c) Microsoft Corporation. All rights reserved.\n\n    Permission is hereby granted, free o"
  },
  {
    "path": "Log_Analytics_queries/Pipelines/CompletedPipelineDurationInSeconds.kql",
    "chars": 525,
    "preview": "// Pipeline Durations in Seconds\nSynapseIntegrationPipelineRuns\n| where Status in ('Succeeded', 'Failed')\n| extend Pipel"
  },
  {
    "path": "Log_Analytics_queries/Pipelines/TopNLongestRunningPipelines.kql",
    "chars": 1028,
    "preview": "// Synapse Pipelines - Chart - Top N Longest Running Pipelines\n// N == 5 \nSynapseIntegrationActivityRuns \n| extend e_Res"
  },
  {
    "path": "Log_Analytics_queries/ServerlessSql/CostPerQuery.txt",
    "chars": 864,
    "preview": "//Cost per query\nSynapseBuiltinSqlPoolRequestsEnded\n//| where _ResourceId has 'contosoprod'\n| project \n    BytesProcesse"
  },
  {
    "path": "Log_Analytics_queries/ServerlessSql/CostPerQuery.txt.bak",
    "chars": 937,
    "preview": "//Cost per query\nSynapseBuiltinSqlPoolRequestsEnded\n//| where _ResourceId has 'contosoprod'\n| project \n    BytesProcesse"
  },
  {
    "path": "Log_Analytics_queries/ServerlessSql/CostPerUser.txt",
    "chars": 536,
    "preview": "//Query cost by User\nSynapseBuiltinSqlPoolRequestsEnded\n//| where _ResourceId has 'contosoprod'\n| project BytesProcessed"
  },
  {
    "path": "Log_Analytics_queries/ServerlessSql/CostPerUser.txt.bak",
    "chars": 592,
    "preview": "//Query cost by User\nSynapseBuiltinSqlPoolRequestsEnded\n//| where _ResourceId has 'contosoprod'\n| project BytesProcessed"
  },
  {
    "path": "Log_Analytics_queries/Spark/CoresAndMemoryByApplication.kql",
    "chars": 191,
    "preview": "SparkListenerEvent_CL\n| summarize Total_vCores_Used=sum(Executor_Info_Total_Cores_d), Total_Memory_Used_GB=sum(Maximum_M"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/DedicatedSqlPoolUsage.kql",
    "chars": 1213,
    "preview": "// Intended to aid cost management of dedicated SQL pools\n// Set the UsageBucket to the level of granularity desired e.g"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/LargestBroadcastSteps.kql",
    "chars": 282,
    "preview": "let databaseName=\"<databaseNameAllCaps>\";\nAzureDiagnostics\n| where Resource == databaseName\n| where Category == 'Request"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/LargestDataMovementSteps.kql",
    "chars": 484,
    "preview": "//Most Rows Moved by step\n// These are the largest data movement steps. Use this to identify a request ID to investigate"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/LogAnalyticsBasicQueries.sql",
    "chars": 3720,
    "preview": "//List all queries \nAzureDiagnostics\n| where Category  == \"ExecRequests\"\n| project TimeGenerated , ErrorId_g , RequestId"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/LongestBuildReplicatedTableCache",
    "chars": 2451,
    "preview": "let databaseName = '<database_name>';\n//Longest running BuildReplicatedTableCache\nAzureDiagnostics\n| where Category  == "
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/MostReplicatedTableRebuilds.txt",
    "chars": 464,
    "preview": "let databaseName = '<database_name>';\nAzureDiagnostics\n| where Category == 'ExecRequests'\n| where Resource == databaseNa"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/QueriesByExecutionTime.kql",
    "chars": 728,
    "preview": "//Queries by Execution Time\nlet databaseName = '<databaseName_ALL_CAPS>';\nAzureDiagnostics \n| where Category  == 'ExecRe"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/RepTableBuildCacheExecutionCount",
    "chars": 487,
    "preview": "let databaseName = '<database_name>';\n//Build cache count by day\nAzureDiagnostics\n| where Category  == 'ExecRequests'\n| "
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/RowsProcessedPerHour",
    "chars": 255,
    "preview": "let databaseName = '<database_name>';\n//rows processed per hour\nAzureDiagnostics\n| where Category  == 'RequestSteps'\n| w"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/SingletonInserts.kql",
    "chars": 1048,
    "preview": "//This query identifies Sessions with large numbers of insert statements, including the max rows inserted. It is mainly "
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/TempTablesNotCreatedAsHeap.kql",
    "chars": 1264,
    "preview": "let databaseName = 'DatabaseName_AllCaps';\n//Long-Running Queries - Just Actual Queries\n//If 'Command' is empty - you ne"
  },
  {
    "path": "Log_Analytics_queries/StandaloneSQLPool/UnionVsUnionAll.kql",
    "chars": 891,
    "preview": "let databaseName = '<databaseNameAllCaps>';\n//Usage of Union vs Union ALL - this query is approximate since query text i"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/FindLargeBroadcasts.kql",
    "chars": 272,
    "preview": "let databaseName=\"<database_name>\";\nSynapseSqlPoolRequestSteps\n| where _ResourceId endswith databaseName\n| where Operati"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/IdentifySingletonInserts.kql",
    "chars": 568,
    "preview": "//This query identifies Sessions with large numbers of insert statements, including the max rows inserted. It is mainly "
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/LongestRunningQueriesByExecutionTime.kql",
    "chars": 1056,
    "preview": "//Long-Running Queries\nlet databaseName = '1';\nSynapseSqlPoolExecRequests\n| where _ResourceId  endswith databaseName\n| w"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/QueriesWithResourceGrant.kql",
    "chars": 6574,
    "preview": "//Queries including SLO and resource grant % until the resource grant % field is avaialble in log analytics covers DW500"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/QueryList_withResultSetCacheData.kql",
    "chars": 1020,
    "preview": "//Query List with ResultSetCache data\nlet databaseName = 'syntheticworkload';\nSynapseSqlPoolExecRequests\n| where _Resour"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/TempTableASHeap.kql",
    "chars": 1160,
    "preview": "let databaseName = '<database_name>';\n//If 'Command' is empty - you need to set a bigger time window, the older record w"
  },
  {
    "path": "Log_Analytics_queries/WorkspacesSQLPool/UnionVsUnionAll.kql",
    "chars": 736,
    "preview": "//Usage of Union vs Union ALL\nlet databaseName = '<database_name>';\nSynapseSqlPoolExecRequests\n| where _ResourceId  ends"
  },
  {
    "path": "Monitor_Workbooks/DW_Summary_v1.1.workbook",
    "chars": 37335,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/DedicatedSQLPool_workspace_v1.2.workbook",
    "chars": 153273,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/DedicatedSqlPool_Non-Workspace_v1.4.workbook",
    "chars": 129003,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/README.md",
    "chars": 2312,
    "preview": "# Monitor Synapse\nUse this template to monitor your dedicated SQL Pools. \nIf you have an instance that was created withi"
  },
  {
    "path": "Monitor_Workbooks/SynapsePipelines_v1.1.workbook",
    "chars": 51647,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/SynapseServerlessWorkbook.workbook",
    "chars": 50780,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/DW_Summary.workbook.bak",
    "chars": 19134,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/DedicatedSQLPool_workspace_v1.0.workbook",
    "chars": 146306,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/DedicatedSQLPool_workspace_v1.1.workbook",
    "chars": 153707,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/DedicatedSQLPool_workspace_v1.1.workbook.bak",
    "chars": 153707,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/DedicatedSqlPool_Non-Workspace_v1.32.workbook",
    "chars": 127381,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/StandaloneSqlPoolWorkbook_v1.31.json",
    "chars": 128703,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapsePipelines.workbook",
    "chars": 46715,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapsePipelines.workbook.bak",
    "chars": 46715,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapsePipelines_v1.1.workbook.bak",
    "chars": 46709,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseServerlessWorkbook.workbook",
    "chars": 37173,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseServerlessWorkbook.workbook.bak",
    "chars": 37361,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_WIP_v01.json",
    "chars": 66436,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_WIP_v02.json",
    "chars": 66945,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_v1.00.json",
    "chars": 84715,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_v1.01.json",
    "chars": 84884,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_v1.1.json",
    "chars": 102910,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/SynapseWorkbook_v1.3.json",
    "chars": 128667,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/WorkspaceSQLPoolWorkbook_WIP_v0.60.JSON",
    "chars": 124236,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/WorkspaceSQLPoolWorkbook_WIP_v0.73.JSON",
    "chars": 141773,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "Monitor_Workbooks/archive/WorkspaceSQLPoolWorkbook_WIP_v0.77.JSON",
    "chars": 145701,
    "preview": "{\n  \"version\": \"Notebook/1.0\",\n  \"items\": [\n    {\n      \"type\": 9,\n      \"content\": {\n        \"version\": \"KqlParameterIt"
  },
  {
    "path": "PowerBI/README.md",
    "chars": 1354,
    "preview": "# This template is a work in progress and is not yet meant for use in production\n\nThis template is a work in progress, b"
  },
  {
    "path": "README.md",
    "chars": 4874,
    "preview": "# Azure Synapse Toolbox     \n![CSELogo.png](https://github.com/microsoft/Azure_Synapse_Toolbox/blob/master/Collateral/CS"
  },
  {
    "path": "SECURITY.md",
    "chars": 2757,
    "preview": "<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->\n\n## Security\n\nMicrosoft takes the security of our software products an"
  },
  {
    "path": "Synapse_Analyzer/README.md",
    "chars": 2108,
    "preview": "# Azure Synapse Analyzer Report\n\nThe Azure Synapse Analyzer Report was created to help you identify common issues that m"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/ArchivedVersions/README.md",
    "chars": 194,
    "preview": "# Archived Folder for older versions of the report\n\nThis folder is to keep older versions of Synapse Analyzer Report. \n\n"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/ForLargeDBwithCTAS/CreateTablesForSynapseAnalyzer.sql",
    "chars": 18962,
    "preview": "-- Create Separate Schema For loading all Tables \nCREATE SCHEMA SynapseAnalyzer\nGO \n\n-- All_Tables\n\nIF Exists(SELECT [na"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/ForLargeDBwithCTAS/README.md",
    "chars": 2697,
    "preview": "# Synapse Analyzer Report – for XL data warehouses.\n\n## CTAS version for XL data warehouses\nWith this update we are also"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/InstallationGuide.md",
    "chars": 3080,
    "preview": "# Using Power BI Template (.pbit) for Synapse Best Practice Report\n\nYou can install and use Power BI Desktop to access P"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/PublishToPowerBIService.md",
    "chars": 2969,
    "preview": "# Publish Azure Synapse Analyzer Report to Power BI service\n\nWhile you can use Power BI desktop to refresh and view Azur"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/README.md",
    "chars": 9440,
    "preview": "# Azure Synapse Analyzer Report to monitor and improve Synapse Dedicated Pool performance\n\nThe Azure Synapse Analyzer Re"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/TroubleshootingGuide.md",
    "chars": 5780,
    "preview": "# Troubleshooting errors when refreshing report from Power BI Desktop\n\nDuring the refresh you may encounter Errors. This"
  },
  {
    "path": "Synapse_Analyzer/Synapse_BPA_Report/UpdatestoSynapseAnalyzerReport.md",
    "chars": 11647,
    "preview": "# Updates to Synapse Analyzer Report – Workload Management and support for XL data warehouses.\n\nIn May 2022 we released "
  },
  {
    "path": "Synapse_Toolkit/README.md",
    "chars": 4837,
    "preview": "# Synapse Toolkit\n\n\tThe Synapse Toolkit is a set of stored procedures that help investigate\n\tcurrent activity on your Sy"
  },
  {
    "path": "Synapse_Toolkit/SynapseToolkit.sql",
    "chars": 18322,
    "preview": "/***************************************************************************\n\tSynapse Toolkit v1.1, 06/13/22 \n\t\n\tThe Syn"
  },
  {
    "path": "Synapse_Toolkit/SynapseToolkit_beta.sql",
    "chars": 23337,
    "preview": "/***************************************************************************\n\tSynapse Toolkit \n\t\n\tThe Synapse Toolkit is"
  },
  {
    "path": "Synapse_Toolkit/SynapseToolkit_beta.sql.bak",
    "chars": 22886,
    "preview": "/***************************************************************************\n\tSynapse Toolkit \n\t\n\tThe Synapse Toolkit is"
  },
  {
    "path": "TSQL_Queries/Current_Activity/CollectNodeMemoryUsage.sql",
    "chars": 1050,
    "preview": "/*\n\t===============================\n\t   Node Memory Usage\n\t===============================\n\tThe following query will sho"
  },
  {
    "path": "TSQL_Queries/Current_Activity/CountGrantedConcurrencySlots.sql",
    "chars": 490,
    "preview": "/*\n\t===============================\n\t   Granted Concurrency Slots\n\t===============================\n\tThe following query "
  },
  {
    "path": "TSQL_Queries/Current_Activity/DMSHeavyHitters.sql",
    "chars": 1385,
    "preview": "/*\n\t==========================\n\t   DMS Heavy Hitters\n\t==========================\n\tThe following query returns queries th"
  },
  {
    "path": "TSQL_Queries/Current_Activity/IdentifyBlocking1.sql",
    "chars": 587,
    "preview": "/*\n\t==========================\n\t   Identify Blocking 1\n\t==========================\n\tThis query looks for any queries tha"
  },
  {
    "path": "TSQL_Queries/Current_Activity/IdentifyBlocking2.sql",
    "chars": 2472,
    "preview": " /*\n\t==========================\n\t   Identify Blocking 2\n\t==========================\n\tNOTE: THIS QUERY IS NOT 100% ACCURA"
  },
  {
    "path": "TSQL_Queries/Current_Activity/IdentifyResourceWaits.sql",
    "chars": 1563,
    "preview": "/*\n\t=============================\n\t   Identify Resource Waits\n\t=============================\n\tThe following query can be"
  },
  {
    "path": "TSQL_Queries/Current_Activity/MemoryGrantPerDistribution.sql",
    "chars": 1305,
    "preview": "/*\n\t===================================\n\t   Memory Grant Per Distribution\n\t===================================\n\tThis que"
  },
  {
    "path": "TSQL_Queries/Current_Activity/QueuedQueryTime.sql",
    "chars": 867,
    "preview": "/*\n\t=======================\n\t   Queued Query Time\n\t=======================\n\tThe following query looks for queries that h"
  },
  {
    "path": "TSQL_Queries/Current_Activity/RecentQueries.sql",
    "chars": 1213,
    "preview": "--Recently ran queries still in exec_requests\nSELECT r.[session_id]\n\t,r.[request_id]\n\t,r.[status]\n\t,s.[login_name]\n\t,r.["
  },
  {
    "path": "TSQL_Queries/Current_Activity/ResourceWaitConsumptionByQuery.sql",
    "chars": 766,
    "preview": "/*\n\t========================================\n\t   Resource Wait Consumption by Query\n\t==================================="
  },
  {
    "path": "TSQL_Queries/Current_Activity/UsedConcurrencySlotsInfo.sql",
    "chars": 687,
    "preview": "/*\n\t=================================\n\t   Used Concurrency Slots Info\n\t=================================\n\tThe following "
  },
  {
    "path": "TSQL_Queries/Delta Lake/README.md",
    "chars": 2162,
    "preview": "# Reading Delta Lake\n\n    This stored procedure reads Delta Lake, it supports time travel but does not support schema dr"
  },
  {
    "path": "TSQL_Queries/Delta Lake/delta.sql",
    "chars": 13730,
    "preview": "/*\nIF OBJECT_ID('mpmtest') IS NOT NULL\n  BEGIN;\n\tDROP TABLE mpmtest\nEND\n\ndeclare @path varchar(400), @dt datetime2, @cre"
  },
  {
    "path": "TSQL_Queries/Identity_Columns/IdentityColumns.sql",
    "chars": 863,
    "preview": "/*\n\t======================\n\t   Identity Columns\n\t======================\n\tThis query will return information about identi"
  },
  {
    "path": "TSQL_Queries/Indexes/CCIHealthByTable.sql",
    "chars": 2883,
    "preview": "/*\n\t=================================================\n\t   Clustered Columnstore Index Health by Table\n\t================"
  },
  {
    "path": "TSQL_Queries/Indexes/CCIHealthWithTrimReasons",
    "chars": 3634,
    "preview": "*\n\t=================================================\n\t   Clustered Columnstore Index Health by Table\n\t=================="
  },
  {
    "path": "TSQL_Queries/Indexes/CCITrimReason_BETA.sql",
    "chars": 1347,
    "preview": "/*\n\t=================================\n\t   CCI Trim Reason\n\t=================================\n\tThis query reports the Tr"
  },
  {
    "path": "TSQL_Queries/Indexes/CreateRowgroupHealthView.sql",
    "chars": 1581,
    "preview": "/*\n\t=================================\n\t   Create Rowgroup Health View\n\t=================================\n\tThis query wil"
  },
  {
    "path": "TSQL_Queries/Indexes/ReorgOrRebuildColumnstoreByPartition_All.sql",
    "chars": 1577,
    "preview": "/*\n\t============================================\n\t   Rebuild Columnstore Index By partition\n\t==========================="
  },
  {
    "path": "TSQL_Queries/Indexes/ReorgOrRebuildColumnstore_LatestPartitionsOnly.sql",
    "chars": 2277,
    "preview": "/*\n\t============================================\n\t   Rebuild Columnstore Index By partiiton\n\t==========================="
  },
  {
    "path": "TSQL_Queries/Partitions/GetPartitionColumn.sql",
    "chars": 296,
    "preview": "select c.name\nfrom sys.index_columns ic\njoin sys.tables t on t.object_id = ic.object_id\njoin sys.columns c\non c.object_i"
  },
  {
    "path": "TSQL_Queries/Partitions/MaxPartitionWithData.sql",
    "chars": 1619,
    "preview": "/*\n\t=============================\n\t   Max Parititon With Data\n\t=============================\n\tThis query will use sys.dm"
  },
  {
    "path": "TSQL_Queries/Partitions/RowsPerPartition.sql",
    "chars": 1438,
    "preview": "/*\n\t=============================\n\t   Row count per partition\n\t=============================\n\tThis query will use sys.dm"
  },
  {
    "path": "TSQL_Queries/Permissions/All_Database_Permissions.sql",
    "chars": 3201,
    "preview": "--This query will list ALL PERMISSIONS in the database. It includes permissions granted to principals through role membe"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetApproxTimeRemaining_QueryStore.sql",
    "chars": 1351,
    "preview": "--Calculate approximate time remaining for running queries based on hits on teh query text in query store. \nSELECT\nreq.s"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetFullQueryText.sql",
    "chars": 398,
    "preview": "/*\n\t===============================\n\t   Get Full Query Text\n\t===============================\n\tThe following query will c"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetQueriesWithBiggestIOReads.sql",
    "chars": 995,
    "preview": "/*\n\t========================================================\n\t   Get Queries with biggest IO Reads in last 24 hours\n\t==="
  },
  {
    "path": "TSQL_Queries/Query_Store/GetQueriesWithMultiplePlans.sql",
    "chars": 1118,
    "preview": "/*\n\t========================================================\n\t   Get Queries with Multiple plans\n\t======================"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetQueryExecutionTime.sql",
    "chars": 884,
    "preview": "/*\n\t======================================\n\t   Find exeuction times for a query\n\t======================================\n"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetQueryStoreSpaceUsage.sql",
    "chars": 423,
    "preview": "/*\n\t========================================================\n\t   Get Query Store Space Usage\n\t=========================="
  },
  {
    "path": "TSQL_Queries/Query_Store/GetQueryStoreState.sql",
    "chars": 438,
    "preview": "/*\n\t========================================================\n\t   Get QUery Store State\n\t================================"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetRecentlyRegressedQueries.sql",
    "chars": 1666,
    "preview": "/*\n\t========================================================\n\t   Get Recently Regressed Queries\n\t======================="
  },
  {
    "path": "TSQL_Queries/Query_Store/GetTopQueriesByExecutionCount.sql",
    "chars": 660,
    "preview": "/*\n\t====================================\n\t   Top Queries By Execution Count\n\t====================================\n\tThe f"
  },
  {
    "path": "TSQL_Queries/Query_Store/GetTopQueriesByExecutionTime.sql",
    "chars": 750,
    "preview": "/*\n\t====================================\n\t   Top Queries By Execution Time\n\t====================================\n\tThe fo"
  },
  {
    "path": "TSQL_Queries/Query_Store/PerfRegressionPlanChoiceChange.sql",
    "chars": 1557,
    "preview": "/*\n\t======================================\n\t   Perf Regression with plan change\n\t======================================\n"
  },
  {
    "path": "TSQL_Queries/Query_Store/QueriesWithPerfRegression.sql",
    "chars": 1500,
    "preview": "/*\n\t======================================\n\t   Queries with Perf Regression\n\t======================================\n\tThe"
  },
  {
    "path": "TSQL_Queries/Replicated_Tables/RepTablesRebuildNeeded.sql",
    "chars": 817,
    "preview": "/*\t\n\t================================\n\t   Replicated Tables Modified\n\t   but not rebuilt\n\t============================="
  },
  {
    "path": "TSQL_Queries/SLO-DWU/ChangeDwuSetting.sql",
    "chars": 368,
    "preview": "/*\n\t========================\n\t   Change DWU Setting\n\t========================\n\tThis query will set the DWU setting to th"
  },
  {
    "path": "TSQL_Queries/SLO-DWU/CheckDwuChangeStatus.sql",
    "chars": 470,
    "preview": "/*\n\t================================\n\t   Check Status of DWU Change\n\t================================\n\tThis query will c"
  },
  {
    "path": "TSQL_Queries/SLO-DWU/CreateColumnstoreDensityView.sql",
    "chars": 4364,
    "preview": "/*\n\t=====================================\n\t   Create Columnstore Density View\n\t=====================================\n\tTh"
  },
  {
    "path": "TSQL_Queries/SLO-DWU/GetDwuSetting.sql",
    "chars": 509,
    "preview": "/*\n\t=============================\n\t   Get Current DWU Setting\n\t=============================\n\tThis query will return the"
  },
  {
    "path": "TSQL_Queries/ServerlessSql/CostPerQuery.sql",
    "chars": 1186,
    "preview": "SELECT \n\n       ERH.status as [status],\n\n       ERH.login_name as [login_name],\n\n       ERH.start_time as [start_time],\n"
  },
  {
    "path": "TSQL_Queries/Statistics/CheckAutoStatsEnabled.sql",
    "chars": 164,
    "preview": "SELECT name, is_auto_create_stats_on \nFROM sys.databases\n\n--To turn on auto create stats:\n--ALTER DATABASE <yourdatawar"
  },
  {
    "path": "TSQL_Queries/Statistics/CreateSP_CreateStatsAllColumnsAllTables.sql",
    "chars": 3784,
    "preview": "/*\n\t=======================================================\n\t   Create SP for Create Stats all columns all tables \n\t===="
  },
  {
    "path": "TSQL_Queries/Statistics/CreateSP_GenUpdateStatsStatements.sql",
    "chars": 3592,
    "preview": "/*\n\t=======================================================\n\t   Create SP for Update Stats all columns all tables \n\t===="
  },
  {
    "path": "TSQL_Queries/Statistics/CreateStatsAllColumnsAllTables.sql",
    "chars": 3566,
    "preview": "/*\n\t=================================================\n\t   Create Statistics on all columns all tables \n\t================"
  },
  {
    "path": "TSQL_Queries/Statistics/GetStatsLastUpdateDate.sql",
    "chars": 1370,
    "preview": "/*\n\t=====================================\n\t   Get Statistics Last Update Date \n\t=====================================\n\n\t"
  },
  {
    "path": "TSQL_Queries/Statistics/ListAllStats.sql",
    "chars": 784,
    "preview": "--Get all stats that exist\n\nSelect \n    db_name() as [Database]\n    , sch.name as [Schema]\n    , t.name as [Table]\n    ,"
  },
  {
    "path": "TSQL_Queries/Statistics/ListAllStats.sql.bak",
    "chars": 722,
    "preview": "--Get all stats that exist\n\nSelect \n    db_name() as [Database]\n    , sch.name as [Schema]\n    , t.name as [Table]\n    ,"
  },
  {
    "path": "TSQL_Queries/Statistics/StatisticsAccuracy.sql",
    "chars": 2129,
    "preview": "select \nobjIdsWithStats.[object_id], \nactualRowCounts.[schema], \nactualRowCounts.logical_table_name, \nstatsRowCounts.sta"
  },
  {
    "path": "TSQL_Queries/Table_Information/CollectTableInformation.sql",
    "chars": 713,
    "preview": "--Table Information query\nSELECT\n\tt.name AS 'Table_Name',\n\tt.object_id,\n\tt.create_date,\n\tt.modify_date,\n\tptdp.Distribut"
  },
  {
    "path": "TSQL_Queries/Table_Information/CreateTableInfoView.sql",
    "chars": 5613,
    "preview": "--Create Table information view for use with various other queries\n--pulled from: https://docs.microsoft.com/en-us/azur"
  },
  {
    "path": "TSQL_Queries/Table_Information/DataTypeMismatch.sql",
    "chars": 780,
    "preview": "SET NOCOUNT ON; \n--Identify columns that have the same name, but different data types or data lengths\nWITH Query as \n(\n\t"
  },
  {
    "path": "TSQL_Queries/Table_Information/DistributionSpaceSummary.sql",
    "chars": 695,
    "preview": "--Distribution Space Summary\n--PRE-REQUISITE: must have the table info view created\n--FROM: https://docs.microsoft.com/"
  },
  {
    "path": "TSQL_Queries/Table_Information/FindNullableDistColumns.sql",
    "chars": 895,
    "preview": "/*\n\t========================================\n\t   Find Nullable Distribution Columns\n\t=================================="
  },
  {
    "path": "TSQL_Queries/Table_Information/GenerateTableSchemas.sql",
    "chars": 3286,
    "preview": "--Generate Schemas of all tables\n--This is an early release that may not cover all data types or table structures and sh"
  },
  {
    "path": "TSQL_Queries/Table_Information/IdentifyLargeDataTypes.sql",
    "chars": 347,
    "preview": "SET NOCOUNT ON;\n--This query will just collect the largest data types it can find in the database. \n--You can change the"
  },
  {
    "path": "TSQL_Queries/Table_Information/MostUsedTables_BETA.sql",
    "chars": 992,
    "preview": "--This query joins the index usage stats from all nodes to determine which tables are the most used. \nSELECT \n\ts.name\n\t"
  },
  {
    "path": "TSQL_Queries/Table_Information/TableSizeByDistType.sql",
    "chars": 633,
    "preview": "--Table size by distribution type\n--PRE-REQUISITE: must have table info view created already\n--pulled from: https://doc"
  },
  {
    "path": "TSQL_Queries/Table_Information/TableSizeByIndexType.sql",
    "chars": 604,
    "preview": "--Table space by index type\n--PRE-REQUISITE: MUST HAVE TABLE INFO VIEW CREATED ALREADY\n--SOURCE: https://docs.microsoft"
  },
  {
    "path": "TSQL_Queries/Table_Information/TableSizeSummary.sql",
    "chars": 893,
    "preview": "--Table size summary\n--PRE-REQUISITE: CREATE THE TABLE INFO VIEW FIRST\n--SOURCE: https://docs.microsoft.com/en-us/azure"
  },
  {
    "path": "TSQL_Queries/Table_Information/TableSkew.sql",
    "chars": 845,
    "preview": "/*\n\t========================================\n\t   Find tables with data skew over 10%\n\t================================="
  },
  {
    "path": "TSQL_Queries/Table_Information/TableUsageInformation.sql",
    "chars": 712,
    "preview": "SELECT \n    s.name AS SchemaName\n    , t.name AS TableName\n    , MAX(i.last_user_seek) as Last_seek\n    , MAX(i.last_use"
  },
  {
    "path": "TSQL_Queries/Table_Information/TablesWithMostLargeTypes.sql",
    "chars": 268,
    "preview": "SET NOCOUNT ON; \n--This query will find tables with the most number of large types\nSELECT TABLE_SCHEMA,TABLE_NAME, COUNT"
  },
  {
    "path": "TSQL_Queries/TempDB/TempDbPerNode.sql",
    "chars": 700,
    "preview": "--Tempdb usage per node\nSELECT \n\t'TempDB per node' AS 'TempDB per node'\n\t,pdw.pdw_node_id\n\t,n.type\n\t,sum(pdw.bytes_proce"
  },
  {
    "path": "TSQL_Queries/TempDB/TempDbPerQuery.sql",
    "chars": 569,
    "preview": "--Tempdb usage per query\nSELECT \n\t'TempDB per query' AS 'TempDB per query'\n\t,req.request_id\n\t,sum(pdw.bytes_processed) a"
  },
  {
    "path": "TSQL_Queries/TempDB/TotalTempDbUsage.sql",
    "chars": 753,
    "preview": "--Total TempDB Usage\nSELECT\n\t'Total TempDB usage' AS 'Total TempDB usage'\n\t,sum(pdw.rows_processed) as 'rows_written'\n\t,"
  },
  {
    "path": "TSQL_Queries/Workarounds/RecursionWorkaround_HierarchicalTableSample.sql",
    "chars": 3019,
    "preview": "SET\n    NOCOUNT ON \n\tDROP TABLE dbo.Employee;\n\nGO\n\nCREATE TABLE dbo.Employee (\n    EmployeeId BIGINT NOT NULL,\n    Emplo"
  },
  {
    "path": "TSQL_Queries/Workload_Management/CurrentRoleByUser.sql",
    "chars": 615,
    "preview": "/*\n\t==========================\n\t   Current Role By User\n\t==========================\n\tThe following query returns what DW"
  },
  {
    "path": "TSQL_Queries/Workload_Management/ViewWorkloadGroups.sql",
    "chars": 2204,
    "preview": "/*\n\t=========================\n\t   View Workload Groups\n\t=========================\n\tThe following query shows details of "
  },
  {
    "path": "TSQL_Queries/Workload_Management/WorkloadManagementMappingsAndUsage.sql",
    "chars": 1290,
    "preview": "--Mapping details per classifier + effective grants + specified grants\nSELECT * FROM \n(SELECT \n    wc.name AS 'Classifie"
  }
]

// ... and 7 more files (download for full content)

About this extraction

This page contains the full source code of the microsoft/Azure_Synapse_Toolbox GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 156 files (2.5 MB), approximately 663.6k tokens, and a symbol index with 8 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!