# Greptime 双周精选 （3 月 27 日-4 月 9 日）｜支持多种时间戳精度

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

## 内容概述

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

以下是这段时间较为重要的 PR 总结：

- 将 PromQL 的兼容性提升到 50%

- 实现了 [Region manifest checkpoint](https://github.com/GreptimeTeam/greptimedb/issues/170)

- 建表支持多种时间戳精度

## 社区贡献者名单

在过去的两周里，共有 **2 位贡献者**，累计 **6 个 PR 被成功合并**，还有很多待合并的 PR。

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

- @[etolbakov](https://github.com/etolbakov) ([db#1083](https://github.com/GreptimeTeam/greptimedb/pull/1083) [db#1289](https://github.com/GreptimeTeam/greptimedb/pull/1289) [db#1304](https://github.com/GreptimeTeam/greptimedb/pull/1304) [db#1306](https://github.com/GreptimeTeam/greptimedb/pull/1306))

- @[haohuaijin](https://github.com/haohuaijin) ([db#1291](https://github.com/GreptimeTeam/greptimedb/pull/1291) [db#1324](https://github.com/GreptimeTeam/greptimedb/pull/1324))

👏 欢迎 @[haohuaijin](https://github.com/haohuaijin) 作为新的贡献者加入到我们的社区，并且已有 2 个 PR 被成功合并！

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

## PR 亮点

### [db#1042](https://github.com/GreptimeTeam/greptimedb/pull/1042) 将 PromQL 的兼容性提升到 50%

我们已经初步支持了 PromQL，并通过了超过 **50%** 的 Prometheus 的兼容性测试，大大提升了与 PromQL 的兼容性。为了不断进行优化，并将所有与 PromQL 兼容性相关的 PR 和任务收集在这里，我们创建了这个 [issue](https://github.com/GreptimeTeam/greptimedb/issues/1042)，以便于跟踪进展。

<figure>
<img src="/zh/blogs/2023-04-12-biweekly/image1.png" alt="（图 1：Compliance History）" style="width: 80%; margin: 0 auto"/>
<figcaption>（图 1：Compliance History）</figcaption>
</figure>

### [db#1202](https://github.com/GreptimeTeam/greptimedb/pull/1202) 实现了 Region manifest checkpoint

你是否遇到过在数据库中存储了大量数据后重启速度慢的问题？我们最近解决了这个问题。我们实现了压缩 manifest 并为它们创建快照，这可以减少磁盘消耗并加速 Region recovery。

主要变化有以下几点：

- Region manifest 快照结构如 `RegionManifestData` 以及 `RegionSnapshot` 等。可参考 [src/storage/src/manifest/action.rs](https://github.com/GreptimeTeam/greptimedb/blob/develop/src/storage/src/manifest/action.rs)。

- 新增 `Checkpointer` 特性并将其添加到 `ManifestImpl`。

- 将 `RegionManifestCheckpointer` 添加到 Region manifest 中进行检查点处理。每隔十次进行保存 manifest 操作时，将尝试执行检查点。

- 从检查点的快照中恢复 Region manifest。

### [db#1332](https://github.com/GreptimeTeam/greptimedb/pull/1332) 建表支持多种时间戳精度

我们增强了 `Timestamp` 来支持在建表时指定时间戳精度，这遵循 MySQL 中的 [fractional seconds 语法](https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.htm)。目前支持以下几个时间精度：

- 0: `TimeUnit::Second`

- 3: `TimeUnit::Millisecond`

- 6: `TimeUnit::Microsecond`

-  9: `TimeUnit::Nanosecond` 
 
例如现在我们可以将时间戳的精度指定为微秒：

```sql
mysql> create table demo (ts timestamp(6) time index, cnt int);
Query OK, 0 rows affected (0.05 sec)
```

并插入不同时区的时间戳：

```sql
mysql> insert into demo(ts,cnt) values ('2023-04-04 08:00:00.52+0000', 1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into demo(ts,cnt) values ('2023-04-04 08:00:00.52+0800', 2);
Query OK, 1 row affected (0.01 sec)
```

而所有的时间戳都将以 UTC 时间显示：

```sql
mysql> select * from demo order by ts asc;
+------------------------------+------+
| ts                           | cnt  |
+------------------------------+------+
| 2023-04-04 00:00:00.520+0000 |    2 || 2023-04-04 08:00:00.520+0000 |    1 |
+------------------------------+------+
2 rows in set (0.01 sec)
```

与此同时，在向 MySQL 协议客户端返回结果时，将时间戳按照 ISO8601 格式化，以便显示时区和小数部分。


## 新鲜事

- GreptimeDB binaries 现在默认提供 dashboard 界面。启动 greptimedb，你可以在 http://localhost:4000/dashboard/ 找到 dashboard。

以上是本期《双周精选》的内容，欢迎关注公众号，我们会定期更新项目有关的进展，分享社区发生的新鲜事。同时，也可以通过各种方式参与 GreptimeDB 和其他相关项目。

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