-
Notifications
You must be signed in to change notification settings - Fork 12
/
Workload Page Splits.sql
61 lines (47 loc) · 1.4 KB
/
Workload Page Splits.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Workload for Page Splits */
USE AdventureWorks2012;
GO
CREATE TABLE TestForPageSplits
(ID UNIQUEIDENTIFIER,
Value VARCHAR(25));
CREATE CLUSTERED INDEX CX_PageSplits_GUID ON TestForPageSplits (ID);
INSERT INTO TestForPageSplits
VALUES (NEWID(), 'Blah');
GO 5000
SELECT *
FROM TestForPageSplits;
--49 pages
--View target data; close
UPDATE TestForPageSplits
SET Value = 'BlahBlahBlahBlahBlah';
--Reopen View live data; add add'l columns; save view
SELECT
s.Name AS SchemaName,
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) AS TotalPages,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM sys.tables t
INNER JOIN sys.schemas s ON s.schema_id = t.schema_id
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE t.NAME = 'TestForPageSplits'
GROUP BY t.Name, s.Name, p.Rows
ORDER BY s.Name, t.Name;
--65 pages
INSERT INTO TestForPageSplits
VALUES (NEWID(), 'Blah');
GO 500
--65 pages
--Reopen View target data
--Now query to get useful info
--Which file?
SELECT *
FROM sys.database_files
WHERE file_id = 1;
--What other questions need to be answered?
--Cleanup
DROP TABLE TestForPageSplits;