Skip to content

Commit 6fea5a1

Browse files
authored
docs: update IOT docs (#4050)
1 parent ef25828 commit 6fea5a1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

docs/en/openmldb_sql/ddl/CREATE_TABLE_STATEMENT.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ The index key must be configured, and other configuration items are optional. Th
241241
| `ABSORLAT` | It defines the expiration time and the maximum number of live records. The configuration value is a 2-tuple of the form `(100m, 10), (1d, 1)`. The maximum can be configured `(15768000m, 1000)`. | Records will be eliminated if either the time expires **or** the number of records exceeds the maximum limit. | `INDEX(key=c1, ts=c6, ttl=(120min, 100), ttl_type=absorlat)`. Records will be eliminated when either the number of records exceeds 100 **or** the records expire. |
242242
| `ABSANDLAT` | It defines the expiration time and the maximum number of live records. The configuration value is a 2-tuple of the form `(100m, 10), (1d, 1)`. The maximum can be configured `(15768000m, 1000)`. | Records will only be eliminated when both the time expires **and** the number of records exceeds the maximum limit. | `INDEX(key=c1, ts=c6, ttl=(120min, 100), ttl_type=absandlat)`. Records will only be eliminated when the number of records exceeds 100 **and** the records expire. |
243243

244+
#### Index-Organized Table(IOT)
245+
246+
When creating a Covering index using KEY in OpenMLDB, the index stores the complete data row, which results in higher memory usage. If lower memory consumption is desired at the cost of some performance degradation, an IOT table can be used. In an IOT table, three types of indexes can be created:
247+
- `CKEY`:Clustered index, storing the complete data row. The configured CKEY and TS are used to uniquely identify a row of data. If a duplicate primary key is inserted, the data will be updated (this triggers the deletion of old data in all indexes, followed by the insertion of new data, which may incur performance overhead). It is also possible to use only CKEY without configuring TS, where CKEY uniquely identifies a row of data. Queries using this index suffer no performance loss.
248+
- `SKEY`:Secondary index, storing the primary key. If TS is not configured, data under the same SKEY is sorted by insertion time. During query execution, the corresponding primary key values are first located in the Secondary index, and then the data is retrieved based on the primary key, resulting in some performance loss.
249+
- `KEY`:Covering index, storing the complete data row. If TS is not configured, data under the same KEY is sorted by insertion time. Queries using this index suffer no performance loss.
250+
251+
When creating an IOT table, the first index must be the only Clustered index, while other indexes are optional. Changing the order of the Clustered index is currently not supported.
252+
253+
```sql
254+
CREATE TABLE iot (c1 int64, c2 int64, c3 int64, INDEX(ckey=c1, ts=c2)); -- Clustered index
255+
CREATE TABLE iot (c1 int64, c2 int64, c3 int64, INDEX(ckey=c1), INDEX(skey=c2)); -- Clustered index and Secondary index
256+
CREATE TABLE iot (c1 int64, c2 int64, c3 int64, INDEX(ckey=c1), INDEX(skey=c2), INDEX(key=c3)); -- Clustered index、Secondary index and Covering index
257+
```
258+
259+
The TTL behavior of indexes in an IOT table differs from that of a regular table. When data is evicted by TTL from the IOT Clustered index, it triggers deletion operations in all other indexes. In contrast, TTL eviction from a Secondary index or a Covering index only removes data within the respective index itself and does not trigger deletions in other indexes.
260+
261+
Generally, unless it is necessary to make Secondary and Covering indexes more memory-efficient, you can configure TTL only for the Clustered index and leave the TTL unset for Secondary and Covering indexes.
262+
263+
##### Notes
264+
265+
- An IOT table does not support concurrent writes of multiple rows with the same primary key, as this may lead to conflicts causing at least one write to fail. Pre-existing rows with the same primary key in the IOT table will be overwritten without requiring additional handling. To avoid the need for import repairs, perform data cleansing before import by deduplicating records with the same primary key in the source data. (Overwriting data triggers deletions in all indexes, resulting in very low efficiency even for single-threaded writes. Therefore, single-threaded import is not recommended.)
266+
244267
#### Example
245268

246269
**Example 1**

docs/zh/openmldb_sql/ddl/CREATE_TABLE_STATEMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ IndexOption ::=
223223

224224
| 配置项 | 描述 | expr | 用法示例 |
225225
|------------|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
226-
| `KEY/CKEY/SKEY` | 索引列(必选)。OpenMLDB支持单列索引,也支持联合索引。当`KEY`后只有一列时,仅在该列上建立索引。当`KEY`后有多列时,建立这几列的联合索引:将多列按顺序拼接成一个字符串作为索引。多KEY使用见[Index-Orgnized Table(IOT)](#index-orgnized-tableiot)| 支持单列索引:`ColumnName`<br/>或联合索引:<br/>`(ColumnName (, ColumnName)* ) ` | 单列索引:`INDEX(KEY=col1)`<br />联合索引:`INDEX(KEY=(col1, col2))` |
226+
| `KEY/CKEY/SKEY` | 索引列(必选)。OpenMLDB支持单列索引,也支持联合索引。当`KEY`后只有一列时,仅在该列上建立索引。当`KEY`后有多列时,建立这几列的联合索引:将多列按顺序拼接成一个字符串作为索引。多KEY使用见[Index-Organized Table(IOT)](#index-organized-tableiot)| 支持单列索引:`ColumnName`<br/>或联合索引:<br/>`(ColumnName (, ColumnName)* ) ` | 单列索引:`INDEX(KEY=col1)`<br />联合索引:`INDEX(KEY=(col1, col2))` |
227227
| `TS` | 索引时间列(可选)。同一个索引上的数据将按照时间索引列排序。当不显式配置`TS`时,使用数据插入的时间戳作为索引时间。时间列的类型只能为BigInt或者Timestamp | `ColumnName` | `INDEX(KEY=col1, TS=std_time)`。索引列为col1,col1相同的数据行按std_time排序。 |
228228
| `TTL_TYPE` | 淘汰规则(可选)。包括四种类型,当不显式配置`TTL_TYPE`时,默认使用`ABSOLUTE`过期配置。 | 支持的expr如下:`ABSOLUTE` <br/> `LATEST`<br/>`ABSORLAT`<br/> `ABSANDLAT`| 具体用法可以参考下文“TTL和TTL_TYPE的配置细则” |
229229
| `TTL` | 最大存活时间/条数(可选)。依赖于`TTL_TYPE`,不同的`TTL_TYPE`有不同的`TTL` 配置方式。当不显式配置`TTL`时,`TTL=0`,表示不设置淘汰规则,OpenMLDB将不会淘汰记录。 | 支持数值:`int_literal`<br/> 或数值带时间单位(`S,M,H,D`):`interval_literal`<br/>或元组形式:`( interval_literal , int_literal )` |具体用法可以参考下文“TTL和TTL_TYPE的配置细则” |
@@ -240,7 +240,7 @@ IndexOption ::=
240240
```{note}
241241
最大过期时间和最大存活条数的限制,是出于性能考虑。如果你一定要配置更大的TTL值,可先创建表时临时使用合规的TTL值,然后使用nameserver的UpdateTTL接口来调整到所需的值(可无视max限制),生效需要经过一个gc时间;或者,调整nameserver配置`absolute_ttl_max`和`latest_ttl_max`,重启生效后再创建表。
242242
```
243-
#### Index-Orgnized Table(IOT)
243+
#### Index-Organized Table(IOT)
244244

245245
索引使用KEY设置时创建Covering索引,在OpenMLDB中Covering索引存储完整的数据行,也因此占用内存较多。如果希望内存占用更低,同时允许性能损失,可以使用IOT表。IOT表中可以建三种类型的索引:
246246
- `CKEY`:Clustered索引,存完整数据行。配置的CKEY+TS用于唯一标识一行数据,INSERT重复主键时将更新数据(会触发所有索引上的删除旧数据,再INSERT新数据,性能会有损失)。也可只使用CKEY,不配置TS,CKEY唯一标识一行数据。查询到此索引的性能无损失。

0 commit comments

Comments
 (0)