# 全文索引搭配 v0.9 日志引擎提升数据搜索效率 | Greptime 双周精选

Source: https://greptime.cn/blogs/2024-07-17-biweekly

## 内容概述

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

最近的内容更新如下：
- **支持全文索引**：增加了全文索引以支持搜索日志数据

- **视图相关语句**：添加了用于查看、创建和删除视图的 SQL 语句

- **优化 `last_value` 函数的性能**：增加多项优化显著提高 last_value 的性能

- **分布式启动 `flownode`**：支持启动 flownode 以在分布式模式下支持持续聚合功能

## 社区贡献者名单

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

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

- @[CookiePieWw](https://github.com/CookiePieWw) ([db#4233](https://github.com/GreptimeTeam/greptimedb/pull/4233) [db#4197](https://github.com/GreptimeTeam/greptimedb/pull/4197))

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

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

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

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

- @[scintillavoy](https://github.com/scintillavoy) ([promql-parser#89](https://github.com/GreptimeTeam/promql-parser/pull/89))

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

<img src="/zh/blogs/2024-07-17-biweekly/contributorpost.webp" alt="Contributor of GreptimeDB" style="width: 80%; margin: 0 auto"/>

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

## PR 亮点
### [db#4310](https://github.com/GreptimeTeam/greptimedb/pull/4310) 支持全文索引

添加了新的 SQL 语法 `FULLTEXT` 和 gRPC 选项，支持在创建表时开启全文索引。例如：

```sql
CREATE TABLE log (
    ts TIMESTAMP TIME INDEX,
    msg TEXT FULLTEXT WITH (analyzer='English', case_sensitive='true'),
);
```

上述 SQL 会在 `msg` 列上创建一个大小写敏感的基于英语的全文索引分析器，意味着可以用 SQL 从 `msg` 列中匹配内容相似的日志：

```sql
SELECT * FROM log WHERE MATCHES(msg, 'error OR fail');
```

### [db#4086](https://github.com/GreptimeTeam/greptimedb/pull/4086) [db#4231](https://github.com/GreptimeTeam/greptimedb/pull/4231) [db#4360](https://github.com/GreptimeTeam/greptimedb/pull/4360) 添加视图相关语句

该 PR 添加了 `SHOW CREATE VIEW`，`DROP VIEW` 和 `SHOW VIEWS` 这样的 SQL 语句，例如：

```sql
public=> CREATE VIEW v1 as SELECT * FROM numbers LIMIT 10;
OK 0
public=> SHOW CREATE VIEW v1;
 View |                   Create View                    
------+--------------------------------------------------
 v1   | CREATE VIEW v1 AS SELECT * FROM numbers LIMIT 10
(1 row)

public=> SHOW VIEWS;
 Views 
-------
 v1
(1 row)

public=> DROP VIEW v1;
OK 0
```

### [db#4357](https://github.com/GreptimeTeam/greptimedb/pull/4357) [db#4369](https://github.com/GreptimeTeam/greptimedb/pull/4369) 优化 `last_value` 函数的性能

该 PR 为 `last_value` 函数实现了如添加优化规则和缓存等优化，使 `last_value` 函数的耗时显著下降。在下述查询中，耗时从优化前的 7 秒提升到了 0.5 秒左右，有效减少了用户的时间成本：

```sql
select last_value(hostname order by ts), last_value(region order by ts), last_value(datacenter order by ts), last_value(rack order by ts), last_value(os order by ts), last_value(arch order by ts), last_value(team order by ts), last_value(service order by ts), last_value(service_version order by ts), last_value(service_environment order by ts), last_value(usage_user order by ts), last_value(usage_system order by ts), last_value(usage_idle order by ts), last_value(usage_nice order by ts), last_value(usage_iowait order by ts), last_value(usage_irq order by ts), last_value(usage_softirq order by ts), last_value(usage_steal order by ts), last_value(usage_guest order by ts), last_value(usage_guest_nice order by ts) from cpu group by hostname;
```

### [db#4256](https://github.com/GreptimeTeam/greptimedb/pull/4256) 分布式中启动 `flownode`

该 PR 添加了在分布式模式下启动 `flownode` 的能力，允许用户在分布式模式下添加持续聚合任务，比如可以用下述命令启动 `flownode`：

```shell
greptime flownode start --node-id=0 --rpc-addr=127.0.0.1:6800 --metasrv-addrs=127.0.0.1:3002;
```

之后用户就可以使用 `CREATE FLOW` 来创建新的持续聚合任务了，与 standalone 模式的使用规则一致。

## Good First Issue

### [db#4351 在默认值位置解析数字 32768 报错](https://github.com/GreptimeTeam/greptimedb/issues/4351)

在 GreptimeDB中，SMALLINT 的范围应该是 -32768 到 32767，但是一个错误的实现使得在创建表时声明默认值时实际接受的值范围变成了 -32767 到 32767，我们可以通过修复解析默认值的函数来修复这个问题。

关键词：查询，SQL

难度：简单

### [db#4340 改进错误信息](https://github.com/GreptimeTeam/greptimedb/issues/4340)

GreptimeDB 中的错误信息有以下问题：

- 源自 DataFusion 的错误总是会被展示成 Internal Error，不仅让人困惑而且毫无帮助；

- MySQL 和 PostgreSQL 协议同样只会返回内部错误，对排查错误没有帮助；

- 超时错误的错误信息不够清晰。

关键词：DataFusion，SQL

难度：中等

### [db#4351 从 `GreptimeRequest` 中移除 `QueryRequest`](https://github.com/GreptimeTeam/greptimedb/issues/4351)

在 `GreptimeRequest` 枚举中有 `QueryRequest` 这一项枚举值，但是目前 `GreptimeRequest` 不应该被用于查询请求，所以该项枚举值以及使用它的代码可以被删除掉（注意：这不包括同名的 `QueryRequest` 结构体自身！）。

关键词：Protobuf

难度：简单

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