Skip to content

Commit

Permalink
Update on how to connect to TiDB using MySQL Client and the limitatio…
Browse files Browse the repository at this point in the history
…ns of the Global indexes (#19759) (#19797)
  • Loading branch information
ti-chi-bot authored Dec 25, 2024
1 parent 8e9bfd0 commit 4d46b27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions develop/dev-guide-connect-to-tidb.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ After the installation, you can connect to TiDB using the following command:
mysql --host <tidb_server_host> --port 4000 -u root -p --comments
```

The MySQL v9.0 client on macOS cannot correctly load the `mysql_native_password` plugin, causing the error `ERROR 2059 (HY000): Authentication plugin 'mysql_native_password' cannot be loaded` when connecting to TiDB. To address this issue, it is recommended to install and use the MySQL v8.0 client to connect to TiDB. Run the following commands to install it:

```shell
brew install [email protected]
brew unlink mysql
brew link [email protected]
```

If you still encounter errors, you can specify the installation path of the MySQL v8.0 client to connect to TiDB. Run the following command:

```shell
/opt/homebrew/opt/[email protected]/bin/mysql --comments --host ${YOUR_IP_ADDRESS} --port ${YOUR_PORT_NUMBER} -u ${your_user_name} -p
```

Replace `/opt/homebrew/opt/[email protected]/bin/mysql` in the preceding command with the installation path of the MySQL v8.0 client in your actual environment.

</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 @@ -1789,7 +1789,14 @@ ALTER TABLE t1 PARTITION BY HASH (col1) PARTITIONS 3 UPDATE INDEXES (uidx12 LOCA

- If the `GLOBAL` keyword is not explicitly specified in the index definition, TiDB creates a local index by default.
- The `GLOBAL` and `LOCAL` keywords only apply to partitioned tables and do not affect non-partitioned tables. In other words, there is no difference between a global index and a local index in non-partitioned tables.
- DDL operations such as `ADD PARTITION`, `DROP PARTITION`, `TRUNCATE PARTITION`, `REORGANIZE PARTITION`, `SPLIT PARTITION`, and `EXCHANGE PARTITION` also trigger updates to global indexes. The results of these DDL operations will only be returned after the global indexes of the corresponding tables are fully updated. This can delay operations that usually require quick DDL completion, such as data archiving operations (`EXCHANGE PARTITION`, `TRUNCATE PARTITION`, and `DROP PARTITION`). In contrast, when global indexes are not involved, these DDL operations can be completed immediately.
- Currently, TiDB only supports creating unique global indexes on unique columns. If you need to create a global index on a non-unique column, you can include a primary key in the global index to create a composite index. For example, if the non-unique column is `col3` and the primary key is `col1`, you can use the following statement to create a global index on the non-unique column `col3`:

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

- DDL operations such as `DROP PARTITION`, `TRUNCATE PARTITION`, `REORGANIZE PARTITION`, and `EXCHANGE PARTITION` also trigger updates to global indexes. These DDL operations need to wait for the global index updates to complete before returning results, which increases the execution time accordingly. This is particularly evident in data archiving scenarios, such as `DROP PARTITION` and `TRUNCATE PARTITION`. Without global indexes, these operations can typically complete immediately. However, with global indexes, the execution time increases as the number of indexes that need to be updated grows.
- Tables with global indexes do not support the `EXCHANGE PARTITION` operation.
- By default, the primary key of a partitioned table is a clustered index and must include the partition key. If you require the primary key to exclude the partition key, you can explicitly specify the primary key as a non-clustered global index when creating the table, for example, `PRIMARY KEY(col1, col2) NONCLUSTERED GLOBAL`.
- If a global index is added to an expression column, or a global index is also a prefix index (for example `UNIQUE KEY idx_id_prefix (id(10)) GLOBAL`), you need to collect statistics manually for this global index.

Expand Down

0 comments on commit 4d46b27

Please sign in to comment.