> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 表示 MergeTree 表的索引和标记文件的内容。 可用于查看内部信息。

# mergeTreeIndex

表示 MergeTree 表的索引和标记文件的内容。可用于查看内部信息。

<div id="syntax">
  ## 语法
</div>

```sql theme={null}
mergeTreeIndex(database, table [, with_marks = true] [, with_minmax = true])
```

<div id="arguments">
  ## 参数
</div>

| 参数            | 描述                   |
| ------------- | -------------------- |
| `database`    | 要从中读取索引和标记的数据库名。     |
| `table`       | 要从中读取索引和标记的表名。       |
| `with_marks`  | 是否在结果中包含标记列。         |
| `with_minmax` | 是否在结果中包含 min-max 索引。 |

<div id="returned_value">
  ## 返回值
</div>

一个表对象，包含以下列：源表的主索引和 min-max 索引 (如果已启用) 的值列、源表各数据分区片段中所有可能文件的标记值列 (如果已启用) ，以及虚拟列：

* `part_name` - 数据分区片段的名称。
* `mark_number` - 数据分区片段中当前标记的编号。
* `rows_in_granule` - 当前粒度中的行数。

如果某列在数据分区片段中不存在，或者其某个子流的标记未写入 (例如在 compact parts 中) ，则标记列可能包含 `(NULL, NULL)` 值。

<div id="usage-example">
  ## 使用示例
</div>

```sql theme={null}
CREATE TABLE test_table
(
    `id` UInt64,
    `n` UInt64,
    `arr` Array(UInt64)
)
ENGINE = MergeTree
ORDER BY id
SETTINGS index_granularity = 3, min_bytes_for_wide_part = 0, min_rows_for_wide_part = 8;

INSERT INTO test_table SELECT number, number, range(number % 5) FROM numbers(5);

INSERT INTO test_table SELECT number, number, range(number % 5) FROM numbers(10, 10);
```

```sql theme={null}
SELECT * FROM mergeTreeIndex(currentDatabase(), test_table, with_marks = true);
```

```text theme={null}
┌─part_name─┬─mark_number─┬─rows_in_granule─┬─id─┬─id.mark─┬─n.mark──┬─arr.size0.mark─┬─arr.mark─┐
│ all_1_1_0 │           0 │               3 │  0 │ (0,0)   │ (42,0)  │ (NULL,NULL)    │ (84,0)   │
│ all_1_1_0 │           1 │               2 │  3 │ (133,0) │ (172,0) │ (NULL,NULL)    │ (211,0)  │
│ all_1_1_0 │           2 │               0 │  4 │ (271,0) │ (271,0) │ (NULL,NULL)    │ (271,0)  │
└───────────┴─────────────┴─────────────────┴────┴─────────┴─────────┴────────────────┴──────────┘
┌─part_name─┬─mark_number─┬─rows_in_granule─┬─id─┬─id.mark─┬─n.mark─┬─arr.size0.mark─┬─arr.mark─┐
│ all_2_2_0 │           0 │               3 │ 10 │ (0,0)   │ (0,0)  │ (0,0)          │ (0,0)    │
│ all_2_2_0 │           1 │               3 │ 13 │ (0,24)  │ (0,24) │ (0,24)         │ (0,24)   │
│ all_2_2_0 │           2 │               3 │ 16 │ (0,48)  │ (0,48) │ (0,48)         │ (0,80)   │
│ all_2_2_0 │           3 │               1 │ 19 │ (0,72)  │ (0,72) │ (0,72)         │ (0,128)  │
│ all_2_2_0 │           4 │               0 │ 19 │ (0,80)  │ (0,80) │ (0,80)         │ (0,160)  │
└───────────┴─────────────┴─────────────────┴────┴─────────┴────────┴────────────────┴──────────┘
```

```sql theme={null}
DESCRIBE mergeTreeIndex(currentDatabase(), test_table, with_marks = true) SETTINGS describe_compact_output = 1;
```

```text theme={null}
┌─name────────────┬─type─────────────────────────────────────────────────────────────────────────────────────────────┐
│ part_name       │ String                                                                                           │
│ mark_number     │ UInt64                                                                                           │
│ rows_in_granule │ UInt64                                                                                           │
│ id              │ UInt64                                                                                           │
│ id.mark         │ Tuple(offset_in_compressed_file Nullable(UInt64), offset_in_decompressed_block Nullable(UInt64)) │
│ n.mark          │ Tuple(offset_in_compressed_file Nullable(UInt64), offset_in_decompressed_block Nullable(UInt64)) │
│ arr.size0.mark  │ Tuple(offset_in_compressed_file Nullable(UInt64), offset_in_decompressed_block Nullable(UInt64)) │
│ arr.mark        │ Tuple(offset_in_compressed_file Nullable(UInt64), offset_in_decompressed_block Nullable(UInt64)) │
└─────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────┘
```
