系统表 system.tables 包含所有表的信息,涵盖表的引擎、结构(分区/排序/主键)、存储路径、数据量等关键属性,是查看表结构、审计表配置的核心系统表。
字段名称 | 数据类型 | 字段含义说明 |
|---|---|---|
database | String | 表所在的数据库名。 |
name | String | 表的名称。 |
engine | String | 表引擎名(不包含参数),固定为 “CnchMergeTree”。 |
is_temporary | UInt8 | 表是否为临时表:
|
data_path | String | 表数据在文件系统中的存储路径。 |
metadata_path | String | 表元数据在文件系统中的存储路径。 |
metadata_modification_time | DateTime | 表元数据的最新修改时间。 |
dependencies_database | Array(String) | 表依赖的数据库列表。 |
dependencies_table | Array(String) | 表依赖的其他表列表,如基于当前表的物化视图,例如 'job_174990_kafka_mv'。 |
create_table_query | String | 创建该表的 SQL 语句。 |
engine_full | String | 表引擎的参数。 |
as_select | String | 表创建时 |
partition_key | String | 表中指定的分区键表达式。 |
sorting_key | String | 表中指定的排序键表达式。 |
primary_key | String | 表中指定的主键表达式。 |
sampling_key | String | 表中指定的采样键表达式。 |
storage_policy | String | 表使用的存储策略名称。 |
total_rows | Nullable(UInt64) | 表的总行数。如果无法快速确定表中的确切行数,则行数返回为 NULL,包括底层 Buffer 表。 |
total_bytes | Nullable(UInt64) | 表的总字节数,如果无法快速确定存储表的确切字节数,则字节数返回为 NULL,不包括任何底层存储。 |
lifetime_rows | Nullable(UInt64) | NULL |
lifetime_bytes | Nullable(UInt64) | NULL |
comment | String | 表的注释。 |
has_own_data | UInt8 | 表是否有独立存储的数据:
|
查询数据库 sales_db 中的表,且只返回关键字段:
SELECT name AS table_name, engine_full, partition_key, primary_key, total_bytes FROM system.tables WHERE database = 'sales_db' LIMIT 10;
查询结果示例: