# PromQL 兼容率达 82%，TSBS 场景最高 200% 性能提升｜ Greptime 双周精选

Source: https://greptime.cn/blogs/2023-12-13-biweekly

## 内容概述

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

在过去两周中，我们砥砺前行。以下是这段时间的总结：

- PromQL 兼容性提高至 82%；

- 实现 SSTs 和 memtables 的并行扫描，TSBS 场景最高 200% 性能提升；

- 新增 `date_add`、`date_sub` 函数；

- 允许在创建表时指定不同存储后端；

- 新增 `ALIGN TO` 子句和 `Interval` 查询支持；

- 支持配置分布式跟踪的采样率参数；

- 修复 Procedure 重启后无法继续执行的 Bug。

## 社区贡献者名单

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

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

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

- @[LinuxSuRen](https://github.com/LinuxSuRen) ([dashboard#359](https://github.com/GreptimeTeam/dashboard/pull/359))

- @[NiwakaDev](https://github.com/NiwakaDev) ([db#2887](https://github.com/GreptimeTeam/greptimedb/pull/2887) [db#2733](https://github.com/GreptimeTeam/greptimedb/pull/2733))

- @[tisonkun](https://github.com/tisonkun) ([db#2886](https://github.com/GreptimeTeam/greptimedb/pull/2886) [db#2884](https://github.com/GreptimeTeam/greptimedb/pull/2884) [db#2874](https://github.com/GreptimeTeam/greptimedb/pull/2874) [db#2859](https://github.com/GreptimeTeam/greptimedb/pull/2859))

🎉 热烈欢迎 @[hygkui](https://github.com/hygkui) @[LinuxSuRen](https://github.com/LinuxSuRen) 作为新的贡献者加入社区并成功合并了首个 PR，还有更多来自其他独立贡献者的 PR 正在等待合并。

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

## PR 亮点

### [db#2651](https://github.com/GreptimeTeam/greptimedb/pull/2651) 实现了 PromQL `histogram_quantile` 函数

### [db#2839](https://github.com/GreptimeTeam/greptimedb/pull/2839) 实现了 PromQL `AND` 和 `UNLESS`  操作符

### [db#2854](https://github.com/GreptimeTeam/greptimedb/pull/2854) 实现了 `time()` 以及日期相关的函数

### [db#2879](https://github.com/GreptimeTeam/greptimedb/pull/2879) 对齐 PromQL `linear_regression` 行为

上述 PR 将 PromQL 的兼容率提升至 82%，更多细节可查看 [db#1042](https://github.com/GreptimeTeam/greptimedb/pull/1042)。

### [db#2852](https://github.com/GreptimeTeam/greptimedb/pull/2852) 支持并行扫描 `SSTs` 和 `memtables`

默认配置 1/4 CPU 数量线程进行并行扫描。在 TSBS Benchmark 中，多线程扫描对比单线程扫描性能显著提升，部分场景提升高达 200%。

### [db#2881](https://github.com/GreptimeTeam/greptimedb/pull/2881) 支持 `date_add`, `date_sub` 函数

支持给时间戳（Timestamp）日期（Date）或日期时间（DateTime）数值增加/减少一个间隔（`Interval`）值。

### [db#2733](https://github.com/GreptimeTeam/greptimedb/pull/2733) 支持在创建表时，指定不同的对象存储后端

在之前的版本中，表只能存储在同一个存储后端中；该 PR 支持在启动时配置多个不同的存储后端，并在创建表时指定存储表数据的存储后端。例如，我们可以将一张表存储在本地，另一张表存储在 S3 上。

### [db#2842](https://github.com/GreptimeTeam/greptimedb/pull/2842) 新增 `ALIGN TO` 子句和 `Interval` 查询支持

#### `Interval` 支持

`Interval` 表达式可以在 `RANGE` 和 `ALIGN` 关键字之后，作为可选的持续时间字符串替代：

```rust
SELECT 
    rate(a) RANGE (INTERVAL '1 year 2 hours 3 minutes') 
FROM 
    t 
    ALIGN (INTERVAL '1 year 2 hours 3 minutes')
FILL NULL;
```

#### `ALIGN TO` 子句

支持 `ALIGN TO` 子句，用户可以使用 `ALIGN TO` 将时间对齐到他们想要的时间点。

```rust
SELECT rate(a) RANGE '6m' FROM t ALIGN '1h' TO '2021-07-01 00:00:00' by (a, b) FILL NULL;
```

可用的 `ALIGN TO` 选项包括：

- Calendar（默认）：对齐到 UTC 时间戳 0
- Now：对齐到当前 UTC 时间戳
- Timestamp：对齐到用户指定的特定时间戳

更多细节可以查看 Range Query 文档:https://docs.greptime.com/reference/sql/range

### [db#2809](https://github.com/GreptimeTeam/greptimedb/pull/2809) 支持配置分布式跟踪的采样率参数

在之前的版本中，分布式跟踪默认采集全量数据，通过配置采样率参数可以按比例采集数据。

更多细节可以查看 Configuration 文档:https://docs.greptime.com/user-guide/operations/configuration#logging-options

### [db#2824](https://github.com/GreptimeTeam/greptimedb/pull/2824) 修复 Procedure 无法在重启后继续执行的 Bug

在之前的版本中，未执行完成的 Procedure 在系统重启后无法继续执行，该 PR 修复了此问题。

## Good First Issue

### [db##2889](https://github.com/GreptimeTeam/greptimedb/issues/2889)  

修复 `redact_sql_secrets` 函数不能正常处理特殊字符的问题。

### [db#2877](https://github.com/GreptimeTeam/greptimedb/issues/2877)

使 HTTP SQL 输出支持 Pretty print。

### [db#2853](https://github.com/GreptimeTeam/greptimedb/issues/2853)

统一 Builder 的代码风格。

### [db#2637](https://github.com/GreptimeTeam/greptimedb/issues/2637)

添加更多包涵特殊的 sqlness 测试。

## 关于 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/
