Skip to content

Commit 26ace79

Browse files
Merge pull request #652 from erikdarlingdata/dev
Dev
2 parents 3266e87 + 95a2551 commit 26ace79

33 files changed

Lines changed: 2012 additions & 1639 deletions

Alerts/Alerts.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GO
1111
1212
This script will set up alerts for high severity and corruption errors in SQL Server.
1313
14-
Copyright 2025 Darling Data, LLC
14+
Copyright 2026 Darling Data, LLC
1515
https://www.erikdarling.com/
1616
1717
For support, head over to GitHub:

CLAUDE.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
This document outlines the T-SQL coding style preferences for Erik Darling (Darling Data, LLC) and must be strictly followed when writing or modifying SQL code.
44

5+
## Project Constraints
6+
7+
- **No Additional Dependencies**: Do not create helper functions, procedures, views, or any other database objects as dependencies for stored procedures. All logic must be self-contained within the procedure itself to avoid deployment and dependency management complexity.
8+
59
## General Formatting
610

711
- **Keywords**: All SQL keywords in UPPERCASE (SELECT, FROM, WHERE, JOIN, etc.)
812
- **Functions**: All SQL functions in UPPERCASE (CONVERT, ISNULL, OBJECT_ID, etc.)
9-
- **Data types**:
13+
- **Data types**:
1014
- Never abbreviate data types (use INTEGER instead of INT)
1115
- All data types must be lowercase (varchar, nvarchar, datetime2, bigint, etc.)
1216
- Length specifications must also be lowercase: nvarchar(max), not nvarchar(MAX)
1317
- Precision and scale specifications must be lowercase: decimal(38,2), not DECIMAL(38,2)
18+
- Always use sysname for SQL Server object names (database names, table names, schema names, column names, index names, etc.) rather than nvarchar(128)
1419
- **Keywords**: Never abbreviate keywords (use EXECUTE instead of EXEC, TRANSACTION instead of TRAN, PROCEDURE instead of PROC)
1520
- **Indentation**: 4 spaces for each level of indentation (NEVER use tabs)
1621
- **Line breaks**: Each statement on a new line

Clear Token Perm/ClearTokenPerm Agent Job.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For background on why you might need this:
1616
1717
In short, if your security caches are growing out of control, it can cause all sorts of weird issues with SQL Server.
1818
19-
Copyright 2025 Darling Data, LLC
19+
Copyright 2026 Darling Data, LLC
2020
https://www.erikdarling.com/
2121
2222
For support, head over to GitHub:
@@ -73,7 +73,7 @@ EXECUTE @ReturnCode = msdb.dbo.sp_add_job
7373
@description = N'For background on why you need this:
7474
https://www.erikdarling.com/troubleshooting-security-cache-issues-userstore_tokenperm-and-tokenandpermuserstore/
7575
76-
Copyright 2025 Darling Data, LLC
76+
Copyright 2026 Darling Data, LLC
7777
https://www.erikdarling.com/
7878
7979
For support, head over to GitHub:

Clear Token Perm/ClearTokenPerm.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For background on why you might need this:
1616
1717
In short, if your security caches are growing out of control, it can cause all sorts of weird issues with SQL Server.
1818
19-
Copyright 2025 Darling Data, LLC
19+
Copyright 2026 Darling Data, LLC
2020
https://www.erikdarling.com/
2121
2222
For support, head over to GitHub:

Clear Token Perm/Inflate Security Cache Demo And Analysis Script.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ https://code.erikdarling.com
2121
2222
MIT License
2323
24-
Copyright 2025 Darling Data, LLC
24+
Copyright 2026 Darling Data, LLC
2525
2626
https://www.erikdarling.com/
2727

Clear Token Perm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ TRUNCATE TABLE dbo.ClearTokenPermLogging;
7171

7272
The DBCC FREESYSTEMCACHE command used in these scripts will clear the security cache, which may cause a temporary performance impact as the cache is rebuilt. Test thoroughly in non-production environments before deploying to production.
7373

74-
Copyright 2025 Darling Data, LLC
74+
Copyright 2026 Darling Data, LLC
7575
Released under MIT license

Create Long IN List/Longingly.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GO
1313
1414
This procedure exists only to show how long IN clauses can hurt query performance.
1515
16-
Copyright 2025 Darling Data, LLC
16+
Copyright 2026 Darling Data, LLC
1717
https://www.erikdarling.com/
1818
1919
For support, head over to GitHub:

Helper Views/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ EXECUTE dbo.tempdb_tester;
100100

101101
Some of these scripts (particularly WhatsUpMemory) may cause performance issues if run on busy production servers. Use with caution, especially on servers with large amounts of memory.
102102

103-
Copyright 2025 Darling Data, LLC
103+
Copyright 2026 Darling Data, LLC
104104
Released under MIT license

Helper Views/WhatsUpIndexes.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SELECT TOP (9223372036854775807)
5151
schema_name = s.name,
5252
table_name = OBJECT_NAME(ps.object_id),
5353
index_name = i.name,
54+
data_compression_desc = p.data_compression_desc,
5455
in_row_pages_mb =
5556
CONVERT
5657
(
@@ -75,6 +76,10 @@ JOIN sys.schemas AS s
7576
JOIN sys.indexes AS i
7677
ON ps.object_id = i.object_id
7778
AND ps.index_id = i.index_id
79+
JOIN sys.partitions AS p
80+
ON ps.object_id = p.object_id
81+
AND ps.index_id = p.index_id
82+
AND ps.partition_number = p.partition_number
7883
ORDER BY
7984
ps.object_id,
8085
ps.index_id,

Helper Views/WhatsUpLocks.sql

Lines changed: 126 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -47,114 +47,135 @@ GO
4747
ALTER FUNCTION
4848
dbo.WhatsUpLocks
4949
(
50-
@spid integer
50+
@spid integer,
51+
@outsider bit = 'false'
5152
)
52-
RETURNS table
53+
RETURNS
54+
table
5355
AS
5456
RETURN
5557
SELECT TOP (9223372036854775807)
56-
dtl.request_session_id,
57-
blocked_by =
58-
ISNULL
59-
(
60-
(
61-
SELECT
62-
der.blocking_session_id
63-
FROM sys.dm_exec_requests AS der
64-
WHERE dtl.request_session_id = der.session_id
65-
),
66-
0
67-
),
68-
dtl.request_mode,
69-
l.locked_object,
70-
index_name = ISNULL(i.name, N'OBJECT'),
71-
dtl.resource_type,
72-
dtl.request_status,
73-
dtl.request_owner_type,
74-
hobt_lock_count =
75-
SUM
76-
(
77-
IIF
78-
(
79-
dtl.resource_associated_entity_id = p.hobt_id,
80-
1,
81-
0
82-
)
83-
),
84-
object_locks =
85-
SUM
86-
(
87-
IIF
88-
(
89-
dtl.resource_type = N'OBJECT',
90-
1,
91-
0
92-
)
93-
),
94-
page_locks =
95-
SUM
96-
(
97-
IIF
98-
(
99-
dtl.resource_type = N'PAGE',
100-
1,
101-
0
102-
)
103-
),
104-
row_locks =
105-
SUM
106-
(
107-
IIF
108-
(
109-
dtl.resource_type IN (N'RID', N'KEY'),
110-
1,
111-
0
112-
)
113-
),
114-
total_locks = COUNT_BIG(*)
115-
FROM sys.dm_tran_locks AS dtl WITH(NOLOCK)
116-
LEFT JOIN sys.partitions AS p WITH(NOLOCK)
117-
ON dtl.resource_associated_entity_id = p.hobt_id
118-
OUTER APPLY
119-
(
120-
SELECT
121-
locked_object = ao.name
122-
FROM sys.all_objects AS ao WITH(NOLOCK)
123-
WHERE dtl.resource_type = N'OBJECT'
124-
AND dtl.resource_associated_entity_id = ao.object_id
58+
dtl.request_session_id,
59+
blocked_by =
60+
ISNULL
61+
(
62+
(
63+
SELECT
64+
der.blocking_session_id
65+
FROM sys.dm_exec_requests AS der
66+
WITH(NOLOCK)
67+
WHERE dtl.request_session_id = der.session_id
68+
),
69+
0
70+
),
71+
dtl.request_mode,
72+
l.locked_object,
73+
index_name = ISNULL(i.name, N'OBJECT'),
74+
dtl.resource_type,
75+
dtl.request_status,
76+
dtl.request_owner_type,
77+
hobt_lock_count =
78+
SUM
79+
(
80+
CASE
81+
WHEN p.hobt_id IS NOT NULL
82+
THEN dtl.lock_count
83+
ELSE 0
84+
END
85+
),
86+
object_locks =
87+
SUM
88+
(
89+
CASE
90+
WHEN dtl.resource_type = N'OBJECT'
91+
THEN dtl.lock_count
92+
ELSE 0
93+
END
94+
),
95+
page_locks =
96+
SUM
97+
(
98+
CASE
99+
WHEN dtl.resource_type = N'PAGE'
100+
THEN dtl.lock_count
101+
ELSE 0
102+
END
103+
),
104+
row_locks =
105+
SUM
106+
(
107+
CASE
108+
WHEN dtl.resource_type IN (N'RID', N'KEY')
109+
THEN dtl.lock_count
110+
ELSE 0
111+
END
112+
),
113+
total_locks = SUM(dtl.lock_count)
114+
FROM
115+
(
116+
SELECT
117+
dtl.request_session_id,
118+
dtl.request_mode,
119+
dtl.resource_type,
120+
dtl.request_status,
121+
dtl.request_owner_type,
122+
dtl.resource_associated_entity_id,
123+
lock_count = COUNT_BIG(*)
124+
FROM sys.dm_tran_locks AS dtl
125+
WITH(NOLOCK)
126+
WHERE (dtl.request_session_id = @spid OR @spid IS NULL)
127+
AND (dtl.request_request_id = CURRENT_REQUEST_ID() OR @spid IS NULL OR @outsider = 'true')
128+
AND (dtl.request_owner_id = CURRENT_TRANSACTION_ID() OR @spid IS NULL OR @outsider = 'true')
129+
AND dtl.resource_type <> N'DATABASE'
130+
GROUP BY
131+
dtl.request_session_id,
132+
dtl.request_mode,
133+
dtl.resource_type,
134+
dtl.request_status,
135+
dtl.request_owner_type,
136+
dtl.resource_associated_entity_id
137+
) AS dtl
138+
LEFT JOIN sys.partitions AS p
139+
WITH(NOLOCK)
140+
ON dtl.resource_associated_entity_id = p.hobt_id
141+
OUTER APPLY
142+
(
143+
SELECT TOP (1)
144+
locked_object = ao.name
145+
FROM sys.all_objects AS ao
146+
WITH(NOLOCK)
147+
WHERE dtl.resource_type = N'OBJECT'
148+
AND dtl.resource_associated_entity_id = ao.object_id
125149

126-
UNION ALL
150+
UNION ALL
127151

128-
SELECT
129-
locked_object = ao.name
130-
FROM sys.all_objects AS ao WITH(NOLOCK)
131-
WHERE dtl.resource_type <> N'OBJECT'
132-
AND p.object_id = ao.object_id
133-
) AS l
134-
OUTER APPLY
135-
(
136-
SELECT TOP (1)
137-
i.name
138-
FROM sys.indexes AS i WITH(NOLOCK)
139-
WHERE i.object_id = p.object_id
140-
AND i.index_id = p.index_id
141-
) AS i
142-
WHERE (dtl.request_session_id = @spid OR @spid IS NULL)
143-
AND (dtl.request_request_id = CURRENT_REQUEST_ID() OR @spid IS NULL)
144-
AND (dtl.request_owner_id = CURRENT_TRANSACTION_ID() OR @spid IS NULL)
145-
AND dtl.resource_type <> N'DATABASE'
146-
AND l.locked_object <> N'WhatsUpLocks'
147-
GROUP BY
148-
dtl.request_session_id,
149-
dtl.resource_type,
150-
dtl.request_mode,
151-
dtl.request_status,
152-
dtl.request_owner_type,
153-
l.locked_object,
154-
i.name
155-
ORDER BY
156-
dtl.request_session_id,
157-
l.locked_object,
158-
index_name,
159-
total_locks DESC;
160-
GO
152+
SELECT TOP (1)
153+
locked_object = ao.name
154+
FROM sys.all_objects AS ao
155+
WITH(NOLOCK)
156+
WHERE dtl.resource_type <> N'OBJECT'
157+
AND p.object_id = ao.object_id
158+
) AS l
159+
OUTER APPLY
160+
(
161+
SELECT TOP (1)
162+
i.name
163+
FROM sys.indexes AS i
164+
WITH(NOLOCK)
165+
WHERE i.object_id = p.object_id
166+
AND i.index_id = p.index_id
167+
) AS i
168+
WHERE l.locked_object <> N'WhatsUpLocks'
169+
GROUP BY
170+
dtl.request_session_id,
171+
dtl.resource_type,
172+
dtl.request_mode,
173+
dtl.request_status,
174+
dtl.request_owner_type,
175+
l.locked_object,
176+
i.name
177+
ORDER BY
178+
dtl.request_session_id,
179+
l.locked_object,
180+
index_name,
181+
total_locks DESC;

0 commit comments

Comments
 (0)