diff --git a/docs/en/12-taos-sql/07-index.md b/docs/en/12-taos-sql/07-index.md new file mode 100644 index 0000000000000000000000000000000000000000..cb2a61d3e813ad130476f8f3309d30b7e208a009 --- /dev/null +++ b/docs/en/12-taos-sql/07-index.md @@ -0,0 +1,51 @@ +--- +sidebar_label: Tag Index +title: Tag Index +description: Use Tag Index to Improve Query Performance +--- + +## Introduction + +Prior to TDengine 3.0.3.0 (excluded),only one index is created by default on the first tag of each super talbe, but it's not allowed to dynamically create index on any other tags. From version 3.0.30, you can dynamically create index on any tag of any type. The index created automatically by TDengine is still valid. Query performance can benefit from indexes if you use properly. + +## Syntax + +1. The syntax of creating an index + +```sql +CREATE INDEX index_name ON tbl_name (tagColName) +``` + +In the above statement, `index_name` if the name of the index, `tbl_name` is the name of the super table,`tagColName` is the name of the tag on which the index is being created. `tagColName` can be any type supported by TDengine. + +2. The syntax of drop an index + +```sql +DROP INDEX index_name +``` + +In the above statement, `index_name` is the name of an existing index. If the index doesn't exist, the command would fail but doesn't generate any impact to the system. + +3. The syntax of show indexes in the system + +```sql +SELECT * FROM information_schema.INS_INDEXES +``` + +You can also add filter conditions to limit the results. + +## Detailed Specification + +1. Indexes can improve query performance significantly if they are used properly. The operators supported by tag index include `=`, `>`, `>=`, `<`, `<=`. If you use these operators with tags, indexes can improve query performance significantly. However, for operators not in this scope, indexes don't help. More and more operators will be added in future. + +2. Only one index can be created on each tag, error would be reported if you try to create more than one indexes on same tag. + +3. Each time you can create an index on a single tag, you are not allowed to create indexes on multiple tags together. + +4. The name of each index must be unique across the whole system, regardless of the type of the index, e.g. tag index or sma index. + +5. There is no limit on the number of indexes, but each index may add some burden on the metadata subsystem. So too many indexes may decrease the efficiency of reading or writing metadata and then decrease the system performance. So it's better not to add unnecessary indexes. + +6. You can' create index on a normal table or a child table. + +7. If the unique values of a tag column are too few, it's better not to create index on such tag columns, the benefit would be very small. \ No newline at end of file diff --git a/docs/zh/12-taos-sql/07-index.md b/docs/zh/12-taos-sql/07-index.md new file mode 100644 index 0000000000000000000000000000000000000000..ae16b0b2ec4db26361c4b241fd6188bfe0df9b5e --- /dev/null +++ b/docs/zh/12-taos-sql/07-index.md @@ -0,0 +1,51 @@ +--- +sidebar_label: 标签索引 +title: 标签索引 +description: 使用标签索引提升查询性能 +--- + +## 简介 + +在 TDengine 3.0.3.0 版本之前(不含),默认在第一列 TAG 上建立索引,但不支持给其它列动态添加索引。从 3.0.3.0 版本开始,可以动态地为其它 TAG 列添加索引。对于第一个 TAG 列上自动建立的索引,其在查询中默认生效,且用户无法对其进行任何干预。适当地使用索引能够有效地提升查询性能。 + +## 语法 + +创建索引的语法如下 + +```sql +CREATE INDEX index_name ON tbl_name (tagColName) +``` + +其中 `index_name` 为索引名称, `tbl_name` 为超级表名称,`tagColName` 为要在其上建立索引的 tag 列的名称。`tagColName` 的类型不受限制,即任何类型的 tag 列都可以建立索引。 + +删除索引的语法如下 + +```sql +DROP INDEX index_name +``` + +其中 `index_name` 为已经建立的某个索引的名称,如果该索引不存在则该命令执行失败,但不会对系统产生任何其它影响。 + +查看系统中已经存在的索引 + +```sql +SELECT * FROM information_schema.INS_INDEXES +``` + +也可以为上面的查询语句加上过滤条件以缩小查询范围。 + +## 使用说明 + +1. 索引使用得当能够提升数据过滤的效率,目前支持的过滤算子有 `=`, `>`, `>=`, `<`, `<=`。如果查询过滤条件中使用了这些算子,则索引能够明显提升查询效率。但如果查询过滤条件中使用的是其它算子,则索引起不到作用,查询效率没有变化。未来会逐步添加更多的算子。 + +2. 针对一个 tag 列只能建立一个索引,如果重复创建索引则会报错。 + +3. 每次只能针对一个 tag 列建立一个索引,不能同时对多个 tag 建立索引。 + +4. 整个系统中不管是哪种类型的索引,其名称必须唯一。 + +5. 对索引个数没有限制,但每增加一个索引都会导致系统中的元数据增加,过多的索引会降低元数据存取的效率从而降低整个系统的性能。所以请尽量避免添加不必要的索引。 + +6. 不支持对普通和子表建立索引。 + +7. 如果某个 tag 列的唯一值较少时,不建议对其建立索引,这种情况下收效甚微。 \ No newline at end of file