SELECT
(SELECT SUM(CAST(df.size as float)) FROM sys.database_files AS df WHERE df.type in ( 0, 2, 4 ) )/ 128.0 -
(SUM(a.total_pages) + (SELECT ISNULL(SUM(CAST(df.size as bigint)), 0) FROM sys.database_files AS df WHERE df.type = 2 ))/ 128.0 AS [SpaceUsed][FreeSpace]
FROM
sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id left join sys.internal_tables it on p.object_id = it.object_id
SpaceUsedFreeSpace
13055,945313
But that still does not exactly explain why FILEPROPERTY(name, 'SpaceUsed') AS INT)
would return moreWe are getting the sum of all these allocation units.
Execution plan
When we look at what My guess would be that the functiondifference is doing in the execution plan, we do find a convert implicitbased on the fileproperty calculation:
[Expr1022]-CONVERT_IMPLICIT(numeric(10,0),fileproperty([test].[sys].[sysprufiles].[lname] as [f].[lname],'SpaceUsed'),0)/(128.0)
We can open a DAC connection and try to query this 'hidden' system table.
Use Test
Go
SELECT * FROM sys.sysprufiles
SELECT fileproperty([lname] ,'SpaceUsed')
FROM [test].[sys].[sysprufiles]
But it doesfile having more overhead pages not really make a difference.
Hopefully somebody else finds an exact whydirectly in the allocation units dmv.
SpaceUsedFreeSpace
13056,070313