SELECT table_name, table_type, create_time
FROM information_schema.tables
ORDER BY create_time DESC;
查看作业历史(最近 24 小时)
SELECT job_id, status, start_time, end_time, execution_time, virtual_cluster
FROM information_schema.job_history
WHERE start_time >= CURRENT_DATE() - INTERVAL 1 DAY
ORDER BY start_time DESC
LIMIT 50;
查看实例级所有空间的表(需 INSTANCE ADMIN)
SELECT table_schema, table_name, create_time
FROM SYS.information_schema.tables
WHERE delete_time IS NULL
ORDER BY table_schema, table_name;
资产盘点 SQL
查看当前空间下所有 Schema
SELECT catalog_name, schema_name, type, schema_creator, create_time, comment
FROM information_schema.schemas
ORDER BY schema_name;
查看所有表及大小、行数
SELECT table_schema, table_name, table_type, row_count, bytes
FROM information_schema.tables
ORDER BY bytes DESC;
查看字段详细信息
SELECT table_schema, table_name, column_name, data_type, is_nullable, comment
FROM information_schema.columns
WHERE table_schema = 'public'
ORDER BY table_name, column_name;
查看排序列推荐
SELECT schema_name, table_name, col, statement, ratio, insert_time
FROM information_schema.sortkey_candidates
ORDER BY ratio DESC;
找出最大的 10 张表
SELECT table_schema, table_name, row_count, bytes
FROM information_schema.tables
WHERE table_type IN ('MANAGED_TABLE', 'EXTERNAL_TABLE')
ORDER BY bytes DESC
LIMIT 10;
找出没有注释的表
SELECT table_schema, table_name
FROM information_schema.tables
WHERE comment IS NULL OR comment = '';
找出没有注释的字段
SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE (comment IS NULL OR comment = '')
AND table_schema NOT IN ('information_schema');
统计各 Schema 下的表数量和总存储
SELECT table_schema,
COUNT(*) AS table_count,
SUM(bytes) AS total_storage
FROM information_schema.tables
GROUP BY table_schema
ORDER BY total_storage DESC;
查看实例下所有工作空间(需 INSTANCE ADMIN)
SELECT workspace_name, workspace_creator, create_time, comment
FROM sys.information_schema.workspaces
WHERE delete_time IS NULL
ORDER BY create_time DESC;
查看实例下所有 Schema(需 INSTANCE ADMIN)
SELECT catalog_name, schema_name, type, schema_creator, create_time
FROM sys.information_schema.schemas
WHERE delete_time IS NULL
ORDER BY catalog_name, schema_name;
查看实例用量(需 INSTANCE ADMIN)
SELECT workspace_name, sku_name, measurements_consumption, amount, measurement_start
FROM sys.information_schema.instance_usage
WHERE measurement_start >= CURRENT_DATE() - INTERVAL 7 DAY
ORDER BY amount DESC;