system.tables

包含服务器知道的每个表的元数据。 分离的表不在 system.tables 显示。

临时表只在创建它们的会话中的 system.tables 中才可见。它们的数据库字段显示为空,并且 is_temporary 标志显示为开启。

此表包含以下列 (列类型显示在括号中):

  • database (String) — 表所在的数据库名。

  • name (String) — 表名。

  • engine (String) — 表引擎名 (不包含参数)。

  • is_temporary (UInt8) - 指示表是否是临时的标志。

  • data_path (String) - 表数据在文件系统中的路径。

  • metadata_path (String) - 表元数据在文件系统中的路径。

  • metadata_modification_time (DateTime) - 表元数据的最新修改时间。

  • dependencies_database (Array(String)) - 数据库依赖关系。

  • dependencies_table (Array(String)) - 表依赖关系 (基于当前表的 物化视图 表) 。

  • create_table_query (String) - 用于创建表的 SQL 语句。

  • engine_full (String) - 表引擎的参数。

  • as_select (String) - 视图的 SELECT 语句。

  • 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)) - 服务启动后插入的总行数(只针对 Buffer 表) 。

  • lifetime_bytes (Nullable(UInt64)) - 服务启动后插入的总字节数(只针对 Buffer 表) 。
  • comment (String) - 表的注释。

  • has_own_data (UInt8) — 标志,表示表本身是否在磁盘上存储数据,或者访问其他来源。

system.tables 表被用于 SHOW TABLES 的查询实现中。

示例

  1. SELECT * FROM system.tables LIMIT 2 FORMAT Vertical;
  1. Row 1:
  2. ──────
  3. database: base
  4. name: t1
  5. uuid: 81b1c20a-b7c6-4116-a2ce-7583fb6b6736
  6. engine: MergeTree
  7. is_temporary: 0
  8. data_paths: ['/var/lib/clickhouse/store/81b/81b1c20a-b7c6-4116-a2ce-7583fb6b6736/']
  9. metadata_path: /var/lib/clickhouse/store/461/461cf698-fd0b-406d-8c01-5d8fd5748a91/t1.sql
  10. metadata_modification_time: 2021-01-25 19:14:32
  11. dependencies_database: []
  12. dependencies_table: []
  13. create_table_query: CREATE TABLE base.t1 (`n` UInt64) ENGINE = MergeTree ORDER BY n SETTINGS index_granularity = 8192
  14. engine_full: MergeTree ORDER BY n SETTINGS index_granularity = 8192
  15. as_select: SELECT database AS table_catalog
  16. partition_key:
  17. sorting_key: n
  18. primary_key: n
  19. sampling_key:
  20. storage_policy: default
  21. total_rows: 1
  22. total_bytes: 99
  23. lifetime_rows: ᴺᵁᴸᴸ
  24. lifetime_bytes: ᴺᵁᴸᴸ
  25. comment:
  26. has_own_data: 0
  27. Row 2:
  28. ──────
  29. database: default
  30. name: 53r93yleapyears
  31. uuid: 00000000-0000-0000-0000-000000000000
  32. engine: MergeTree
  33. is_temporary: 0
  34. data_paths: ['/var/lib/clickhouse/data/default/53r93yleapyears/']
  35. metadata_path: /var/lib/clickhouse/metadata/default/53r93yleapyears.sql
  36. metadata_modification_time: 2020-09-23 09:05:36
  37. dependencies_database: []
  38. dependencies_table: []
  39. create_table_query: CREATE TABLE default.`53r93yleapyears` (`id` Int8, `febdays` Int8) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 8192
  40. engine_full: MergeTree ORDER BY id SETTINGS index_granularity = 8192
  41. as_select: SELECT name AS catalog_name
  42. partition_key:
  43. sorting_key: id
  44. primary_key: id
  45. sampling_key:
  46. storage_policy: default
  47. total_rows: 2
  48. total_bytes: 155
  49. lifetime_rows: ᴺᵁᴸᴸ
  50. lifetime_bytes: ᴺᵁᴸᴸ
  51. comment:
  52. has_own_data: 0

原文