Skip to content

Commit fb06efe

Browse files
authored
Update partitions-stats.sql
1 parent fae92b0 commit fb06efe

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

QueryTemplates/Common Scripts/partitions-stats.sql

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
--paritioned table and index details
2+
--paritioned table and index details
23
SELECT
34
SCHEMA_NAME(o.schema_id) AS SchemaName,
45
OBJECT_NAME(p.object_id) AS ObjectName,
5-
i.name AS IndexName,
6+
i.[name] AS IndexName,
67
p.index_id AS IndexID,
78
ds.name AS PartitionScheme,
89
p.partition_number AS PartitionNumber,
@@ -12,41 +13,27 @@ SELECT
1213
CASE pf.boundary_value_on_right
1314
WHEN 1 THEN 'RIGHT'
1415
ELSE 'LEFT' END AS Range,
15-
FORMAT(p.rows, 'N0') AS [Rows],
16+
FORMAT(p.[rows], 'N0') AS [Rows],
1617
p.[data_compression_desc] AS [Compression]
1718
FROM sys.partitions AS p
18-
JOIN sys.indexes AS i
19-
ON i.object_id = p.object_id
20-
AND i.index_id = p.index_id
21-
JOIN sys.tables AS o
22-
ON i.object_id = o.object_id
23-
JOIN sys.data_spaces AS ds
24-
ON ds.data_space_id = i.data_space_id
25-
JOIN sys.partition_schemes AS ps
26-
ON ps.data_space_id = ds.data_space_id
27-
JOIN sys.partition_functions AS pf
28-
ON pf.function_id = ps.function_id
29-
JOIN sys.destination_data_spaces AS dds2
30-
ON dds2.partition_scheme_id = ps.data_space_id
31-
AND dds2.destination_id = p.partition_number
32-
JOIN sys.filegroups AS fg
33-
ON fg.data_space_id = dds2.data_space_id
34-
LEFT JOIN sys.partition_range_values AS prv_left
35-
ON ps.function_id = prv_left.function_id
36-
AND prv_left.boundary_id = p.partition_number - 1
37-
LEFT JOIN sys.partition_range_values AS prv_right
38-
ON ps.function_id = prv_right.function_id
39-
AND prv_right.boundary_id = p.partition_number
19+
JOIN sys.indexes AS i ON i.object_id = p.object_id AND i.index_id = p.index_id
20+
JOIN sys.tables AS o ON i.object_id = o.object_id
21+
JOIN sys.data_spaces AS ds ON ds.data_space_id = i.data_space_id
22+
JOIN sys.partition_schemes AS ps ON ps.data_space_id = ds.data_space_id
23+
JOIN sys.partition_functions AS pf ON pf.function_id = ps.function_id
24+
JOIN sys.destination_data_spaces AS dds2 ON dds2.partition_scheme_id = ps.data_space_id AND dds2.destination_id = p.partition_number
25+
JOIN sys.filegroups AS fg ON fg.data_space_id = dds2.data_space_id
26+
LEFT JOIN sys.partition_range_values AS prv_left ON ps.function_id = prv_left.function_id AND prv_left.boundary_id = p.partition_number - 1
27+
LEFT JOIN sys.partition_range_values AS prv_right ON ps.function_id = prv_right.function_id AND prv_right.boundary_id = p.partition_number
4028
WHERE
4129
OBJECTPROPERTY(p.object_id, 'ISMSShipped') = 0
4230
AND p.index_id = 1 /* only show clustered index */
4331
--AND OBJECT_NAME(p.object_id) = ''
44-
--AND i.name = ''
32+
--AND i.[name] = ''
4533
--AND p.partition_number = 0
34+
--AND p.[rows] > 0
4635
ORDER BY
47-
ObjectName,
48-
IndexID,
49-
PartitionNumber;
36+
ObjectName, IndexID, PartitionNumber
5037

5138

5239

0 commit comments

Comments
 (0)