> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 扩展表

> 键 → 记录的查找表，在流水线里给事件做富化，零查询开销。

**扩展表**是在 MoleSignal 里维护、并在[流水线](/zh-Hans/pipelines)变换中用来联表的小型「键 → 记录」
查找表。扩展表可为事件富化参考数据——把 `service` 映射到所属团队、把账号 ID 映射到套餐档位、把 IP 段映射
到地区——而无需在热路径上调用外部存储。

## 创建表并添加行

打开**扩展表**并创建表。每一行是一个**键**加一条带命名字段的记录。也可以通过 API 管理：

```bash theme={null}
# upsert 一行，键为 "checkout"
curl -X PUT http://localhost:5080/api/v1/extend_tables/service_meta/rows/checkout \
  -H "authorization: Bearer $MS_JWT" \
  -H 'content-type: application/json' \
  -d '{"team":"payments","tier":"gold"}'
```

| 操作        | 端点                                                |
| --------- | ------------------------------------------------- |
| 列出所有表     | `GET /api/v1/extend_tables`                       |
| 列出某表的行    | `GET /api/v1/extend_tables/{table}`               |
| upsert 一行 | `PUT /api/v1/extend_tables/{table}/rows/{key}`    |
| 删除一行      | `DELETE /api/v1/extend_tables/{table}/rows/{key}` |

## 在变换里查表

在 [VRL 变换](/zh-Hans/functions)里调用 `lookup(table, key)`，并从返回的记录上读取
字段：

```ruby theme={null}
# 给每条事件富化该服务所属的团队
.team = lookup("service_meta", .service).team
```

查表在**内存**中进行，因此不给流水线运行增加任何查询或存储开销。表在启动时加载，并随 upsert、删除
行而保持最新。

<Tip>
  扩展表按组织隔离、并在所有流水线间共享——映射定义一次，处处复用。
</Tip>

`functions.read` 用于列出表与使用情况。创建表需要 `functions.create`；修改行需要
`functions.edit`；删除表需要 `functions.delete`。

<Card title="流水线" icon="diagram-project" href="/zh-Hans/pipelines">
  构建调用扩展表的变换链。
</Card>
