Skip to content

Commit

Permalink
docs: update log example in data model (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
evenyag authored Dec 26, 2024
1 parent 62b7b7c commit 3fafb93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions docs/user-guide/concepts/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ CREATE TABLE access_logs (
http_refer STRING,
user_agent STRING,
request STRING FULLTEXT,
PRIMARY KEY (remote_addr, http_status, http_method, http_refer, user_agent)
)
PRIMARY KEY (http_status, http_method)
) with ('append_mode'='true');
```

- The time index column is `access_time`.
- `remote_addr`, `http_status`, `http_method`, `http_refer` and `user_agent` are tags.
- `request` is a field that enables full-text index by the [`FULLTEXT` column option](/reference/sql/create.md#fulltext-column-option).
- `http_status`, `http_method` are tags.
- `remote_addr`, `http_refer`, `user_agent` and `request` are fields. `request` is a field that enables full-text index by the [`FULLTEXT` column option](/reference/sql/create.md#fulltext-column-option).
- The table is an [append-only table](/reference/sql/create.md#create-an-append-only-table) for storing logs that may have duplicate timestamps under the same primary key.

To learn how to indicate `Tag`, `Timestamp`, and `Field` columns, Please refer to [table management](/user-guide/administration/manage-data/basic-table-operations.md#create-a-table) and [CREATE statement](/reference/sql/create.md).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ staging_size = "10GB"

### 避免将高基数的列放到主键中

将高基数的列,如 `trace_id``uuid` 等列设置为主键会降低写入和查询的性能。建议建表时使用 [append-only](/reference/sql/create.md#create-an-append-only-table) 表并将这些高基数的列设置为 fields。
将高基数的列,如 `trace_id``uuid` 等列设置为主键会降低写入和查询的性能。建议建表时使用 [append-only](/reference/sql/create.md#创建-append-only-) 表并将这些高基数的列设置为 fields。


### 尽可能使用 append-only 表

一般来说,append-only 表具有更高的扫描性能,因为存储引擎可以跳过合并和去重操作。此外,如果表是 append-only 表,查询引擎可以使用统计信息来加速某些查询。

如果表不需要去重或性能优先于去重,我们建议为表启用 [append_mode](/reference/sql/create.md#create-an-append-only-table)。例如,日志表应该是 append-only 表,因为日志消息可能具有相同的时间戳。
如果表不需要去重或性能优先于去重,我们建议为表启用 [append_mode](/reference/sql/create.md#创建-append-only-)。例如,日志表应该是 append-only 表,因为日志消息可能具有相同的时间戳。


## 写入
Expand All @@ -133,7 +133,7 @@ staging_size = "10GB"
### 按时间窗口写入
虽然 GreptimeDB 可以处理乱序数据,但乱序数据仍然会影响性能。GreptimeDB 从写入的数据中推断出时间窗口的大小,并根据时间戳将数据划分为多个时间窗口。如果写入的行不在同一个时间窗口内,GreptimeDB 需要将它们拆分,这会影响写入性能。

通常,实时数据不会出现上述问题,因为它们始终使用最新的时间戳。如果需要将具有较长时间范围的数据导入数据库,我们建议提前创建表并 [指定 compaction.twcs.time_window 选项](/reference/sql/create.md#create-a-table-with-custom-compaction-options)
通常,实时数据不会出现上述问题,因为它们始终使用最新的时间戳。如果需要将具有较长时间范围的数据导入数据库,我们建议提前创建表并 [指定 compaction.twcs.time_window 选项](/reference/sql/create.md#创建自定义-compaction-参数的表)


## 表结构
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ CREATE TABLE access_logs (
http_refer STRING,
user_agent STRING,
request STRING FULLTEXT,
PRIMARY KEY (remote_addr, http_status, http_method, http_refer, user_agent)
)
PRIMARY KEY (http_status, http_method)
) with ('append_mode'='true');
```
其中:

- 时间索引列为 `access_time`
- `remote_addr``http_status``http_method``http_refer``user_agent` 为 Tag。
- `request` 是通过 [`FULLTEXT` 列选项](/reference/sql/create.md#fulltext-列选项)启用全文索引的字段。
- `http_status``http_method` 为 Tag。
- `remote_addr``http_refer``user_agent``request` 为 Field。`request` 是通过 [`FULLTEXT` 列选项](/reference/sql/create.md#fulltext-列选项)启用全文索引的字段。
- 这个表是一个用于存储日志的 [append-only 表](/reference/sql/create.md#创建-append-only-表)。它允许一个主键下存在重复的时间戳。

要了解如何指定 `Tag``Timestamp``Field` 列,请参见[表管理](/user-guide/administration/manage-data/basic-table-operations.md#创建表)[CREATE 语句](/reference/sql/create.md)

Expand Down

0 comments on commit 3fafb93

Please sign in to comment.