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

Update how to connect TiDB by MySQL Client and the limitations of the global indexes #19345

Merged
merged 11 commits into from
Dec 25, 2024
14 changes: 14 additions & 0 deletions develop/dev-guide-connect-to-tidb.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ sudo yum install mysql
mysql --host <tidb_server_host> --port 4000 -u root -p --comments
```

macOS 上的 MySQL v9.0 客户端无法正确加载 `mysql_native_password` 插件,导致连接 TiDB 时报错 `ERROR 2059 (HY000): Authentication plugin 'mysql_native_password' cannot be loaded`。为解决该问题,建议安装并使用 MySQL v8.0 客户端来连接 TiDB 。安装命令如下:

```shell
brew install mysql-client@8.0
brew unlink mysql
brew link mysql-client@8.0
```

如果仍然遇到问题,可以尝试指定 MySQL v8.0 客户端的安装路径来使用 MySQL v8.0 客户端连接 TiDB。连接命令如下:

```shell
/opt/homebrew/opt/mysql-client@8.0/bin/mysql --comments --host ${YOUR_IP_ADDRESS} --port ${YOUR_PORT_NUMBER} -u ${your_user_name} -p
```

hfxsd marked this conversation as resolved.
Show resolved Hide resolved
</div>

<div label="MySQL Shell">
Expand Down
9 changes: 8 additions & 1 deletion partitioned-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,14 @@ ALTER TABLE t1 PARTITION BY HASH (col1) PARTITIONS 3 UPDATE INDEXES (uidx12 LOCA

- 如果索引定义中未显式指定 `GLOBAL` 关键字,TiDB 将默认创建局部索引 (Local Index)。
- `GLOBAL` 和 `LOCAL` 关键字仅适用于分区表,对非分区表没有影响。即在非分区表中,全局索引和局部索引之间没有区别。
- DDL 操作如 `ADD PARTITION`、`DROP PARTITION`、`TRUNCATE PARTITION`、`REORGANIZE PARTITION`、`SPLIT PARTITION` 和 `EXCHANGE PARTITION` 等也会触发对全局索引的更新,这些 DDL 的执行结果将在全局索引更新完成后才会返回。因此,这可能会延迟一些通常需要快速完成的 DDL 的操作,如数据归档操作(`EXCHANGE PARTITION`、`TRUNCATE PARTITION` 和 `DROP PARTITION`)。而如果没有全局索引,这些 DDL 操作可以立即执行完成。
- 当前仅支持为唯一列创建全局索引 (Unique Global Index)。如果需要对非唯一列创建全局索引,该索引必须包含分区键并形成复合索引,且非唯一列应位于分区键之前。例如,如果非唯一列是 `col3` 而分区键是 `col1`,可以通过执行以下 SQL 语句为 `col3` 创建全局索引:
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

```sql
ALTER TABLE ... ADD UNIQUE INDEX(col3, col1) GLOBAL;
```

- 以下 DDL 操作会触发全局索引的更新:`DROP PARTITION`、`TRUNCATE PARTITION`、`REORGANIZE PARTITION` 和 `EXCHANGE PARTITION`。这些 DDL 需等待全局索引更新完成后才会返回结果,耗时会相应增加。尤其是在数据归档场景下,如 `DROP PARTITION` 和 `TRUNCATE PARTITION`,若没有全局索引,通常可以立即完成;但使用全局索引后,耗时会随着所需更新的索引数量而增加。
Frank945946 marked this conversation as resolved.
Show resolved Hide resolved
- 包含全局索引的表不支持 `EXCHANGE PARTITION`。
- 默认情况下,分区表的主键为聚簇索引,且必须包含分区键。如果要求主键不包含分区建,可以在建表时显式指定主键为非聚簇的全局索引,例如:`PRIMARY KEY(col1, col2) NONCLUSTERED GLOBAL`。
- 如果在表达式列上添加了全局索引,或者一个全局索引同时也是前缀索引(如 `UNIQUE KEY idx_id_prefix (id(10)) GLOBAL`),你需要为该全局索引手动收集统计信息。

Expand Down
Loading