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

ebnf show collation #17018

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions sql-statements/sql-statement-show-collation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ This statement provides a static list of collations, and is included to provide

## Synopsis

**ShowCollationStmt:**
```ebnf+diagram
ShowCollationStmt ::=
"SHOW" "COLLATION" ShowLikeOrWhere?

![ShowCollationStmt](/media/sqlgram/ShowCollationStmt.png)
ShowLikeOrWhere ::=
"LIKE" SimpleExpr
| "WHERE" Expression
```

## Examples

When new collation framework is disabled, only binary collations are displayed.

```sql
mysql> SHOW COLLATION;
SHOW COLLATION;
```

```
+-------------+---------+------+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+-------------+---------+------+---------+----------+---------+
Expand All @@ -39,7 +47,10 @@ mysql> SHOW COLLATION;
When new collation framework is enabled, `utf8_general_ci` and `utf8mb4_general_ci` are additionally supported.

```sql
mysql> SHOW COLLATION;
SHOW COLLATION;
```

```
+--------------------+---------+------+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+--------------------+---------+------+---------+----------+---------+
Expand All @@ -58,6 +69,25 @@ mysql> SHOW COLLATION;
11 rows in set (0.001 sec)
```

To filter on the character set, you can add a `WHERE` clause.

```sql
SHOW COLLATION WHERE Charset="utf8mb4";
```

```sql
+--------------------+---------+-----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+--------------------+---------+-----+---------+----------+---------+
| utf8mb4_0900_ai_ci | utf8mb4 | 255 | | Yes | 1 |
| utf8mb4_0900_bin | utf8mb4 | 309 | | Yes | 1 |
| utf8mb4_bin | utf8mb4 | 46 | Yes | Yes | 1 |
| utf8mb4_general_ci | utf8mb4 | 45 | | Yes | 1 |
| utf8mb4_unicode_ci | utf8mb4 | 224 | | Yes | 1 |
+--------------------+---------+-----+---------+----------+---------+
5 rows in set (0.00 sec)
```

## MySQL compatibility

The usage of the `SHOW COLLATION` statement in TiDB is fully compatible with MySQL. However, charsets in TiDB might have different default collations compared with MySQL. For details, refer to [Compatibility with MySQL](/mysql-compatibility.md). If you find any compatibility differences, [report a bug](https://docs.pingcap.com/tidb/stable/support).
Expand Down