Monitore tabelas temporais versionadas pelo sistema otimizadas para memória

Aplica-se a: SQL Server 2016 (13.x) e versões posteriores Instância Gerenciada SQL do Azure

Você pode usar vistas existentes para controlar o consumo de memória detalhado e resumido para cada tabela com versão do sistema e otimizada para memória.

Monitorar tabelas temporais

Use o seguinte código de exemplo para monitorizar tabelas temporais que utilizam OLTP em memória. Estes exemplos utilizam expressões de tabela comuns (CTEs).

Consumo de memória detalhado

A consulta a seguir detalha o consumo de memória, a divisão por versão do sistema principal e a tabela de preparo do histórico interno.

WITH InMemoryTemporalTables
AS (SELECT SCHEMA_NAME(t1.schema_id) AS TemporalTableSchema,
           t1.object_id AS TemporalTableObjectId,
           t1.object_id AS InternalTableObjectId,
           OBJECT_NAME(t1.parent_object_id) AS TemporalTableName,
           t1.Name AS InternalHistoryStagingName
    FROM sys.internal_tables AS t1
         INNER JOIN sys.tables AS t1
             ON t1.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 AS ConsumedBy,
       c.*
FROM sys.dm_db_xtp_memory_consumers AS c
     INNER JOIN InMemoryTemporalTables AS t
         ON c.object_id = t.TemporalTableObjectId
         OR c.object_id = t.InternalTableObjectId
WHERE t.TemporalTableSchema = 'dbo'
      AND t.TemporalTableName = 'FXCurrencyPairs';

Resumo do consumo de memória

A consulta a seguir resume o consumo de memória, com um total para uma tabela otimizada para memória versionada pelo sistema.

;WITH InMemoryTemporalTables
AS (
    SELECT SCHEMA_NAME(t1.schema_id) AS TemporalTableSchema,
        t1.object_id AS TemporalTableObjectId,
        t1.object_id AS InternalTableObjectId,
        OBJECT_NAME(t1.parent_object_id) AS TemporalTableName,
        t1.Name AS InternalHistoryStagingName
    FROM sys.internal_tables t1
    INNER JOIN sys.tables t1
        ON t1.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 AS 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;