-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM, please involve a technical review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。示例如下: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TiDB 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。示例如下: | |
TiDB 不仅能将索引建立在表中的一个或多个列上,还可以将索引建立在一个表达式上。当查询涉及表达式时,表达式索引能够加速这些查询。 |
SELECT * FROM t WHERE lower(name) = "pingcap"; | ||
``` | ||
|
||
如果建立了如下的表达式索引,上述的查询就可以使用索引进行加速: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果建立了如下的表达式索引,上述的查询就可以使用索引进行加速: | |
如果建立了如下的表达式索引,就可以使用索引加速以上查询: |
CREATE INDEX idx ON t ((lower(name))); | ||
``` | ||
|
||
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。 | |
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。 |
|
||
维护表达式索引的代价比一般的索引更高,因为在插入或者更新每一行时都需要计算出表达式的值。然而,因为表达式的值已经存储在索引中,所以当优化器选择表达式索引时,表达式的值就不需要再计算。因此,当查询速度比插入速度和更新速度更重要时,可以考虑建立表达式索引。 | ||
|
||
表达式索引的语法和限制与 MySQL 相同,是通过将索引建立在隐藏的虚拟生成列(generated virtual column)上来实现的。因此所支持的表达式继承了虚拟生成列的所有[限制](/reference/sql/generated-columns.md#局限性)。目前,建立了索引的表达式只有在 `FIELD` 子句、`WHERE` 子句和 `ORDER BY` 子句中时,优化器才能使用表达式索引。后续将支持 `GROUP BY` 子句。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
表达式索引的语法和限制与 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` 子句。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What is changed, added or deleted?
Add document for expression index.
What is the related PR or file link(s)?
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: