Skip to content

Commit 13fe94a

Browse files
authored
docs: add sql example to the overview of user guide (#1057)
1 parent fa62a59 commit 13fe94a

File tree

2 files changed

+128
-8
lines changed

2 files changed

+128
-8
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
11
# Overview
22

3+
Welcome to the user guide for GreptimeDB.
4+
5+
GreptimeDB is the unified time series database for metrics, events, and logs,
6+
providing real-time insights from Edge to Cloud at any scale.
7+
This guide will help you explore each powerful feature of GreptimeDB.
8+
9+
## SQL query example
10+
11+
Let's start with a SQL query example.
12+
13+
To monitor the performance and reliability of specific metrics,
14+
engineers commonly analyze data over time at regular intervals using queries.
15+
This often involves joining two data sources.
16+
However, executing a query like the one below was previously impossible,
17+
which is now possible with GreptimeDB.
18+
19+
```sql
20+
SELECT
21+
host,
22+
approx_percentile_cont(latency, 0.95) RANGE '15s' as p95_latency,
23+
count(error) RANGE '15s' as num_errors,
24+
FROM
25+
metrics INNER JOIN logs on metrics.host = logs.host
26+
WHERE
27+
time > now() - INTERVAL '1 hour' AND
28+
matches(path, '/api/v1/avator')
29+
ALIGN '5s' BY (host) FILL PREV
30+
```
31+
32+
This query analyzes the performance and errors of a specific API path (`/api/v1/avator`) over the past hour.
33+
It calculates the 95th percentile latency and the number of errors in 15-second intervals and aligns the results to 5-second intervals for continuity and readability.
34+
35+
Break down the query step by step:
36+
37+
1. SELECT clause:
38+
- `host`: Selects the host field.
39+
- `approx_percentile_cont(latency, 0.95) RANGE '15s' as p95_latency`: Calculates the 95th percentile of latency within a 15-second range and labels it as p95_latency.
40+
- `count(error) RANGE '15s' as num_errors`: Counts the number of errors within a 15-second range and labels it as num_errors.
41+
2. FROM clause:
42+
- `metrics INNER JOIN logs on metrics.host = logs.host`: Joins the metrics and logs tables on the host field.
43+
3. WHERE clause:
44+
- `time > now() - INTERVAL '1 hour'`: Filters the records to include only those from the past hour.
45+
- `matches(path, '/api/v1/avator')`: Filters the records to include only those matching the path `/api/v1/avator`.
46+
4. ALIGN clause:
47+
- `ALIGN '5s' BY (host) FILL PREV`: Aligns the results to every 5 seconds and fills in missing values with the previous non-null value.
48+
49+
Next, let's analyze the key features of GreptimeDB demonstrated by this query example:
50+
51+
- **Unified Storage:** GreptimeDB stores both time-series metrics and [logs](/user-guide/logs/overview.md) in one database. The simplified architecture and data consistency enhances the ability to analyze and troubleshoot issues, and can lead to cost savings and improved system performance.
52+
- **Unique Data Model:** The unique [data model](/user-guide/concepts/data-model.md) with time index and full-text index greatly improves query performance and has stood the test of large data sets. It not only supports metric [insertion](/user-guide/write-data/overview.md) and [query](/user-guide/query-data/overview.md), but also provides a very friendly way to [write](/user-guide/logs/write-logs.md) and [query](/user-guide/logs/query-logs.md) logs.
53+
- **Range Queries:** GreptimeDB supports [range queries](/user-guide/query-data/sql#aggregate-data-by-time-window) to evaluate [expressions](/reference/sql/functions/overview.md) over time, providing insights into metric trends. You can also [continuously aggregate](/user-guide/continuous-aggregation/overview) data for further analysis.
54+
- **SQL and Multiple Protocols:** GreptimeDB uses SQL as the main query language and supports [multiple protocols](/user-guide/clients/overview.md#protocols), which greatly reduces the learning curve and development cost. You can easily migrate from Prometheus or [Influxdb to GreptimeDB](/user-guide/migrate-to-greptimedb/migrate-from-influxdb), or just start with GreptimeDB.
55+
- **JOIN Operations:** The data model of GreptimeDB's time series tables makes it the first time series database to support [JOIN operations](/reference/sql/join.md).
56+
57+
Having understood these features, you can now go directly to exploring the features that interest you, or continue reading the next step in the sequence.
58+
59+
## Next steps
60+
361
* [Concepts](./concepts/overview.md)
462
* [Clients](./clients/overview.md)
563
* [Table Management](./table-management.md)
64+
* [Migrate to GreptimeDB](./migrate-to-greptimedb/migrate-from-influxdb.md)
665
* [Write data](./write-data/overview.md)
766
* [Query data](./query-data/overview.md)
67+
* [Continuous Aggregation](./continuous-aggregation/overview.md)
868
* [Python Scripts](./python-scripts/overview.md)
969
* [Operations](./operations/overview.md)
1070
* [Cluster](./cluster.md)
Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
11
# 概述
22

3-
- [概念](../user-guide/concepts/overview.md)
4-
- [客户端](../user-guide/clients/overview.md)
5-
- [表管理](../user-guide/table-management.md)
6-
- [数据写入](../user-guide/write-data/overview.md)
7-
- [数据查询](../user-guide/query-data/overview.md)
8-
- [Python 脚本](../user-guide/python-scripts/overview.md)
9-
- [运维操作](../user-guide/operations/overview.md)
10-
- [集群](../user-guide/cluster.md)
3+
欢迎使用 GreptimeDB 用户指南。
4+
5+
GreptimeDB 是用于指标、事件和日志的统一时间序列数据库,
6+
可提供从边缘到云的任何规模的实时洞察。
7+
本指南将帮助你探索 GreptimeDB 的每个强大功能。
8+
9+
## SQL 查询示例
10+
11+
让我们从一个 SQL 查询示例开始。
12+
13+
为了监控特定指标的性能和可靠性,
14+
工程师通常定期查询并分析一段时间内的数据。
15+
在分析过程中通常涉及到 JOIN 两个数据源,
16+
但如下方的查询在之前是不可能的,
17+
而现在使用 GreptimeDB 就可以做到:
18+
19+
```sql
20+
SELECT
21+
host,
22+
approx_percentile_cont(latency, 0.95) RANGE '15s' as p95_latency,
23+
count(error) RANGE '15s' as num_errors,
24+
FROM
25+
metrics INNER JOIN logs on metrics.host = logs.host
26+
WHERE
27+
time > now() - INTERVAL '1 hour' AND
28+
matches(path, '/api/v1/avator')
29+
ALIGN '5s' BY (host) FILL PREV
30+
```
31+
32+
该查询分析了过去一小时内特定 API 路径 (`/api/v1/avator`) 的性能和错误。
33+
它计算了每个 15 秒间隔内的第 95 百分位延迟和错误数量,并将结果对齐到每个 5 秒间隔以保持连续性和可读性。
34+
35+
逐步解析该查询:
36+
37+
1. SELECT 子句:
38+
- `host`:选择 host 字段。
39+
- `approx_percentile_cont(latency, 0.95) RANGE '15s' as p95_latency`:计算 15 秒范围内的第 95 百分位延迟,并将其标记为 p95_latency。
40+
- `count(error) RANGE '15s' as num_errors`:计算 15 秒范围内的错误数量,并将其标记为 num_errors。
41+
2. FROM 子句:
42+
- `metrics INNER JOIN logs on metrics.host = logs.host`:在 host 字段上将 metrics 和 logs 表进行连接。
43+
3. WHERE 子句:
44+
- `time > now() - INTERVAL '1 hour'`:筛选出过去一小时内的记录。
45+
- `matches(path, '/api/v1/avator')`:筛选出特定 API 路径 `/api/v1/avator` 的记录。
46+
4. ALIGN 子句:
47+
- `ALIGN '5s' BY (host) FILL PREV`:将结果对齐到每 5 秒,并使用前一个非空值填充缺失值。
48+
49+
接下来解析一下该查询示例展示的 GreptimeDB 关键功能:
50+
51+
- **统一存储:** GreptimeDB 将时间序列指标和 [日志](/user-guide/logs/overview.md) 存储在一个数据库中。简化的架构和数据一致性增强了分析和解决问题的能力,并可节省成本且提高系统性能。
52+
- **独特的数据模型:** 独特的[数据模型](/user-guide/concepts/data-model.md)搭配时间索引和全文索引,大大提升了查询性能,并在超大数据集上也经受住了考验。它不仅支持[数据指标的插入](/user-guide/write-data/overview.md)[查询](/user-guide/query-data/overview.md),也提供了非常友好的方式便于日志的[写入](/user-guide/logs/write-logs.md)[查询](/user-guide/logs/query-logs.md)
53+
- **范围查询:** GreptimeDB 支持[范围查询](/user-guide/query-data/sql#aggregate-data-by-time-window)来计算一段时间内的[表达式](/reference/sql/functions/overview.md),从而了解指标趋势。你还可以[持续聚合](/user-guide/continuous-aggregation/overview)数据以进行进一步分析。
54+
- **SQL 和多种协议:** GreptimeDB 使用 SQL 作为主要查询语言,并支持[多种协议](/user-guide/clients/overview.md#protocols),大大降低了学习曲线和接入成本。你可以轻松从 Prometheus 或 [Influxdb 迁移](/user-guide/migrate-to-greptimedb/migrate-from-influxdb)至 GreptimeDB,或者从 0 接入 GreptimeDB。
55+
- **JOIN 操作:** GreptimeDB 的时间序列表的数据模型,使其成为第一个支持[JOIN 操作](reference/sql/join.md)的时序数据库。
56+
57+
了解了这些功能后,你现在可以直接探索感兴趣的功能,或按顺序继续阅读下一步骤。
58+
59+
## 下一步
60+
61+
* [概念](./concepts/overview.md)
62+
* [客户端](./clients/overview.md)
63+
* [表管理](./table-management.md)
64+
* [迁移到 GreptimeDB](./migrate-to-greptimedb/migrate-from-influxdb.md)
65+
* [数据写入](./write-data/overview.md)
66+
* [数据查询](./query-data/overview.md)
67+
* [持续聚合](./continuous-aggregation/overview.md)
68+
* [Python 脚本](./python-scripts/overview.md)
69+
* [运维操作](./operations/overview.md)
70+
* [集群](./cluster.md)

0 commit comments

Comments
 (0)