# 优化内存使用，改进 TTL 管理和新增向量、字符串转换功能 | Greptime 双周精选

Source: https://greptime.cn/blogs/2024-12-04-biweekly-report

## 内容概述

作为一个成长中的开源项目，GreptimeDB 的进展离不开来自全球的社区贡献者们，感谢各位！

最近的内容更新如下：

- **在 PartSort 中实现 `LIMIT` 以减少内存占用**

- **更改数据库 TTL**

- **异步恢复文件缓存索引**

- **启用 Metasrv 客户端 RPC 压缩**

- **添加向量和字符串之间的转换**

## 社区贡献者名单

在过去的两周里，GreptimeDB 共合并了 **72 个**PR，其中有 **1 位**独立贡献者，累计 **1 个**PR 被成功合并，还有很多待合并的 PR。

祝贺以下各位在过去 2 周内成为我们最突出的贡献者：

- @[lyang24](https://github.com/lyang24) ([db#5046](https://github.com/GreptimeTeam/greptimedb/pull/5046))

衷心感谢我们所有的成员和贡献者！是你们的付出让我们的项目得以成功，也是你们让 GreptimeDB 成为一个更优质的产品。让我们一起努力，建立一个更棒的社区！

## PR 亮点

### [db#5018](https://github.com/GreptimeTeam/greptimedb/pull/5018) 在 PartSort 中实现 LIMIT 以减少内存占用

实现基于 `TopK` 堆的 `LIMIT` 功能，这将大幅减少在按时间索引排序时查询的内存占用。例如：

```sql
SELECT * FROM t ORDER BY ts LIMIT 5;
```

### [db#5035](https://github.com/GreptimeTeam/greptimedb/pull/5035) 更改数据库 TTL（Time to live）

现在可以使用 `ALTER DATABASE <database_name> SET <options>` 和 `ALTER DATABASE <database_name> UNSET <options>` 来更改数据库的 TTL 和其他选项。

### [db#5087](https://github.com/GreptimeTeam/greptimedb/pull/5087) 异步恢复文件缓存索引

同步恢复大量文件的缓存索引可能非常耗时，例如恢复 50 万个缓存文件可能需要耗费 10 ~ 20 秒。此更新通过异步恢复缓存索引，减少了 Datanode 启动时的等待时间。

### [db#5078](https://github.com/GreptimeTeam/greptimedb/pull/5078) 启用 Metasrv 客户端 RPC 压缩

此前 MetaSrv RPC 未开启压缩，可能会导致以下错误提示：`Error, message length too large: found 4228291 bytes, the limit is: 4194304 bytes`。此 PR 默认为 MetaSrv 客户端启用默认的 zstd 压缩功能，从而解决此问题。

### [db#5029](https://github.com/GreptimeTeam/greptimedb/pull/5029) 添加向量和字符串之间的转换

添加 `parse_vec` 和 `vec_to_string` 使字符串和向量之间的类型转换更加直观。示例如下：

```sql
=> SELECT vec_to_string(parse_vec('[1.0, 2.0]'));
+----------------------------------------------+
| vec_to_string(parse_vec(Utf8("[1.0, 2.0]"))) |
+----------------------------------------------+
| [1,2]                                        |
+----------------------------------------------+
```

## Good First Issue

### [db#5085 为 Metasrv 添加备份和恢复 API](https://github.com/GreptimeTeam/greptimedb/issues/5085)

关键词：Metasrv，API

难度：中等

### [db#5084 添加用于查询 Pipeline 的 HTTP API](https://github.com/GreptimeTeam/greptimedb/issues/5084)

关键词：Pipeline，API

难度：简单

---

## 关于 Greptime

[Greptime 格睿科技](https://greptime.cn/)专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务，帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) 已经衍生出多款适合不同用户的解决方案，更多信息或 demo 展示请联系下方小助手（微信号：greptime）。

欢迎对开源感兴趣的朋友们参与贡献和讨论，从带有 good first issue 标签的 issue 开始你的开源之旅吧～期待在开源社群里遇见你！添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~

Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb

官网：https://greptime.cn/

文档：https://docs.greptime.cn/

Twitter: https://twitter.com/Greptime

Slack: https://greptime.com/slack

LinkedIn: https://www.linkedin.com/company/greptime/
