Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference/sql: add document for expression index #2312

Merged
merged 13 commits into from
Mar 4, 2020

Conversation

wjhuang2016
Copy link
Member

@wjhuang2016 wjhuang2016 commented Feb 26, 2020

What is changed, added or deleted?

Add document for expression index.

What is the related PR or file link(s)?

  • Reference link(s):
  • This PR is to align with:
  • N/A (not applicable)

Important Notice:

If your changes apply to multiple TiDB documentation versions, to trigger the bot to cherry-pick this PR to other release branches, make sure you add labels such as:

  • needs-cherry-pick-3.0
  • needs-cherry-pick-3.1
  • needs-cherry-pick-2.1

@wjhuang2016 wjhuang2016 requested a review from TomShawn February 26, 2020 10:26
@TomShawn TomShawn self-assigned this Feb 26, 2020
@TomShawn TomShawn added translation/doing This PR’s assignee is translating this PR. dev v4.0 This PR/issue applies to TiDB v4.0. labels Feb 26, 2020
TomShawn
TomShawn previously approved these changes Feb 26, 2020
Copy link
Contributor

@TomShawn TomShawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TomShawn TomShawn dismissed their stale review February 26, 2020 12:49

LGTM, please involve a technical review.

@yikeke yikeke removed the dev label Mar 3, 2020
Copy link
Contributor

@Deardrops Deardrops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@TomShawn TomShawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

@@ -128,6 +128,30 @@ CREATE UNIQUE INDEX c1 ON t1 (c1);
Query OK, 0 rows affected (0.31 sec)
```

## 表达式索引

TiDB 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。示例如下:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TiDB 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。示例如下:
TiDB 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。

SELECT * FROM t WHERE lower(name) = "pingcap";
```

如果建立了如下的表达式索引,上述的查询就可以使用索引进行加速:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
如果建立了如下的表达式索引,上述的查询就可以使用索引进行加速
如果建立了如下的表达式索引,就可以使用索引加速以上查询

CREATE INDEX idx ON t ((lower(name)));
```

维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。


维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。

表达式索引的语法和限制与 MySQL 相同,是通过将索引建立在隐藏的虚拟生成列(generated virtual column)上来实现的。因此所支持的表达式继承了虚拟生成列的所有[限制](/reference/sql/generated-columns.md#局限性)。目前,建立了索引的表达式只有在 `FIELD` 子句、`WHERE` 子句和 `ORDER BY` 子句中时,优化器才能使用表达式索引。后续将支持 `GROUP BY` 子句。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
表达式索引的语法和限制与 MySQL 相同,是通过将索引建立在隐藏的虚拟生成列(generated virtual column)上来实现的。因此所支持的表达式继承了虚拟生成列的所有[限制](/reference/sql/generated-columns.md#局限性)。目前,建立了索引的表达式只有在 `FIELD` 子句、`WHERE` 子句和 `ORDER BY` 子句中时,优化器才能使用表达式索引。后续将支持 `GROUP BY` 子句。
表达式索引的语法和限制与 MySQL 相同,是通过将索引建立在隐藏的虚拟生成列 (generated virtual column) 上来实现的。因此所支持的表达式继承了虚拟生成列的所有[限制](/reference/sql/generated-columns.md#局限性)。目前,建立了索引的表达式只有在 `FIELD` 子句、`WHERE` 子句和 `ORDER BY` 子句中时,优化器才能使用表达式索引。后续将支持 `GROUP BY` 子句。

Copy link
Contributor

@TomShawn TomShawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TomShawn TomShawn merged commit 5832228 into pingcap:master Mar 4, 2020
@TomShawn TomShawn removed their assignment Mar 16, 2020
@TomShawn TomShawn added translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR. and removed translation/doing This PR’s assignee is translating this PR. labels Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR. v4.0 This PR/issue applies to TiDB v4.0.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants