Skip to content

Instantly share code, notes, and snippets.

View MarkPryceMaherMSFT's full-sized avatar

Mark Pryce-Maher MarkPryceMaherMSFT

View GitHub Profile
import struct
import pyodbc
import pandas as pd
from azure.identity import ClientSecretCredential
import jwt
tenant_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "Nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / dmvs.sql
Created May 21, 2026 23:19
dmvs - some dmvs
-- https://learn.microsoft.com/en-us/fabric/data-warehouse/monitor-using-dmv
-- connections/sessions/queries
select * from sys.dm_exec_connections;
select * from sys.dm_exec_sessions;
select * from sys.dm_exec_requests;
select * from sys.dm_exec_query_stats;
-- query text
select st.text
FROM sys.dm_exec_requests r
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / tpc-h-10tb-100percentpool.csv
Last active May 1, 2026 15:22
tpc-h-10tb-100percentpool
10TB dataset
Pool Size: 100%
Query Not Read Optimized Read Optimized Improvement
Q1 5.408 0.975 5.5x
Q2 35.304 5.333 6.6x
Q3 84.184 8.026 10.5x
Q4 49.687 10.474 4.7x
Q5 104.358 18.64 5.6x
Q6 16.753 0.398 42.1x
Q7 75.211 4.46 16.9x
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / summary_results.csv
Created May 1, 2026 12:06
The timings for tpc-h 10tb - call outs
Not Read-Optimized Read-Optimized Speedup
Q1 5.408s 0.975s 5.5x
Q6 16.753s 0.398s 42x
Q17 161.288s 26.192s 6.2x
Q18 99.039s 9.500s 10.4x
Q21 147.082s 21.298s 6.9x
Overall 4894.60s 634.39s ~7.7x
CREATE FUNCTION dbo.ConvertUtcToFixedOffset
(
@UtcTime DATETIME,
@TimeZoneName VARCHAR(100)
)
RETURNS DATETIME
AS
BEGIN
DECLARE @OffsetMinutes INT;
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / create_offset_table.sql
Last active April 15, 2026 12:06
Create a table with consistent timezone offsets
--DROP TABLE dbo.TimeZoneOffsets
CREATE TABLE dbo.TimeZoneOffsets (
TimeZoneName VARCHAR(100) ,
OffsetMinutes INT
);
INSERT INTO dbo.TimeZoneOffsets (TimeZoneName, OffsetMinutes)
VALUES
-- UTC
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / update_indexes.sql
Created March 18, 2026 16:49
Simple script to update all the stats
DECLARE @sql NVARCHAR(MAX) = N'';
SELECT @sql +=
'BEGIN TRY '+ CHAR(13) + ' UPDATE STATISTICS [' + s.name + '].[' + t.name + '] [' + st.name + '] WITH FULLSCAN;' + CHAR(13) + 'END TRY' + CHAR(13)+ ' BEGIN CATCH' + CHAR(13) + ' PRINT ''Failed to update statistics on [' + s.name + '].[' + t.name + '] [' + st.name + ']'';' + CHAR(13) + 'END CATCH;' + CHAR(13)
FROM sys.stats st
JOIN sys.tables t ON st.object_id = t.object_id
JOIN sys.schemas s ON t.schema_id = s.schema_id
where st.name not in ('ClusteredIndex') and st.name not like 'ACE%'
print @sql
EXEC sp_executesql @sql;
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / exec_requests_history.sql
Last active March 10, 2026 12:37
query-insights exec_requests_history
SELECT [distributed_statement_id],
[database_name],
[submit_time],
[start_time],
[end_time],
[is_distributed],
[statement_type],
[total_elapsed_time_ms],
[login_name],
[row_count],
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / tables-columns-datatypes.sql
Created March 10, 2026 10:47
query to get the datatypes for each column
SELECT
s.name AS SchemaName,
t.name AS TableName,
c.name AS ColumnName,
ty.name AS DataType,
c.max_length,
c.precision,
c.scale,
c.is_nullable
FROM sys.tables t
declare @list varchar(max)
declare @sql nvarchar(max)
drop table if exists sys_tables
create table sys_tables (object_id bigint, tablename varchar(50))
SELECT @list = STRING_AGG('(' + CAST([object_id] AS VARCHAR(20)) + ', ''' + CAST([name] AS VARCHAR(128)) + ''')', ',') FROM sys.tables
SET @sql = 'INSERT INTO sys_tables (object_id, tablename) VALUES ' + @list
--print @sql
exec sp_executesql @sql