预测优化系统表参考

重要

此系统表为公共预览版

注意

若要访问此表,区域必须支持预测优化。 请参阅 Azure Databricks 区域

本文概述预测优化操作历史记录表架构并提供示例查询。 预测优化可优化数据布局,实现最佳性能和成本效益。 系统表跟踪此功能的操作历史记录。 有关预测优化的信息,请参阅 Unity Catalog 托管表的预测性优化

表路径:此系统表位于 system.storage.predictive_optimization_operations_history.

交付注意事项

  • 预测优化系统表在两小时内更新。 但是,计费信息最多可能需要 24 小时才能填充数据。
  • 预测优化可能在同一群集上运行多个操作。 如果是这样,则表示每个操作归因于每个操作的 DBU 共享是近似的。 这就是为什么 usage_unit 设置为 ESTIMATED_DBU 的原因。 不过,在群集上使用的 DBU 总数是准确的。

预测优化表架构

预测优化操作历史记录系统表使用以下架构:

列名称 数据类型 说明 示例
account_id 字符串 帐户的 ID。 11e22ba4-87b9-4cc2-9770-d10b894b7118
workspace_id 字符串 预测优化在其中运行操作的工作区的 ID。 1234567890123456
start_time 时间戳 操作开始的时间。 时区信息记录在值的末尾,其中 +00:00 表示 UTC。 2023-01-09 10:00:00.000+00:00
end_time 时间戳 操作结束的时间。 时区信息记录在值的末尾,其中 +00:00 表示 UTC。 2023-01-09 11:00:00.000+00:00
metastore_name 字符串 优化表所属的元存储的名称。 metastore
metastore_id 字符串 优化表所属的元存储的 ID。 5a31ba44-bbf4-4174-bf33-e1fa078e6765
catalog_name 字符串 优化表所属的目录的名称。 catalog
schema_name 字符串 优化表所属的架构的名称。 schema
table_id 字符串 优化表的 ID。 138ebb4b-3757-41bb-9e18-52b38d3d2836
table_name 字符串 优化表的名称。 table1
operation_type 字符串 已执行的优化操作。 必须是下列值之一:COMPACTION、、VACUUMANALYZECLUSTERINGAUTO_CLUSTERING_COLUMN_SELECTION、或DATA_SKIPPING_COLUMN_SELECTIONCOMPATIBILITY_MODE_REFRESH COMPACTION
operation_id 字符串 优化操作的 ID。 4dad1136-6a8f-418f-8234-6855cfaff18f
operation_status 字符串 优化操作的状态。 必须是下列值之一: SUCCESSFULFAILED: INTERNAL_ERROR SUCCESSFUL
operation_metrics map[string, string] 有关执行的特定优化的其他详细信息。 请参阅 操作指标 {"number_of_output_files":"100","number_of_compacted_files":"1000","amount_of_output_data_bytes":"4000","amount_of_data_compacted_bytes":"10000"}
usage_unit 字符串 该操作产生的使用量单位。 必须是以下值: ESTIMATED_DBU ESTIMATED_DBU
usage_quantity 十进制 此操作使用的使用单位量。 2.12

操作指标

列中记录 operation_metrics 的指标因操作类型而异:

操作名称 操作说明 运营指标 说明
COMPACTION 通过优化文件大小来提高查询性能。 请参阅优化数据文件布局 number_of_compacted_files 此作删除的文件数。
amount_of_data_compacted_bytes 此操作删除的字节数。
number_of_output_files 此操作添加的新文件数。
amount_of_output_data_bytes 此操作添加的字节数。
VACUUM 通过删除表不再引用的数据文件来降低存储成本。 请参阅使用 vacuum 删除未使用的数据文件 number_of_deleted_files 此操作垃圾回收的文件数。
amount_of_data_deleted_bytes 由此操作回收的字节数。
ANALYZE 触发统计信息增量更新以提高查询性能。 请参阅 ANALYZE TABLE amount_of_scanned_bytes 此作扫描的字节数。
number_of_scanned_files 此作扫描的文件数。
staleness_percentage_reduced 此操作后,过时性百分比的减少。 此统计数据的范围可以根据ANALYZE执行的频率在 0 到 100 之间变化。
CLUSTERING 为已启用的表触发增量聚类分析。 请参阅对表使用 liquid 聚类分析 number_of_removed_files 此作删除的文件数。
number_of_clustered_files 此操作新增的文件数。
amount_of_data_removed_bytes 此操作移除的字节数量。
amount_of_clustered_data_bytes 此操作添加的字节数。
AUTO_CLUSTERING_COLUMN_SELECTION 评估是否要演变聚类列。 请参阅 自动液体聚类 old_clustering_columns 先前的数据布局,可以是旧有的聚类键或“无”(如果未分区)。
new_clustering_columns 此操作应用的新聚类列。
has_column_selection_changed 该操作是否已使聚类列演变。
additional_reason 聚类列发生更改或无更改的原因。
DATA_SKIPPING_COLUMN_SELECTION 检测缺少数据的列,跳过工作负荷中的统计信息并回填它们。 请参阅 数据跳过 amount_of_scanned_bytes 此作扫描的字节数。
number_of_scanned_files 此作扫描的文件数。
added_data_skipping_columns 新添加的用于跳过数据的列在此操作中应用。
removed_data_skipping_columns 该操作移除了数据跳过的列。
old_data_skipping_columns 之前跳过列的数据的详尽列表。
new_data_skipping_columns 数据跳过列的当前详尽列表。
COMPATIBILITY_MODE_REFRESH 检测兼容性模式是否过期并刷新表。 请参阅 兼容性模式 N/A 兼容性模式刷新操作。

示例查询

以下部分包括可用于深入了解预测优化系统表的示例查询。 若要使这些查询正常工作,需要将参数值替换为自己的值。

本文包括以下示例查询:

估计过去 30 天内有多少 DBU 使用了预测优化?

SELECT SUM(usage_quantity)
  FROM system.storage.predictive_optimization_operations_history
  WHERE
    usage_unit = "ESTIMATED_DBU"
    AND timestampdiff(day, start_time, Now()) < 30;

若要查找特定 ETL 管道的相同值,可以先在该管道中找到表,然后搜索 DBU:

-- Find all full table names for the pipeline:
WITH pipeline_mapping AS (
  SELECT DISTINCT target_table_full_name AS target_table_name
  FROM system.access.table_lineage
  WHERE entity_type = 'PIPELINE' AND entity_id = :pipeline_id
)
-- Select all operations for any table in that pipeline:
SELECT SUM(usage_quantity)
  FROM system.storage.predictive_optimization_operations_history
  WHERE
    CONCAT_WS('.', catalog_name, schema_name, table_name)
      IN ( SELECT target_table_name FROM pipeline_mapping)
    AND usage_unit = "ESTIMATED_DBU"
    AND timestampdiff(day, start_time, Now()) < 30;

过去 30 天内哪些表的预测优化开支最多(估计成本)?

SELECT
  metastore_name,
  catalog_name,
  schema_name,
  table_name,
  SUM(usage_quantity) as totalDbus
FROM system.storage.predictive_optimization_operations_history
WHERE
  usage_unit = "ESTIMATED_DBU"
  AND timestampdiff(day, start_time, Now()) < 30
GROUP BY ALL
ORDER BY totalDbus DESC;

预测优化在哪些表上执行的操作最多?

SELECT
  metastore_name,
  catalog_name,
  schema_name,
  table_name,
  operation_type,
  COUNT(DISTINCT operation_id) as operations
FROM system.storage.predictive_optimization_operations_history
GROUP BY ALL
ORDER BY operations DESC;

对于给定目录,总字节数压缩了多少?

SELECT
  schema_name,
  table_name,
  SUM(operation_metrics["amount_of_data_compacted_bytes"]) as bytesCompacted
FROM system.storage.predictive_optimization_operations_history
WHERE
  metastore_name = :metastore_name
  AND catalog_name = :catalog_name
  AND operation_type = "COMPACTION"
GROUP BY ALL
ORDER BY bytesCompacted DESC;

哪些表清空的字节最多?

SELECT
  metastore_name,
  catalog_name,
  schema_name,
  table_name,
  SUM(operation_metrics["amount_of_data_deleted_bytes"]) as bytesVacuumed
FROM system.storage.predictive_optimization_operations_history
WHERE operation_type = "VACUUM"
GROUP BY ALL
ORDER BY bytesVacuumed DESC;

通过预测优化所执行的操作成功率是多少?

WITH operation_counts AS (
  SELECT
    COUNT(DISTINCT (CASE WHEN operation_status = "SUCCESSFUL" THEN operation_id END)) as successes,
    COUNT(DISTINCT operation_id) as total_operations
  FROM system.storage.predictive_optimization_operations_history
 )
SELECT successes / total_operations as success_rate
FROM operation_counts;