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

Capitalize sql keywords in several files #4862

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions auto-random.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ aliases: ['/docs-cn/dev/auto-random/','/docs-cn/dev/reference/sql/attributes/aut
以下面语句建立的表为例:

```sql
create table t (a bigint primary key auto_increment, b varchar(255))
CREATE TABLE t (a bigint PRIMARY KEY AUTO_INCREMENT, b varchar(255))
```

在以上语句所建的表上执行大量未指定主键值的 `INSERT` 语句,示例如下:

```sql
insert into t(b) values ('a'), ('b'), ('c')
INSERT INTO t(b) VALUES ('a'), ('b'), ('c')
```

如以上语句,由于未指定主键列的值(`a` 列),TiDB 会使用连续自增的行值作为行 ID,可能导致单个 TiKV 节点上产生写入热点,进而影响对外提供服务的性能。要避免这种写入热点,可以在执行建表语句时为 `a` 列指定 `AUTO_RANDOM` 属性而不是 `AUTO_INCREMENT` 属性。示例如下:

{{< copyable "sql" >}}

```sql
create table t (a bigint primary key auto_random, b varchar(255))
CREATE TABLE t (a bigint PRIMARY KEY AUTO_RANDOM, b varchar(255))
```

或者

{{< copyable "sql" >}}

```sql
create table t (a bigint auto_random, b varchar(255), primary key (a))
CREATE TABLE t (a bigint AUTO_RANDOM, b varchar(255), PRIMARY KEY (a))
```

此时再执行形如 `INSERT INTO t(b) values...` 的 `INSERT` 语句。
Expand All @@ -60,7 +60,7 @@ create table t (a bigint auto_random, b varchar(255), primary key (a))
{{< copyable "sql" >}}

```sql
create table t (a bigint primary key auto_random(3), b varchar(255))
CREATE TABLE t (a bigint PRIMARY KEY AUTO_RANDOM(3), b varchar(255))
```

以上建表语句中,shard bits 的数量为 `3`。shard bits 的数量的取值范围是 `[1, field_max_bits)`,其中 `field_max_bits` 为整型主键列类型占用的位长度。
Expand All @@ -70,16 +70,15 @@ create table t (a bigint primary key auto_random(3), b varchar(255))
{{< copyable "sql" >}}

```sql
show warnings
SHOW WARNINGS
```

```
```sql
+-------+------+----------------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------------+
| Note | 1105 | Available implicit allocation times: 1152921504606846976 |
+-------+------+----------------------------------------------------------+

```

> **注意:**
Expand All @@ -88,19 +87,19 @@ show warnings

另外,要查看某张含有 `AUTO_RANDOM` 属性的表的 shard bits 数量,可以在系统表 `information_schema.tables` 中 `TIDB_ROW_ID_SHARDING_INFO` 一列看到模式为 `PK_AUTO_RANDOM_BITS=x` 的值,其中 `x` 为 shard bits 的数量。

`AUTO RANDOM` 列隐式分配的值会影响 `last_insert_id()`。可以使用 `select last_insert_id()` 获取上一次 TiDB 隐式分配的 ID,例如:
`AUTO RANDOM` 列隐式分配的值会影响 `last_insert_id()`。可以使用 `SELECT last_insert_id()` 获取上一次 TiDB 隐式分配的 ID,例如:

{{< copyable "sql" >}}

```sql
insert into t (b) values ("b")
select * from t;
select last_insert_id()
INSERT INTO t (b) VALUES ("b")
SELECT * FROM t;
SELECT last_insert_id()
```

可能得到的结果如下:

```
```sql
+------------+---+
| a | b |
+------------+---+
Expand All @@ -121,18 +120,18 @@ TiDB 支持解析版本注释语法。示例如下:
{{< copyable "sql" >}}

```sql
create table t (a bigint primary key /*T![auto_rand] auto_random */)
CREATE TABLE t (a bigint PRIMARY KEY /*T![auto_rand] auto_random */)
```

{{< copyable "sql" >}}

```sql
create table t (a bigint primary key auto_random)
CREATE TABLE t (a bigint PRIMARY KEY AUTO_RANDOM)
```

以上两个语句含义相同。

在 `show create table` 的结果中,`AUTO_RANDOM` 属性会被注释掉。注释会附带一个特性标识符,例如 `/*T![auto_rand] auto_random */`。其中 `auto_rand` 表示 `AUTO_RANDOM` 的特性标识符,只有实现了该标识符对应特性的 TiDB 版本才能够正常解析 SQL 语句片段。
在 `SHOW CREATE TABLE` 的结果中,`AUTO_RANDOM` 属性会被注释掉。注释会附带一个特性标识符,例如 `/*T![auto_rand] auto_random */`。其中 `auto_rand` 表示 `AUTO_RANDOM` 的特性标识符,只有实现了该标识符对应特性的 TiDB 版本才能够正常解析 SQL 语句片段。

该功能支持向前兼容,即降级兼容。没有实现对应特性的 TiDB 版本则会忽略表(带有上述注释)的 `AUTO_RANDOM` 属性,因此能够使用含有该属性的表。

Expand Down
4 changes: 2 additions & 2 deletions backup-and-restore-using-dumpling-lightning.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ Could not read data from testSchema.testTable: GC life time is shorter than tran
{{< copyable "sql" >}}

```sql
update mysql.tidb set VARIABLE_VALUE = '720h' where VARIABLE_NAME = 'tikv_gc_life_time';
UPDATE mysql.tidb SET VARIABLE_VALUE = '720h' WHERE VARIABLE_NAME = 'tikv_gc_life_time';
```

2. 执行 `dumpling` 命令后,将 TiDB 集群的 GC 值恢复到第 1 步中的初始值:

{{< copyable "sql" >}}

```sql
update mysql.tidb set VARIABLE_VALUE = '10m' where VARIABLE_NAME = 'tikv_gc_life_time';
UPDATE mysql.tidb SET VARIABLE_VALUE = '10m' WHERE VARIABLE_NAME = 'tikv_gc_life_time';
```

## 向 TiDB 恢复数据
Expand Down
4 changes: 2 additions & 2 deletions backup-and-restore-using-mydumper-lightning.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ aliases: ['/docs-cn/dev/backup-and-restore-using-mydumper-lightning/','/docs-cn/
{{< copyable "sql" >}}

```sql
update mysql.tidb set VARIABLE_VALUE = '720h' where VARIABLE_NAME = 'tikv_gc_life_time';
UPDATE mysql.tidb SET VARIABLE_VALUE = '720h' WHERE VARIABLE_NAME = 'tikv_gc_life_time';
```

2. 执行 `mydumper` 命令后,将 TiDB 集群的 GC 值恢复到第 1 步中的初始值:

{{< copyable "sql" >}}

```sql
update mysql.tidb set VARIABLE_VALUE = '10m' where VARIABLE_NAME = 'tikv_gc_life_time';
UPDATE mysql.tidb SET VARIABLE_VALUE = '10m' WHERE VARIABLE_NAME = 'tikv_gc_life_time';
```

## 向 TiDB 恢复数据
Expand Down
8 changes: 4 additions & 4 deletions basic-sql-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SHOW DATABASES;
{{< copyable "sql" >}}

```sql
use mysql;
USE mysql;
```

使用 `SHOW TABLES` 语句查看数据库中的所有表。例如:
Expand Down Expand Up @@ -104,7 +104,7 @@ CREATE TABLE person (
{{< copyable "sql" >}}

```sql
SHOW CREATE table person;
SHOW CREATE TABLE person;
```

使用 `DROP TABLE` 语句删除表。例如:
Expand Down Expand Up @@ -154,7 +154,7 @@ ALTER TABLE person ADD UNIQUE person_unique_id (id);
{{< copyable "sql" >}}

```sql
SHOW INDEX from person;
SHOW INDEX FROM person;
```

使用 `ALTER TABLE` 或 `DROP INDEX` 语句来删除索引。与 `CREATE INDEX` 语句类似,`DROP INDEX` 也可以嵌入 `ALTER TABLE` 语句。例如:
Expand Down Expand Up @@ -241,7 +241,7 @@ SELECT name FROM person;
{{< copyable "sql" >}}

```sql
SELECT * FROM person where id<5;
SELECT * FROM person WHERE id<5;
```

常用的 DCL 功能是创建或删除用户,和对用户权限的管理。
Expand Down
28 changes: 14 additions & 14 deletions blacklist-control-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ aliases: ['/docs-cn/dev/blacklist-control-plan/']
{{< copyable "sql" >}}

```sql
insert into mysql.opt_rule_blacklist values("join_reorder"), ("topn_push_down");
INSERT INTO mysql.opt_rule_blacklist VALUES("join_reorder"), ("topn_push_down");
```

执行以下 SQL 语句可让禁用规则立即生效,包括相应 TiDB Server 的所有旧链接:

{{< copyable "sql" >}}

```sql
admin reload opt_rule_blacklist;
ADMIN reload opt_rule_blacklist;
```

> **注意:**
>
>
> `admin reload opt_rule_blacklist` 只对执行该 SQL 语句的 TiDB server 生效。若需要集群中所有 TiDB server 生效,需要在每台 TiDB server 上执行该 SQL 语句。

- 需要解除一条规则的禁用时,需要删除表中禁用该条规则的相应数据,再执行 `admin reload`:

{{< copyable "sql" >}}

```sql
delete from mysql.opt_rule_blacklist where name in ("join_reorder", "topn_push_down");
DELETE FROM mysql.opt_rule_blacklist WHERE name IN ("join_reorder", "topn_push_down");
admin reload opt_rule_blacklist;
```

Expand All @@ -83,15 +83,15 @@ aliases: ['/docs-cn/dev/blacklist-control-plan/']
| [日期运算](/functions-and-operators/date-and-time-functions.md) | [`DATE_FORMAT()`](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format) |

### 禁止特定表达式下推

当函数的计算过程由于下推而出现异常时,可通过黑名单功能禁止其下推来快速恢复业务。具体而言,你可以将上述支持的函数或运算符名加入黑名单 `mysql.expr_pushdown_blacklist` 中,以禁止特定表达式下推。

`mysql.expr_pushdown_blacklist` 的 schema 如下:

{{< copyable "sql" >}}

```sql
desc mysql.expr_pushdown_blacklist;
DESC mysql.expr_pushdown_blacklist;
```

```sql
Expand Down Expand Up @@ -147,7 +147,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
explain select * from t where a < 2 and a > 2;
EXPLAIN SELECT * FROM t WHERE a < 2 AND a > 2;
```

```sql
Expand All @@ -166,7 +166,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
insert into mysql.expr_pushdown_blacklist values('<','tikv',''), ('>','tikv','');
INSERT INTO mysql.expr_pushdown_blacklist VALUES('<','tikv',''), ('>','tikv','');
```

```sql
Expand All @@ -177,7 +177,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
admin reload expr_pushdown_blacklist;
ADMIN reload expr_pushdown_blacklist;
```

```sql
Expand All @@ -189,7 +189,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
explain select * from t where a < 2 and a > 2;
EXPLAIN SELECT * FROM t WHERE a < 2 and a > 2;
```

```sql
Expand All @@ -208,7 +208,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
delete from mysql.expr_pushdown_blacklist where name = '>';
DELETE FROM mysql.expr_pushdown_blacklist WHERE name = '>';
```

```sql
Expand All @@ -218,7 +218,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
admin reload expr_pushdown_blacklist;
ADMIN reload expr_pushdown_blacklist;
```

```sql
Expand All @@ -230,7 +230,7 @@ desc mysql.expr_pushdown_blacklist;
{{< copyable "sql" >}}

```sql
explain select * from t where a < 2 and a > 2;
EXPLAIN SELECT * FROM t WHERE a < 2 AND a > 2;
```

```sql
Expand Down
28 changes: 14 additions & 14 deletions character-set-and-collation.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ALTER DATABASE db_name
{{< copyable "sql" >}}

```sql
create schema test1 character set utf8mb4 COLLATE uft8mb4_general_ci;
CREATE SCHEMA test1 CHARACTER SET utf8mb4 COLLATE uft8mb4_general_ci;
```

```sql
Expand All @@ -184,7 +184,7 @@ Query OK, 0 rows affected (0.09 sec)
{{< copyable "sql" >}}

```sql
use test1;
USE test1;
```

```sql
Expand All @@ -209,7 +209,7 @@ SELECT @@character_set_database, @@collation_database;
{{< copyable "sql" >}}

```sql
create schema test2 character set latin1 COLLATE latin1_bin;
CREATE SCHEMA test2 CHARACTER SET latin1 COLLATE latin1_bin;
```

```sql
Expand All @@ -219,7 +219,7 @@ Query OK, 0 rows affected (0.09 sec)
{{< copyable "sql" >}}

```sql
use test2;
USE test2;
```

```sql
Expand Down Expand Up @@ -390,13 +390,13 @@ SELECT _utf8mb4'string' COLLATE utf8mb4_general_ci;
{{< copyable "sql" >}}

```sql
create table t(a varchar(20) charset utf8mb4 collate utf8mb4_general_ci primary key);
CREATE TABLE t(a varchar(20) charset utf8mb4 collate utf8mb4_general_ci PRIMARY KEY);
Query OK, 0 rows affected
insert into t values ('A');
INSERT INTO t VALUES ('A');
Query OK, 1 row affected
insert into t values ('a');
INSERT INTO t VALUES ('a');
Query OK, 1 row affected # TiDB 会执行成功,而在 MySQL 中,则由于 utf8mb4_general_ci 大小写不敏感,报错 Duplicate entry 'a'。
insert into t1 values ('a ');
INSERT INTO t VALUES ('a ');
Query OK, 1 row affected # TiDB 会执行成功,而在 MySQL 中,则由于补齐空格比较,报错 Duplicate entry 'a '。
```

Expand All @@ -407,7 +407,7 @@ TiDB 4.0 新增了完整的排序规则支持框架,从语义上支持了排
{{< copyable "sql" >}}

```sql
select VARIABLE_VALUE from mysql.tidb where VARIABLE_NAME='new_collation_enabled';
SELECT VARIABLE_VALUE FROM mysql.tidb WHERE VARIABLE_NAME='new_collation_enabled';
```

```sql
Expand All @@ -426,13 +426,13 @@ select VARIABLE_VALUE from mysql.tidb where VARIABLE_NAME='new_collation_enabled
{{< copyable "sql" >}}

```sql
create table t(a varchar(20) charset utf8mb4 collate utf8mb4_general_ci primary key);
CREATE TABLE t(a varchar(20) charset utf8mb4 collate utf8mb4_general_ci PRIMARY KEY);
Query OK, 0 rows affected (0.00 sec)
insert into t values ('A');
INSERT INTO t VALUES ('A');
Query OK, 1 row affected (0.00 sec)
insert into t values ('a');
INSERT INTO t VALUES ('a');
ERROR 1062 (23000): Duplicate entry 'a' for key 'PRIMARY' # TiDB 兼容了 MySQL 的 case insensitive collation。
insert into t values ('a ');
INSERT INTO t VALUES ('a ');
ERROR 1062 (23000): Duplicate entry 'a ' for key 'PRIMARY' # TiDB 修正了 `PADDING` 行为,与 MySQL 兼容。
```

Expand Down Expand Up @@ -468,7 +468,7 @@ TiDB 支持使用 `COLLATE` 子句来指定一个表达式的排序规则,该
{{< copyable "sql" >}}

```sql
select 'a' = _utf8mb4 'A' collate utf8mb4_general_ci;
SELECT 'a' = _utf8mb4 'A' collate utf8mb4_general_ci;
```

```sql
Expand Down