Skip to content

Commit

Permalink
Include extra restrictions for multi-valued indexes (#14614)
Browse files Browse the repository at this point in the history
  • Loading branch information
songrijie committed Jul 27, 2023
1 parent 02c3f08 commit baba4a4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions choose-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ mysql> SHOW WARNINGS;

[多值索引](/sql-statements/sql-statement-create-index.md#多值索引)和普通索引有所不同,TiDB 目前只会使用 [IndexMerge](/explain-index-merge.md) 来访问多值索引。因此要想使用多值索引进行数据访问,请确保`tidb_enable_index_merge` 被设置为 `ON`

多值索引的使用限制请参考 [`CREATE INDEX`](/sql-statements/sql-statement-create-index.md#特性与限制)

目前 TiDB 支持将 `json_member_of``json_contains``json_overlaps` 条件自动转换成 IndexMerge 来访问多值索引。既可以依赖优化器根据代价自动选择,也可通过 [`use_index_merge`](/optimizer-hints.md#use_index_merget1_name-idx1_name--idx2_name-) optimizer hint 或 [`use_index`](/optimizer-hints.md#use_indext1_name-idx1_name--idx2_name-) 指定选择多值索引,见下面例子:

```sql
Expand Down
4 changes: 2 additions & 2 deletions releases/release-6.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ TiDB 版本:6.6.0-[DMR](/releases/versioning.md#开发里程碑版本)

更多信息,请参考[用户文档](/foreign-key.md)

* 支持 MySQL 兼容的多值索引 (Multi-Valued Index)(实验特性)[#39592](https://github.com/pingcap/tidb/issues/39592) @[xiongjiwei](https://github.com/xiongjiwei) @[qw4990](https://github.com/qw4990)
* 支持 MySQL 兼容的多值索引 (Multi-Valued Indexes)(实验特性)[#39592](https://github.com/pingcap/tidb/issues/39592) @[xiongjiwei](https://github.com/xiongjiwei) @[qw4990](https://github.com/qw4990)

TiDB 在 v6.6.0 引入了 MySQL 兼容的多值索引 (Multi-Valued Index)。过滤 JSON 列中某个数组的值是常见的操作,但普通索引对这类操作起不到加速作用。在数组上创建多值索引能够大幅提升过滤的性能。如果 JSON 列中的某个数组上存在多值索引,那么可以利用多值索引过滤带有 `MEMBER OF()``JSON_CONTAINS()``JSON_OVERLAPS()` 函数的检索条件,从而减少大量的 I/O 消耗,提升运行速度。
TiDB 在 v6.6.0 引入了 MySQL 兼容的多值索引 (Multi-Valued Indexes)。过滤 JSON 列中某个数组的值是常见的操作,但普通索引对这类操作起不到加速作用。在数组上创建多值索引能够大幅提升过滤的性能。如果 JSON 列中的某个数组上存在多值索引,那么可以利用多值索引过滤带有 `MEMBER OF()``JSON_CONTAINS()``JSON_OVERLAPS()` 函数的检索条件,从而减少大量的 I/O 消耗,提升运行速度。

多值索引的引入,进一步增强了 TiDB 对 JSON 类型的支持,同时也提升了 TiDB 对 MySQL 8.0 的兼容性。

Expand Down
2 changes: 1 addition & 1 deletion releases/release-7.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ TiDB 7.1.0 为长期支持版本 (Long-Term Support Release, LTS)。

更多信息,请参考[用户文档](/tiflash/tiflash-results-materialization.md)。

* MySQL 兼容的多值索引 (Multi-Valued Index) 成为正式功能 (GA) [#39592](https://github.com/pingcap/tidb/issues/39592) @[xiongjiwei](https://github.com/xiongjiwei) @[qw4990](https://github.com/qw4990) @[YangKeao](https://github.com/YangKeao)
* MySQL 兼容的多值索引 (Multi-Valued Indexes) 成为正式功能 (GA) [#39592](https://github.com/pingcap/tidb/issues/39592) @[xiongjiwei](https://github.com/xiongjiwei) @[qw4990](https://github.com/qw4990) @[YangKeao](https://github.com/YangKeao)

过滤 JSON 列中某个数组的值是一种常见操作,但使用普通索引无法加速此过程。在数组上创建多值索引可以大幅提升过滤性能。如果 JSON 列中的某个数组上存在多值索引,则函数 `MEMBER OF()``JSON_CONTAINS()``JSON_OVERLAPS()` 的检索条件可以利用该多值索引进行过滤,从而减少大量的 I/O 消耗,提升执行速度。

Expand Down
2 changes: 2 additions & 0 deletions sql-statements/sql-statement-create-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Query OK, 1 row affected (0.00 sec)
- 相比于普通索引,DML 会对多值索引产生更多的索引记录的修改,因此多值索引会带来比普通索引更大的性能影响。
- 由于多值索引是一种特殊的表达式索引,因此具有表达式索引的限制。
- 使用备份恢复工具 (BR)、同步工具 (TiCDC)、导入工具 (TiDB Lightning) 无法将定义了多值索引的表备份、同步、导入到低于 v6.6.0 版本的 TiDB。
- 由于多值索引的统计信息暂时还没有被收集,多值索引的选择率基于固定假设。当查询命中多个多值索引时,可能无法选取最优的索引。在这种情况下,建议用优化器提示 [`use_index_merge`](/optimizer-hints.md#use_index_merget1_name-idx1_name--idx2_name-) 来固定执行计划。具体使用方式请参考[使用多值索引](/choose-index.md#使用多值索引)。
- 条件复杂的查询有可能无法选择到多值索引,多值索引支持的条件模式请参考[使用多值索引](/choose-index.md#使用多值索引)。
## 不可见索引
Expand Down

0 comments on commit baba4a4

Please sign in to comment.