监视内存优化的系统版本控制时态表
适用于:SQL Server 2016 (13.x) 及更高版本 Azure SQL 数据库 Azure SQL 托管实例
每个系统版本控制型内存优化表都可以使用现有视图来跟踪详细的和摘要性的内存占用情况。
监视时态表
使用以下示例代码监视使用内存中 OLTP 的时态表。 这些示例使用公用表表达式 (CTE)。
详细的内存消耗
以下查询详细说明了内存消耗(按每个主要的系统版本控制的内部历史记录临时表进行拆分)。
WITH InMemoryTemporalTables
AS (
SELECT SCHEMA_NAME(T1.schema_id) AS TemporalTableSchema,
T1.object_id AS TemporalTableObjectId,
IT.object_id AS InternalTableObjectId,
OBJECT_NAME(IT.parent_object_id) AS TemporalTableName,
IT.Name AS InternalHistoryStagingName
FROM sys.internal_tables IT
INNER JOIN sys.tables T1
ON IT.parent_object_id = T1.object_id
WHERE T1.is_memory_optimized = 1
AND T1.temporal_type = 2
)
SELECT TemporalTableSchema,
T.TemporalTableName,
T.InternalHistoryStagingName,
CASE
WHEN C.object_id = T.TemporalTableObjectId
THEN 'Temporal Table Consumption'
ELSE 'Internal Table Consumption'
END ConsumedBy,
C.*
FROM sys.dm_db_xtp_memory_consumers C
INNER JOIN InMemoryTemporalTables T
ON C.object_id = T.TemporalTableObjectId
OR C.object_id = T.InternalTableObjectId
WHERE T.TemporalTableSchema = 'dbo'
AND T.TemporalTableName = 'FXCurrencyPairs';
内存消耗摘要
以下查询汇总了内存消耗(系统版本控制的内存优化表的总计)。
WITH InMemoryTemporalTables
AS (
SELECT SCHEMA_NAME(T1.schema_id) AS TemporalTableSchema,
T1.object_id AS TemporalTableObjectId,
IT.object_id AS InternalTableObjectId,
OBJECT_NAME(IT.parent_object_id) AS TemporalTableName,
IT.Name AS InternalHistoryStagingName
FROM sys.internal_tables IT
INNER JOIN sys.tables T1
ON IT.parent_object_id = T1.object_id
WHERE T1.is_memory_optimized = 1
AND T1.temporal_type = 2
),
DetailedConsumption
AS (
SELECT TemporalTableSchema,
T.TemporalTableName,
T.InternalHistoryStagingName,
CASE
WHEN C.object_id = T.TemporalTableObjectId
THEN 'Temporal Table Consumption'
ELSE 'Internal Table Consumption'
END ConsumedBy,
C.*
FROM sys.dm_db_xtp_memory_consumers C
INNER JOIN InMemoryTemporalTables T
ON C.object_id = T.TemporalTableObjectId
OR C.object_id = T.InternalTableObjectId
)
SELECT TemporalTableSchema TemporalTableName,
sum(allocated_bytes) AS allocated_bytes,
sum(used_bytes) AS used_bytes
FROM DetailedConsumption
WHERE TemporalTableSchema = 'dbo' ANDTemporalTableName = 'FXCurrencyPairs'
GROUP BY TemporalTableSchema,
TemporalTableName;