From b2c63847708c7b8f271265f8c3004b6599874ba3 Mon Sep 17 00:00:00 2001 From: Frank945946 <108602632+Frank945946@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:31:42 +0800 Subject: [PATCH 1/9] *: add performance improvement of system tables in release notes v8.0 (#17206) --- releases/release-8.0.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/releases/release-8.0.0.md b/releases/release-8.0.0.md index 4f85878041a4..27da9ea14bed 100644 --- a/releases/release-8.0.0.md +++ b/releases/release-8.0.0.md @@ -392,6 +392,7 @@ TiDB 版本:8.0.0 - 支持 MemoryTracker 追踪 `IndexLookup` 算子的内存使用情况 [#45901](https://github.com/pingcap/tidb/issues/45901) @[solotzg](https://github.com/solotzg) - 支持 MemoryTracker 追踪 `MemTableReaderExec` 算子的内存使用情况 [#51456](https://github.com/pingcap/tidb/issues/51456) @[wshwsh12](https://github.com/wshwsh12) - 支持从 PD 批量加载 Region,加快在对大表进行查询时,从 KV Range 到 Regions 的转换过程 [#51326](https://github.com/pingcap/tidb/issues/51326) @[SeaRise](https://github.com/SeaRise) + - 优化系统表 `INFORMATION_SCHEMA.TABLES`、`INFORMATION_SCHEMA.STATISTICS`、`INFORMATION_SCHEMA.KEY_COLUMN_USAGE`、`INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS` 的查询性能。相比之前版本,性能提升最高可达 100 倍 [#50305](https://github.com/pingcap/tidb/issues/50305) @[ywqzzy](https://github.com/ywqzzy) + TiKV From 391f3025e18dcaf200190c968ced6a88ff3a07f2 Mon Sep 17 00:00:00 2001 From: pepezzzz <35323945+pepezzzz@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:31:42 +0800 Subject: [PATCH 2/9] Update schedule-replicas-by-topology-labels.md (#17208) --- schedule-replicas-by-topology-labels.md | 266 ++++++++++++++---------- 1 file changed, 152 insertions(+), 114 deletions(-) diff --git a/schedule-replicas-by-topology-labels.md b/schedule-replicas-by-topology-labels.md index 0ab57b345e4c..51142121ca7f 100644 --- a/schedule-replicas-by-topology-labels.md +++ b/schedule-replicas-by-topology-labels.md @@ -14,9 +14,156 @@ summary: TiDB v5.3.0 引入了通过拓扑 label 进行副本调度的功能。 要让这个机制生效,需要在部署时进行合理配置,把集群的拓扑信息(特别是 TiKV 的位置)上报给 PD。阅读本章前,请先确保阅读 [TiUP 部署方案](/production-deployment-using-tiup.md)。 -## 根据集群拓扑配置 labels +## 配置 TiKV、TiFlash 和 TiDB 的 labels -### 设置 TiKV 和 TiFlash 的 `labels` +你可以根据集群拓扑配置 TiKV、TiFlash 和 TiDB 的 labels。 + +### 使用 TiUP 进行配置(推荐) + +如果使用 TiUP 部署集群,可以在[初始化配置文件](/production-deployment-using-tiup.md#第-3-步初始化集群拓扑文件)中统一进行 location 相关配置。TiUP 会负责在部署时生成对应的 TiDB、TiKV、PD 和 TiFlash 配置文件。 + +下面的例子定义了 `zone` 和 `host` 两层拓扑结构。集群的 TiDB、TiKV 和 TiFlash 分布在三个 zone,z1、z2 和 z3。 + +- 每个 zone 内有两台主机部署 TiDB 实例,TiDB 实例均为独占机器部署。 +- 每个 zone 内有两台主机部署 TiKV 实例,z1 每台主机同时部署两个 TiKV 实例,z2 和 z3 每台主机分别独立部署一个 TiKV 实例。 +- 每个 zone 内有两台主机部署 TiFlash 实例,TiFlash 实例均为独占机器部署。 + +以下例子中 `tidb-host-machine-n` 代表第 n 个 TiDB 节点的 IP 地址,`tikv-host-machine-n` 代表第 n 个 TiKV 节点的 IP 地址,`tiflash-host-machine-n` 代表第 n 个 TiFlash 节点的 IP 地址。 + +``` +server_configs: + pd: + replication.location-labels: ["zone", "host"] +tidb_servers: +# z1 + - host: tidb-host-machine-1 + config: + labels: + zone: z1 + host: tidb-host-machine-1 + - host: tidb-host-machine-2 + config: + labels: + zone: z1 + host: tidb-host-machine-2 +# z2 + - host: tidb-host-machine-3 + config: + labels: + zone: z2 + host: tidb-host-machine-3 + - host: tikv-host-machine-4 + config: + labels: + zone: z2 + host: tidb-host-machine-4 +# z3 + - host: tidb-host-machine-5 + config: + labels: + zone: z3 + host: tidb-host-machine-5 + - host: tidb-host-machine-6 + config: + labels: + zone: z3 + host: tidb-host-machine-6 +tikv_servers: +# z1 + # machine-1 on z1 + - host: tikv-host-machine-1 + port:20160 + config: + server.labels: + zone: z1 + host: tikv-host-machine-1 + - host: tikv-host-machine-1 + port:20161 + config: + server.labels: + zone: z1 + host: tikv-host-machine-1 + # machine-2 on z1 + - host: tikv-host-machine-2 + port:20160 + config: + server.labels: + zone: z1 + host: tikv-host-machine-2 + - host: tikv-host-machine-2 + port:20161 + config: + server.labels: + zone: z1 + host: tikv-host-machine-2 +# z2 + - host: tikv-host-machine-3 + config: + server.labels: + zone: z2 + host: tikv-host-machine-3 + - host: tikv-host-machine-4 + config: + server.labels: + zone: z2 + host: tikv-host-machine-4 +# z3 + - host: tikv-host-machine-5 + config: + server.labels: + zone: z3 + host: tikv-host-machine-5 + - host: tikv-host-machine-6 + config: + server.labels: + zone: z3 + host: tikv-host-machine-6 + +tiflash_servers: +# z1 + - host: tiflash-host-machine-1 + learner_config: + server.labels: + zone: z1 + host: tiflash-host-machine-1 + - host: tiflash-host-machine-2 + learner_config: + server.labels: + zone: z1 + host: tiflash-host-machine-2 +# z2 + - host: tiflash-host-machine-3 + learner_config: + server.labels: + zone: z2 + host: tiflash-host-machine-3 + - host: tiflash-host-machine-4 + learner_config: + server.labels: + zone: z2 + host: tiflash-host-machine-4 +# z3 + - host: tiflash-host-machine-5 + learner_config: + server.labels: + zone: z3 + host: tiflash-host-machine-5 + - host: tiflash-host-machine-6 + learner_config: + server.labels: + zone: z3 + host: tiflash-host-machine-6 +``` + +详情参阅 [TiUP 跨数据中心部署拓扑](/geo-distributed-deployment-topology.md)。 + +> **注意:** +> +> 如果你未在配置文件中配置 `replication.location-labels` 项,使用该拓扑配置文件部署集群时可能会报错。建议在部署集群前,确认 `replication.location-labels` 已配置。 + +### 使用命令行或配置文件进行配置 + +#### 设置 TiKV 和 TiFlash 的 `labels` TiKV 和 TiFlash 支持在命令行参数或者配置文件中以键值对的形式绑定一些属性,我们把这些属性叫做标签 (label)。TiKV 和 TiFlash 在启动后,会将自身的标签上报给 PD,因此可以使用标签来标识 TiKV 和 TiFlash 节点的地理位置。 @@ -56,7 +203,7 @@ rack = "" host = "" ``` -### 设置 TiDB 的 `labels`(可选) +#### 设置 TiDB 的 `labels`(可选) 如果需要使用 [Follower Read](/follower-read.md) 的优先读同一区域副本的功能,需要为 TiDB 节点配置相关的 `labels`。 @@ -76,7 +223,7 @@ host = "" > > 目前,TiDB 依赖 `zone` 标签匹配选择同一区域的副本。如果需要使用此功能,需要在 PD [`location-labels` 配置](#设置-pd-的-isolation-level-配置)中包含 `zone`,并在 TiDB、TiKV 和 TiFlash 设置的 `labels` 中包含 `zone`。关于如何设置 TiKV 和 TiFlash 的 `labels`,可参考[设置 TiKV 和 TiFlash 的 `labels`](#设置-tikv-和-tiflash-的-labels)。 -### 设置 PD 的 `location-labels` 配置 +## 设置 PD 的 `location-labels` 配置 根据前面的描述,标签可以是用来描述 TiKV 属性的任意键值对,但 PD 无从得知哪些标签是用来标识地理位置的,而且也无从得知这些标签的层次关系。因此,PD 也需要一些配置来使得 PD 理解 TiKV 节点拓扑。 @@ -108,7 +255,7 @@ PD 上的配置叫做 `location-labels`,是一个字符串数组。该配置 pd-ctl config set location-labels zone,rack,host ``` -### 设置 PD 的 `isolation-level` 配置 +## 设置 PD 的 `isolation-level` 配置 在配置了 `location-labels` 的前提下,用户可以还通过 `isolation-level` 配置来进一步加强对 TiKV 集群的拓扑隔离要求。假设按照上面的说明通过 `location-labels` 将集群的拓扑结构分成三层:可用区 (zone) -> 机架 (rack) -> 主机 (host),并对 `isolation-level` 作如下配置: @@ -133,115 +280,6 @@ pd-ctl config set isolation-level zone > > `isolation-level` 默认情况下为空,即不进行强制隔离级别限制,若要对其进行设置,必须先配置 PD 的 `location-labels` 参数,同时保证 `isolation-level` 的值一定为 `location-labels` 中的一个。 -### 使用 TiUP 进行配置(推荐) - -如果使用 TiUP 部署集群,可以在[初始化配置文件](/production-deployment-using-tiup.md#第-3-步初始化集群拓扑文件)中统一进行 location 相关配置。TiUP 会负责在部署时生成对应的 TiKV、PD 和 TiFlash 配置文件。 - -下面的例子定义了 `zone` 和 `host` 两层拓扑结构。集群的 TiKV 和 TiFlash 分布在三个 zone,z1、z2 和 z3。 - -- 每个 zone 内有两台主机部署 TiKV 实例,z1 每台主机同时部署两个 TiKV 实例,z2 和 z3 每台主机分别独立部署一个 TiKV 实例。 -- 每个 zone 内有两台主机部署 TiFlash 实例,TiFlash 实例均为独占机器部署。 - -以下例子中 `tikv-host-machine-n` 代表第 n 个 TiKV 节点的 IP 地址,`tiflash-host-machine-n` 代表第 n 个 TiFlash 节点的 IP 地址。 - -``` -server_configs: - pd: - replication.location-labels: ["zone", "host"] - -tikv_servers: -# z1 - # machine-1 on z1 - - host: tikv-host-machine-1 - port:20160 - config: - server.labels: - zone: z1 - host: tikv-host-machine-1 - - host: tikv-host-machine-1 - port:20161 - config: - server.labels: - zone: z1 - host: tikv-host-machine-1 - # machine-2 on z1 - - host: tikv-host-machine-2 - port:20160 - config: - server.labels: - zone: z1 - host: tikv-host-machine-2 - - host: tikv-host-machine-2 - port:20161 - config: - server.labels: - zone: z1 - host: tikv-host-machine-2 -# z2 - - host: tikv-host-machine-3 - config: - server.labels: - zone: z2 - host: tikv-host-machine-3 - - host: tikv-host-machine-4 - config: - server.labels: - zone: z2 - host: tikv-host-machine-4 -# z3 - - host: tikv-host-machine-5 - config: - server.labels: - zone: z3 - host: tikv-host-machine-5 - - host: tikv-host-machine-6 - config: - server.labels: - zone: z3 - host: tikv-host-machine-6 - -tiflash_servers: -# z1 - - host: tiflash-host-machine-1 - learner_config: - server.labels: - zone: z1 - host: tiflash-host-machine-1 - - host: tiflash-host-machine-2 - learner_config: - server.labels: - zone: z1 - host: tiflash-host-machine-2 -# z2 - - host: tiflash-host-machine-3 - learner_config: - server.labels: - zone: z2 - host: tiflash-host-machine-3 - - host: tiflash-host-machine-4 - learner_config: - server.labels: - zone: z2 - host: tiflash-host-machine-4 -# z3 - - host: tiflash-host-machine-5 - learner_config: - server.labels: - zone: z3 - host: tiflash-host-machine-5 - - host: tiflash-host-machine-6 - learner_config: - server.labels: - zone: z3 - host: tiflash-host-machine-6 -``` - -详情参阅 [TiUP 跨数据中心部署拓扑](/geo-distributed-deployment-topology.md)。 - -> **注意:** -> -> 如果你未在配置文件中配置 `replication.location-labels` 项,使用该拓扑配置文件部署集群时可能会报错。建议在部署集群前,确认 `replication.location-labels` 已配置。 - ## 基于拓扑 label 的 PD 调度策略 PD 在副本调度时,会按照 label 层级,保证同一份数据的不同副本尽可能分散。 From 39069c7353189bd441a3a76477e8fbad0946fa53 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 25 Apr 2024 17:39:12 +0800 Subject: [PATCH 3/9] information-functions: Update reference manual and more (#17198) --- .../information-functions.md | 285 +++++++++++++++++- tidb-configuration-file.md | 2 +- 2 files changed, 272 insertions(+), 15 deletions(-) diff --git a/functions-and-operators/information-functions.md b/functions-and-operators/information-functions.md index 48c6b06cbdd4..17d15bd840e5 100644 --- a/functions-and-operators/information-functions.md +++ b/functions-and-operators/information-functions.md @@ -1,29 +1,284 @@ --- title: 信息函数 aliases: ['/docs-cn/dev/functions-and-operators/information-functions/','/docs-cn/dev/reference/sql/functions-and-operators/information-functions/'] -summary: TiDB 支持大部分 MySQL 5.7 的信息函数,包括 BENCHMARK(), CONNECTION_ID(), CURRENT_USER(), DATABASE(), FOUND_ROWS(), LAST_INSERT_ID(), ROW_COUNT(), SCHEMA(), SESSION_USER(), SYSTEM_USER(), USER(), 和 VERSION()。此外,TiDB 还有一个特有的信息函数 CURRENT_RESOURCE_GROUP(),而不支持 CHARSET(), COERCIBILITY(), 和 COLLATION() 函数。 +summary: TiDB 支持 MySQL 8.0 中提供的大部分信息函数。 --- # 信息函数 -TiDB 支持使用 MySQL 5.7 中提供的大部分[信息函数](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html)。 +TiDB 支持使用 MySQL 8.0 中提供的大部分[信息函数](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html)。 ## TiDB 支持的 MySQL 信息函数 | 函数名 | 功能描述 | | ------ | ---------------------------------------- | -| [`BENCHMARK()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_benchmark) | 循环执行一个表达式 | -| [`CONNECTION_ID()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_connection-id) | 返回当前连接的连接 ID (线程 ID) | -| [`CURRENT_USER()`, `CURRENT_USER`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_current-user) | 返回当前用户的用户名和主机名 | -| [`DATABASE()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_database) | 返回默认(当前)的数据库名 | -| [`FOUND_ROWS()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_found-rows) | 该函数返回对于一个包含 LIMIT 的 SELECT 查询语句,在不包含 LIMIT 的情况下回返回的记录数 | -| [`LAST_INSERT_ID()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_last-insert-id) | 返回最后一条 INSERT 语句中自增列的值 | -| [`ROW_COUNT()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_row-count) | 影响的行数 | -| [`SCHEMA()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_schema) | 与 DATABASE() 同义 | -| [`SESSION_USER()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_session-user) | 与 USER() 同义 | -| [`SYSTEM_USER()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_system-user) | 与 USER() 同义 | -| [`USER()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_user) | 返回客户端提供的用户名和主机名 | -| [`VERSION()`](https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_version) | 返回当前 MySQL 服务器的版本信息 | +| [`BENCHMARK()`](#benchmark) | 循环执行一个表达式 | +| [`CONNECTION_ID()`](#connection_id) | 返回当前连接的连接 ID(线程 ID) | +| [`CURRENT_ROLE()`](#current_role) | 返回当前连接的角色 | +| [`CURRENT_USER()`, `CURRENT_USER`](#current_user) | 返回当前用户的用户名和主机名 | +| [`DATABASE()`](#database) | 返回默认(当前)的数据库 | +| [`FOUND_ROWS()`](#found_rows) | 该函数对于一个包含 `LIMIT` 的 `SELECT` 查询语句,返回在不包含 `LIMIT` 的情况下的记录数 | +| [`LAST_INSERT_ID()`](#last_insert_id) | 返回上一条 `INSERT` 语句中自增列的值 | +| [`ROW_COUNT()`](#row_count) | 影响的行数 | +| [`SCHEMA()`](#schema) | 与 `DATABASE()` 同义 | +| [`SESSION_USER()`](#session_user) | 与 `USER()` 同义 | +| [`SYSTEM_USER()`](#system_user) | 与 `USER()` 同义 | +| [`USER()`](#user) | 返回客户端提供的用户名和主机名 | +| [`VERSION()`](#version) | 返回当前 MySQL 服务器的版本信息 | + +### BENCHMARK() + +`BENCHMARK()` 函数可以按照指定的次数重复执行给定的表达式。 + +语法: + +```sql +BENCHMARK(count, expression) +``` + +- `count`:要执行表达式的次数。 +- `expression`:要重复执行的表达式。 + +示例: + +```sql +SELECT BENCHMARK(5, SLEEP(2)); +``` + +``` ++------------------------+ +| BENCHMARK(5, SLEEP(2)) | ++------------------------+ +| 0 | ++------------------------+ +1 row in set (10.00 sec) +``` + +### CONNECTION_ID() + +`CONNECTION_ID()` 函数返回连接的 ID。根据 TiDB 的 [`enable-32bits-connection-id`](/tidb-configuration-file.md#enable-32bits-connection-id-从-v730-版本开始引入) 配置项的值不同,该函数将返回一个 32 位或 64 位的连接 ID。 + +如果启用了 [`enable-global-kill`](/tidb-configuration-file.md#enable-global-kill-从-v610-版本开始引入),连接的 ID 可用于在同一集群的多个 TiDB 实例中终止查询。 + +```sql +SELECT CONNECTION_ID(); +``` + +``` ++-----------------+ +| CONNECTION_ID() | ++-----------------+ +| 322961414 | ++-----------------+ +1 row in set (0.00 sec) +``` + +### CURRENT_ROLE() + +`CURRENT_ROLE()` 函数返回当前会话的当前[角色](/role-based-access-control.md)。 + +```sql +SELECT CURRENT_ROLE(); +``` + +``` ++----------------+ +| CURRENT_ROLE() | ++----------------+ +| NONE | ++----------------+ +1 row in set (0.00 sec) +``` + +### CURRENT_USER() + +`CURRENT_USER()` 函数返回当前会话中使用的账户。 + +```sql +SELECT CURRENT_USER(); +``` + +``` ++----------------+ +| CURRENT_USER() | ++----------------+ +| root@% | ++----------------+ +1 row in set (0.00 sec) +``` + +### DATABASE() + +`DATABASE()` 函数返回当前会话正在使用的数据库名。 + +```sql +SELECT DATABASE(); +``` + +``` ++------------+ +| DATABASE() | ++------------+ +| test | ++------------+ +1 row in set (0.00 sec) +``` + +### FOUND_ROWS() + +`FOUND_ROWS()` 函数返回上一条执行的 `SELECT` 语句的结果集中的行数。 + +```sql +SELECT 1 UNION ALL SELECT 2; +``` + +``` ++------+ +| 1 | ++------+ +| 2 | +| 1 | ++------+ +2 rows in set (0.01 sec) +``` + +```sql +SELECT FOUND_ROWS(); +``` + +``` ++--------------+ +| FOUND_ROWS() | ++--------------+ +| 2 | ++--------------+ +1 row in set (0.00 sec) +``` + +> **注意:** +> +> `SQL_CALC_FOUND_ROWS` 查询修饰符用于计算在没有 `LIMIT` 子句的情况下结果集中的总行数,只有在启用了 [`tidb_enable_noop_functions`](/system-variables.md#tidb_enable_noop_functions-从-v40-版本开始引入) 时才能使用。从 MySQL 8.0.17 开始,该查询修饰符已废弃。建议使用 `COUNT(*)` 代替。 + +### LAST_INSERT_ID() + +`LAST_INSERT_ID()` 函数返回包含 [`AUTO_INCREMENT`](/auto-increment.md) 或 [`AUTO_RANDOM`](/auto-random.md) 列的表中最后插入行的 ID。 + +```sql +CREATE TABLE t1(id SERIAL); +Query OK, 0 rows affected (0.17 sec) + +INSERT INTO t1() VALUES(); +Query OK, 1 row affected (0.03 sec) + +INSERT INTO t1() VALUES(); +Query OK, 1 row affected (0.00 sec) + +SELECT LAST_INSERT_ID(); ++------------------+ +| LAST_INSERT_ID() | ++------------------+ +| 3 | ++------------------+ +1 row in set (0.00 sec) + +TABLE t1; ++----+ +| id | ++----+ +| 1 | +| 3 | ++----+ +2 rows in set (0.00 sec) +``` + +> **注意** +> +> - 在 TiDB 中,[`AUTO_ID_CACHE`](/auto-increment.md#auto_id_cache) 可能会导致该函数的返回结果与 MySQL 不同。这是因为 TiDB 在每个节点上都会各自缓存 ID,这可能导致分配的 ID 出现无序或间隔。如果你的应用程序依赖于严格的 ID 顺序,可以启用 [MySQL 兼容模式](/auto-increment.md#mysql-兼容模式)。 +> +> - 在以上示例中,ID 是以 2 递增的,而 MySQL 在相同场景中生成的 ID 是以 1 递增的。关于兼容性的更多信息,请参见[自增 ID](/mysql-compatibility.md#自增-id)。 + +### ROW_COUNT() + +`ROW_COUNT()` 函数返回受影响的行数。 + +```sql +CREATE TABLE t1(id BIGINT UNSIGNED PRIMARY KEY AUTO_RANDOM); +Query OK, 0 rows affected, 1 warning (0.16 sec) + +INSERT INTO t1() VALUES (),(),(); +Query OK, 3 rows affected (0.02 sec) +Records: 3 Duplicates: 0 Warnings: 0 + +SELECT ROW_COUNT(); ++-------------+ +| ROW_COUNT() | ++-------------+ +| 3 | ++-------------+ +1 row in set (0.00 sec) +``` + +### SCHEMA() + +`SCHEMA()` 函数与 [`DATABASE()`](#database) 同义。 + +### SESSION_USER() + +`SESSION_USER()` 函数与 [`USER()`](#user) 同义。 + +### SYSTEM_USER() + +`SYSTEM_USER()` 函数与 [`USER()`](#user) 同义。 + +### USER() + +`USER()` 函数返回当前连接的用户。该函数的输出可能与 `CURRENT_USER()` 的输出略有不同,因为 `USER()` 显示的是实际 IP 地址,而不是通配符。 + +```sql +SELECT USER(), CURRENT_USER(); +``` + +``` ++----------------+----------------+ +| USER() | CURRENT_USER() | ++----------------+----------------+ +| root@127.0.0.1 | root@% | ++----------------+----------------+ +1 row in set (0.00 sec) +``` + +### VERSION() + +`VERSION()` 函数以与 MySQL 兼容的格式返回 TiDB 版本。如需获取更详细的版本信息,可以使用 [`TIDB_VERSION()`](/functions-and-operators/tidb-functions.md#tidb_version) 函数。 + +```sql +SELECT VERSION(); ++--------------------+ +| VERSION() | ++--------------------+ +| 8.0.11-TiDB-v7.5.1 | ++--------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT TIDB_VERSION()\G +*************************** 1. row *************************** +TIDB_VERSION(): Release Version: v7.5.1 +Edition: Community +Git Commit Hash: 7d16cc79e81bbf573124df3fd9351c26963f3e70 +Git Branch: heads/refs/tags/v7.5.1 +UTC Build Time: 2024-02-27 14:28:32 +GoVersion: go1.21.6 +Race Enabled: false +Check Table Before Drop: false +Store: tikv +1 row in set (0.00 sec) +``` + +以上示例来自 TiDB v7.5.1,它会将自身标识为 MySQL 8.0.11。 + +如需更改该函数返回的版本,可以修改 [`server-version`](/tidb-configuration-file.md#server-version) 配置项。 ## TiDB 特有的信息函数 @@ -38,3 +293,5 @@ TiDB 支持使用 MySQL 5.7 中提供的大部分[信息函数](https://dev.mysq * `CHARSET()` * `COERCIBILITY()` * `COLLATION()` +* `ICU_VERSION()` +* `ROLES_GRAPHML()` diff --git a/tidb-configuration-file.md b/tidb-configuration-file.md index 7453dd02db0b..145cf4c98726 100644 --- a/tidb-configuration-file.md +++ b/tidb-configuration-file.md @@ -121,7 +121,7 @@ TiDB 配置文件比命令行参数支持更多的选项。你可以在 [config/ - 当使用内置函数 `VERSION()` 时。 - 当与客户端初始连接,TiDB 返回带有服务端版本号的初始握手包时。具体可以查看 MySQL 初始握手包的[描述](https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase.html#sect_protocol_connection_phase_initial_handshake)。 + 默认值:"" -+ 默认情况下,TiDB 版本号格式为:`5.7.${mysql_latest_minor_version}-TiDB-${tidb_version}`。 ++ 默认情况下,TiDB 版本号格式为:`8.0.11-TiDB-${tidb_version}`。 > **注意:** > From 1b0318df8500b8ccd37b56443fad1ad0cc8fbea0 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Fri, 26 Apr 2024 08:48:12 +0800 Subject: [PATCH 4/9] track-and-verify-wals-in-manifes: update supported versions (#17202) --- tikv-configuration-file.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tikv-configuration-file.md b/tikv-configuration-file.md index bb2a58a333b3..dec0ccf684bb 100644 --- a/tikv-configuration-file.md +++ b/tikv-configuration-file.md @@ -1322,7 +1322,7 @@ RocksDB 相关的配置项。 + 单位:KiB|MiB|GiB -### `track-and-verify-wals-in-manifest` 从 v6.5.9 和 v8.0.0 版本开始引入 +### `track-and-verify-wals-in-manifest` 从 v6.5.9、v7.1.5、v8.0.0 版本开始引入 + 控制是否在 RocksDB 的 MANIFEST 文件中记录 WAL (Write Ahead Log) 文件的信息,以及在启动时是否验证 WAL 文件的完整性。详情请参考 RocksDB [Track WAL in MANIFEST](https://github.com/facebook/rocksdb/wiki/Track-WAL-in-MANIFEST)。 + 默认值:`true` From 59aa0d371d1d3bcdde87cdfb7f58c0881a830e89 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Fri, 26 Apr 2024 12:57:12 +0800 Subject: [PATCH 5/9] v7.1.5: add release notes (#17155) --- TOC.md | 1 + releases/release-7.1.5.md | 119 +++++++++++++++++++++++++++++++++++ releases/release-notes.md | 1 + releases/release-timeline.md | 1 + 4 files changed, 122 insertions(+) create mode 100644 releases/release-7.1.5.md diff --git a/TOC.md b/TOC.md index 05e9f96bb8b3..bd7d819a565f 100644 --- a/TOC.md +++ b/TOC.md @@ -1058,6 +1058,7 @@ - v7.2 - [7.2.0-DMR](/releases/release-7.2.0.md) - v7.1 + - [7.1.5](/releases/release-7.1.5.md) - [7.1.4](/releases/release-7.1.4.md) - [7.1.3](/releases/release-7.1.3.md) - [7.1.2](/releases/release-7.1.2.md) diff --git a/releases/release-7.1.5.md b/releases/release-7.1.5.md new file mode 100644 index 000000000000..ec221b9005ee --- /dev/null +++ b/releases/release-7.1.5.md @@ -0,0 +1,119 @@ +--- +title: TiDB 7.1.5 Release Notes +summary: 了解 TiDB 7.1.5 版本的兼容性变更、改进提升,以及错误修复。 +--- + +# TiDB 7.1.5 Release Notes + +发版日期:2024 年 4 月 26 日 + +TiDB 版本:7.1.5 + +试用链接:[快速体验](https://docs.pingcap.com/zh/tidb/v7.1/quick-start-with-tidb) | [生产部署](https://docs.pingcap.com/zh/tidb/v7.1/production-deployment-using-tiup) | [下载离线包](https://cn.pingcap.com/product-community/?version=v7.1.5#version-list) + +## 兼容性变更 + +- 在 TiKV 中提供 RocksDB [`track-and-verify-wals-in-manifest`](https://docs.pingcap.com/zh/tidb/v7.1/tikv-configuration-file#track-and-verify-wals-in-manifest-从-v659-和-v715-版本开始引入) 配置,用于调查 WAL (Write Ahead Log) 可能损坏问题 [#16549](https://github.com/tikv/tikv/issues/16549) @[v01dstar](https://github.com/v01dstar) + +## 改进提升 + ++ TiDB + + - 支持从 PD 批量加载 Region,加快在对大表进行查询时,从 KV Range 到 Regions 的转换过程 [#51326](https://github.com/pingcap/tidb/issues/51326) @[SeaRise](https://github.com/SeaRise) + - 优化 `ANALYZE` 语句卡住元数据锁的问题 [#47475](https://github.com/pingcap/tidb/issues/47475) @[wjhuang2016](https://github.com/wjhuang2016) + - 为 LDAP 身份认证添加超时机制,避免资源锁 (RLock) 无法及时释放的问题 [#51883](https://github.com/pingcap/tidb/issues/51883) @[YangKeao](https://github.com/YangKeao) + ++ TiKV + + - 增加 peer 和 store 消息的 slow log [#16600](https://github.com/tikv/tikv/issues/16600) @[Connor1996](https://github.com/Connor1996) + - 在 raftstore 线程中避免进行快照文件的 IO 操作,提高 TiKV 稳定性 [#16564](https://github.com/tikv/tikv/issues/16564) @[Connor1996](https://github.com/Connor1996) + ++ PD + + - 升级 etcd 版本至 v3.4.30 [#7904](https://github.com/tikv/pd/issues/7904) @[JmPotato](https://github.com/JmPotato) + ++ Tools + + + Backup & Restore (BR) + + - 在遇到较大的 checkpoint lag 时,日志备份支持自动放弃任务,以避免日志备份长时间阻塞 GC,从而防止集群出现问题 [#50803](https://github.com/pingcap/tidb/issues/50803) @[RidRisR](https://github.com/RidRisR) + - 增加 PITR 集成测试用例,覆盖对日志备份与添加索引加速功能的兼容性测试 [#51987](https://github.com/pingcap/tidb/issues/51987) @[Leavrth](https://github.com/Leavrth) + - 移除日志备份启动时检查是否存在活动 DDL job 的无效检查 [#52733](https://github.com/pingcap/tidb/issues/52733) @[Leavrth](https://github.com/Leavrth) + +## 错误修复 + ++ TiDB + + - 修复一些情况下查询 `BINARY` 类型的 JSON 可能会报错的问题 [#51547](https://github.com/pingcap/tidb/issues/51547) @[YangKeao](https://github.com/YangKeao) + - 修复当 SQL 语句中包含 `JOIN` 且 `SELECT` 列表只包含常量时,使用 MPP 执行查询可能导致查询结果出错的问题 [#50358](https://github.com/pingcap/tidb/issues/50358) @[yibin87](https://github.com/yibin87) + - 修复 `init-stats` 流程可能导致 TiDB panic 以及 `load stats` 流程直接退出的问题 [#51581](https://github.com/pingcap/tidb/issues/51581) @[hawkingrei](https://github.com/hawkingrei) + - 修复 TiDB Server 在初始化完成之前就标记为 Health 的问题 [#51596](https://github.com/pingcap/tidb/issues/51596) @[shenqidebaozi](https://github.com/shenqidebaozi) + - 修复主键类型是 `VARCHAR` 时,执行 `ALTER TABLE ... COMPACT TIFLASH REPLICA` 可能会错误地提前结束的问题 [#51810](https://github.com/pingcap/tidb/issues/51810) @[breezewish](https://github.com/breezewish) + - 修复 `shuffleExec` 意外退出导致 TiDB 崩溃的问题 [#48230](https://github.com/pingcap/tidb/issues/48230) @[wshwsh12](https://github.com/wshwsh12) + - 修复某些情况下 `SHOW CREATE PLACEMENT POLICY` 语句不显示 `SURVIVAL_PREFERENCES` 属性的问题 [#51699](https://github.com/pingcap/tidb/issues/51699) @[lcwangchao](https://github.com/lcwangchao) + - 修复设置统计信息自动更新的时间窗口后,时间窗口外统计信息仍然可能更新的问题 [#49552](https://github.com/pingcap/tidb/issues/49552) @[hawkingrei](https://github.com/hawkingrei) + - 修复当子查询中的 `HAVING` 子句包含关联列时,查询结果可能出错的问题 [#51107](https://github.com/pingcap/tidb/issues/51107) @[hawkingrei](https://github.com/hawkingrei) + - 修复 `approx_percentile` 函数可能导致 TiDB panic 的问题 [#40463](https://github.com/pingcap/tidb/issues/40463) @[xzhangxian1008](https://github.com/xzhangxian1008) + - 修复 `IN()` 谓词中包含 `NULL` 时,查询结果错误的问题 [#51560](https://github.com/pingcap/tidb/issues/51560) @[winoros](https://github.com/winoros) + - 修复当配置文件中出现不合规的配置项时,配置文件不生效的问题 [#51399](https://github.com/pingcap/tidb/issues/51399) @[Defined2014](https://github.com/Defined2014) + - 修复 `EXCHANGE PARTITION` 在处理外键时判断错误的问题 [#51807](https://github.com/pingcap/tidb/issues/51807) @[YangKeao](https://github.com/YangKeao) + - 修复查询 `TIDB_HOT_REGIONS` 表时结果返回内存表的问题 [#50810](https://github.com/pingcap/tidb/issues/50810) @[Defined2014](https://github.com/Defined2014) + - 修复 `IFNULL` 函数返回的类型和 MySQL 不一致的问题 [#51765](https://github.com/pingcap/tidb/issues/51765) @[YangKeao](https://github.com/YangKeao) + - 修复 TTL 功能在某些情况下因为没有正确切分数据范围而造成数据热点的问题 [#51527](https://github.com/pingcap/tidb/issues/51527) @[lcwangchao](https://github.com/lcwangchao) + - 修复 TiDB 持续发送探活请求到已经下线的 TiFlash 节点的问题 [#46602](https://github.com/pingcap/tidb/issues/46602) @[zyguan](https://github.com/zyguan) + - 修复在 `AUTO_ID_CACHE=1` 时,AutoID Leader 发生变更可能造成自增列的值减少的问题 [#52600](https://github.com/pingcap/tidb/issues/52600) @[tiancaiamao](https://github.com/tiancaiamao) + - 修复执行 `INSERT IGNORE` 可能出现唯一索引和数据不一致的问题 [#51784](https://github.com/pingcap/tidb/issues/51784) @[wjhuang2016](https://github.com/wjhuang2016) + - 修复添加唯一索引可能导致 TiDB panic 的问题 [#52312](https://github.com/pingcap/tidb/issues/52312) @[wjhuang2016](https://github.com/wjhuang2016) + - 修复窗口函数中有某些子查询时可能会 panic 的问题 [#42734](https://github.com/pingcap/tidb/issues/42734) @[hi-rustin](https://github.com/hi-rustin) + - 修复 `init-stats` 流程可能导致 TiDB panic 以及 `load stats` 流程直接退出的问题 [#51581](https://github.com/pingcap/tidb/issues/51581) @[hawkingrei](https://github.com/hawkingrei) + - 修复关闭 TableDual 的 Predicate 下推后,出现性能回退的问题 [#50614](https://github.com/pingcap/tidb/issues/50614) @[time-and-fate](https://github.com/time-and-fate) + - 修复当子查询中的 `HAVING` 子句包含关联列时,查询结果可能出错的问题 [#51107](https://github.com/pingcap/tidb/issues/51107) @[hawkingrei](https://github.com/hawkingrei) + - 修复当某些列的统计信息没有完全加载时,`EXPLAIN` 语句的结果中可能会显示错误的列 ID 的问题 [#52207](https://github.com/pingcap/tidb/issues/52207) @[time-and-fate](https://github.com/time-and-fate) + ++ TiKV + + - 修复由于过时的 Region peer 忽略 GC 消息导致 resolve-ts 被阻塞的问题 [#16504](https://github.com/tikv/tikv/issues/16504) @[crazycs520](https://github.com/crazycs520) + - 修复 RocksDB 中非活跃的 WAL (Write Ahead Log) 可能损毁数据的问题 [#16705](https://github.com/tikv/tikv/issues/16705) @[Connor1996](https://github.com/Connor1996) + - 修复监控指标 `tikv_unified_read_pool_thread_count` 有时没有数据的问题 [#16629](https://github.com/tikv/tikv/issues/16629) @[YuJuncen](https://github.com/YuJuncen) + - 修复乐观事务在执行期间被其它事务发起 resolve lock 时,如果事务的 primary key 上之前有通过异步提交 (Async Commit) 或一阶段提交 (1PC) 模式提交的数据,事务的原子性可能有小概率被破坏问题 [#16620](https://github.com/tikv/tikv/issues/16620) @[MyonKeminta](https://github.com/MyonKeminta) + ++ PD + + - 修复写热点调度可能会违反放置策略 (placement policy) 约束的问题 [#7848](https://github.com/tikv/pd/issues/7848) @[lhy1024](https://github.com/lhy1024) + - 修复 `SHOW CONFIG` 的查询结果包含已废弃的 `trace-region-flow` 配置项的问题 [#7917](https://github.com/tikv/pd/issues/7917) @[rleungx](https://github.com/rleungx) + - 修复扩缩容进度显示不准确的问题 [#7726](https://github.com/tikv/pd/issues/7726) @[CabinfeverB](https://github.com/CabinfeverB) + ++ TiFlash + + - 修复日志中 `local_region_num` 数值错误的问题 [#8895](https://github.com/pingcap/tiflash/issues/8895) @[JaySon-Huang](https://github.com/JaySon-Huang) + - 修复查询生成列出错的问题 [#8787](https://github.com/pingcap/tiflash/issues/8787) @[guo-shaoge](https://github.com/guo-shaoge) + - 修复 `ENUM` 列在 chunk encode 时可能会导致 TiFlash crash 的问题 [#8674](https://github.com/pingcap/tiflash/issues/8674) @[yibin87](https://github.com/yibin87) + - 修复在非严格 `sql_mode` 下插入数据到带有异常默认值的列可能导致 TiFlash panic 的问题 [#8803](https://github.com/pingcap/tiflash/issues/8803) @[Lloyd-Pottiger](https://github.com/Lloyd-Pottiger) + - 修复 `TIME` 类型的列在精度修改后,如果发生 Region 迁移、分裂或合并,可能会导致查询出错的问题 [#8601](https://github.com/pingcap/tiflash/issues/8601) @[JaySon-Huang](https://github.com/JaySon-Huang) + ++ Tools + + + Backup & Restore (BR) + + - 修复在日志备份任务被暂停后,移除任务无法立即恢复 GC safepoint 的问题 [#52082](https://github.com/pingcap/tidb/issues/52082) @[3pointer](https://github.com/3pointer) + - 修复全量备份失败时打印过多日志的问题 [#51572](https://github.com/pingcap/tidb/issues/51572) @[Leavrth](https://github.com/Leavrth) + - 修复在包含 `AUTO_RANDOM` 列的联合聚簇索引中,BR 无法备份 `AUTO_RANDOM` ID 分配进度的问题 [#52255](https://github.com/pingcap/tidb/issues/52255) @[Leavrth](https://github.com/Leavrth) + - 修复在某些极端情况下,全量备份因找不到 peer 导致 TiKV panic 的问题 [#16394](https://github.com/tikv/tikv/issues/16394) @[Leavrth](https://github.com/Leavrth) + - 修复 PD 连接失败导致日志备份 advancer owner 所在的 TiDB 可能崩溃的问题 [#52597](https://github.com/pingcap/tidb/issues/52597) @[YuJuncen](https://github.com/YuJuncen) + - 修复一个不稳定的测试用例 [#52547](https://github.com/pingcap/tidb/issues/52547) @[Leavrth](https://github.com/Leavrth) + - 修复因 TiKV 重启,日志备份的 global checkpoint 推进提前于实际备份文件写入点,可能导致少量备份数据丢失的问题 [#16809](https://github.com/tikv/tikv/issues/16809) @[YuJuncen](https://github.com/YuJuncen) + - 修复在小概率情况下,由于特殊的事件时序导致日志备份数据丢失的问题 [#16739](https://github.com/tikv/tikv/issues/16739) @[YuJuncen](https://github.com/YuJuncen) + + + TiCDC + + - 修复上游写入 `Exchange Partition ... With Validation` DDL 后,TiCDC 向下游执行该 DDL 时失败,导致 changefeed 卡住的问题 [#10859](https://github.com/pingcap/tiflow/issues/10859) @[hongyunyan](https://github.com/hongyunyan) + - 修复恢复 changefeed 时 changefeed 的 `checkpoint-ts` 小于 TiDB 的 GC safepoint,没有及时报错 `snapshot lost caused by GC` 的问题 [#10463](https://github.com/pingcap/tiflow/issues/10463) @[sdojjy](https://github.com/sdojjy) + - 修复在调度表的同步任务时 TiCDC panic 的问题 [#10613](https://github.com/pingcap/tiflow/issues/10613) @[CharlesCheung96](https://github.com/CharlesCheung96) + - 修复在频繁执行 DDL 的场景中,由于错误的 BarrierTS 导致数据被写入到错误的 CSV 文件的问题 [#10668](https://github.com/pingcap/tiflow/issues/10668) @[lidezhu](https://github.com/lidezhu) + - 修复当对象存储遇到暂时故障时,启用了最终一致性功能的 changefeed 可能直接失败的问题 [#10710](https://github.com/pingcap/tiflow/issues/10710) @[CharlesCheung96](https://github.com/CharlesCheung96) + - 修复 `open-protocol` 的 old value 部分错误地按照 `STRING` 类型而非真正类型输出默认值的问题 [#10803](https://github.com/pingcap/tiflow/issues/10803) @[3AceShowHand](https://github.com/3AceShowHand) + + + TiDB Lightning + + - 修复导入 Parquet 格式的空表时,TiDB Lightning panic 的问题 [#52518](https://github.com/pingcap/tidb/issues/52518) @[kennytm](https://github.com/kennytm) + - 修复服务器模式下 TiDB Lightning 打印日志敏感信息的问题 [#36374](https://github.com/pingcap/tidb/issues/36374) @[kennytm](https://github.com/kennytm) diff --git a/releases/release-notes.md b/releases/release-notes.md index 4c5e04ed644b..86bbeb15e454 100644 --- a/releases/release-notes.md +++ b/releases/release-notes.md @@ -34,6 +34,7 @@ TiDB 历史版本发布声明如下: ## 7.1 +- [7.1.5](/releases/release-7.1.5.md): 2024-04-26 - [7.1.4](/releases/release-7.1.4.md): 2024-03-11 - [7.1.3](/releases/release-7.1.3.md): 2023-12-21 - [7.1.2](/releases/release-7.1.2.md): 2023-10-25 diff --git a/releases/release-timeline.md b/releases/release-timeline.md index 0a93f3e31cf5..7f048412cf98 100644 --- a/releases/release-timeline.md +++ b/releases/release-timeline.md @@ -9,6 +9,7 @@ summary: 了解 TiDB 的版本发布时间线。 | 版本 | 发布日期 | | :--- | :--- | +| [7.1.5](/releases/release-7.1.5.md) | 2024-04-26 | | [6.5.9](/releases/release-6.5.9.md) | 2024-04-12 | | [8.0.0-DMR](/releases/release-8.0.0.md) | 2024-03-29 | | [7.1.4](/releases/release-7.1.4.md) | 2024-03-11 | From c573438fe0a146c32e2abebd752d39dbcbca88b3 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Fri, 26 Apr 2024 15:15:12 +0800 Subject: [PATCH 6/9] Add example for multi argument CHAR() (#17011) --- functions-and-operators/string-functions.md | 374 +++++++++++++++++++- 1 file changed, 373 insertions(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 945fa629f35a..a4e6f8ebdac9 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -130,7 +130,7 @@ SELECT CustomerName, BIT_LENGTH(CustomerName) AS BitLengthOfName FROM Customers; ### [`CHAR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char) -`CHAR()` 函数用于获取指定 ASCII 值的对应字符。该函数执行的操作与 `ASCII()` 相反,`ASCII()` 用于返回指定字符的 ASCII 值。 +`CHAR()` 函数用于获取指定 ASCII 值的对应字符。该函数执行的操作与 `ASCII()` 相反,`ASCII()` 用于返回指定字符的 ASCII 值。如果提供了多个参数,`CHAR()` 函数将作用于所有参数并将它们的结果拼接在一起返回。 示例: @@ -184,6 +184,19 @@ SELECT CHAR(50089); +--------------+ ``` +```sql +SELECT CHAR(65,66,67); +``` + +``` ++----------------+ +| CHAR(65,66,67) | ++----------------+ +| ABC | ++----------------+ +1 row in set (0.00 sec) +``` + ### [`CHAR_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char-length) `CHAR_LENGTH()` 函数用于获取输入参数中字符的总数。 @@ -1539,22 +1552,368 @@ SELECT QUOTE(0x002774657374); 使用正则表达式匹配模式 +示例: + +下面示例使用了两个正则表达式来匹配一些字符串。 + +```sql +WITH vals AS ( + SELECT 'TiDB' AS v + UNION ALL + SELECT 'Titanium' + UNION ALL + SELECT 'Tungsten' + UNION ALL + SELECT 'Rust' +) +SELECT + v, + v REGEXP '^Ti' AS 'starts with "Ti"', + v REGEXP '^.{4}$' AS 'Length is 4 characters' +FROM + vals; +``` + +``` ++----------+------------------+------------------------+ +| v | starts with "Ti" | Length is 4 characters | ++----------+------------------+------------------------+ +| TiDB | 1 | 1 | +| Titanium | 1 | 0 | +| Tungsten | 0 | 0 | +| Rust | 0 | 1 | ++----------+------------------+------------------------+ +4 rows in set (0.00 sec) +``` + +`REGEXP` 并不限于只在 `SELECT` 子句中使用。例如,`REGEXP` 还可以用于查询的 `WHERE` 子句中。 + +```sql +SELECT + v +FROM ( + SELECT 'TiDB' AS v + ) AS vals +WHERE + v REGEXP 'DB$'; +``` + +``` ++------+ +| v | ++------+ +| TiDB | ++------+ +1 row in set (0.01 sec) +``` + ### [`REGEXP_INSTR()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr) 返回满足正则的子字符串的第一个索引位置(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) +`REGEXP_INSTR(str, regexp, [start, [match, [ret, [match_type]]]])` 函数返回正则表达式(`regexp`)匹配字符串(`str`)的位置。 + +如果 `str` 或 `regexp` 为 `NULL`,则该函数返回 `NULL`。 + +示例: + +下面示例展示了 `^.b.$` 匹配 `abc` 的情况。 + +```sql +SELECT REGEXP_INSTR('abc','^.b.$'); +``` + +``` ++-----------------------------+ +| REGEXP_INSTR('abc','^.b.$') | ++-----------------------------+ +| 1 | ++-----------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了使用第三个参数来从字符串的指定位置起查找匹配值的情况。 + +```sql +SELECT REGEXP_INSTR('abcabc','a'); +``` + +``` ++----------------------------+ +| REGEXP_INSTR('abcabc','a') | ++----------------------------+ +| 1 | ++----------------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT REGEXP_INSTR('abcabc','a',2); +``` + +``` ++------------------------------+ +| REGEXP_INSTR('abcabc','a',2) | ++------------------------------+ +| 4 | ++------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了使用第四个参数来查找第二个匹配值的情况。 + +```sql +SELECT REGEXP_INSTR('abcabc','a',1,2); +``` + +``` ++--------------------------------+ +| REGEXP_INSTR('abcabc','a',1,2) | ++--------------------------------+ +| 4 | ++--------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了使用第五个参数来返回匹配值后面的那个值的位置,而不是返回匹配值的位置。 + +```sql +SELECT REGEXP_INSTR('abcabc','a',1,1,1); +``` + +``` ++----------------------------------+ +| REGEXP_INSTR('abcabc','a',1,1,1) | ++----------------------------------+ +| 2 | ++----------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了使用第六个参数来添加 `i` 标志以获得不区分大小写的匹配。有关正则表达式 `match_type` 的更多详细信息,请参阅 [`match_type` 兼容性](#匹配模式-match_type-兼容性)。 + +```sql +SELECT REGEXP_INSTR('abcabc','A',1,1,0,''); +``` + +``` ++-------------------------------------+ +| REGEXP_INSTR('abcabc','A',1,1,0,'') | ++-------------------------------------+ +| 0 | ++-------------------------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT REGEXP_INSTR('abcabc','A',1,1,0,'i'); +``` + +``` ++--------------------------------------+ +| REGEXP_INSTR('abcabc','A',1,1,0,'i') | ++--------------------------------------+ +| 1 | ++--------------------------------------+ +1 row in set (0.00 sec) +``` + +除了 `match_type`,[排序规则](/character-set-and-collation.md) 也会影响匹配。在下面的示例中,使用了区分大小写和不区分大小写的排序规则来展示这种影响。 + +```sql +SELECT REGEXP_INSTR('abcabc','A' COLLATE utf8mb4_general_ci); +``` + +``` ++-------------------------------------------------------+ +| REGEXP_INSTR('abcabc','A' COLLATE utf8mb4_general_ci) | ++-------------------------------------------------------+ +| 1 | ++-------------------------------------------------------+ +1 row in set (0.01 sec) +``` + +```sql +SELECT REGEXP_INSTR('abcabc','A' COLLATE utf8mb4_bin); +``` + +``` ++------------------------------------------------+ +| REGEXP_INSTR('abcabc','A' COLLATE utf8mb4_bin) | ++------------------------------------------------+ +| 0 | ++------------------------------------------------+ +1 row in set (0.00 sec) +``` + ### [`REGEXP_LIKE()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-like) 判断字符串是否满足正则表达式(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) +`REGEXP_LIKE(str, regex, [match_type])` 函数用于判断正则表达式是否匹配字符串。可选的 `match_type` 参数可以用于更改匹配行为。 + +示例: + +下面示例展示了 `^a` 匹配 `abc` 的情况。 + +```sql +SELECT REGEXP_LIKE('abc','^a'); +``` + +``` ++-------------------------+ +| REGEXP_LIKE('abc','^a') | ++-------------------------+ +| 1 | ++-------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了 `^A` 不匹配 `abc` 的情况。 + +```sql +SELECT REGEXP_LIKE('abc','^A'); +``` + +``` ++-------------------------+ +| REGEXP_LIKE('abc','^A') | ++-------------------------+ +| 0 | ++-------------------------+ +1 row in set (0.00 sec) +``` + +下面示例展示了 `^A` 匹配 `abc` 的情况,因为 `i` 标志启用了不区分大小写的匹配,所以能够匹配上。关于正则表达式 `match_type` 的更多详细信息,请参阅 [`match_type` 兼容性](#匹配模式-match_type-兼容性)。 + +```sql +SELECT REGEXP_LIKE('abc','^A','i'); +``` + +``` ++-----------------------------+ +| REGEXP_LIKE('abc','^A','i') | ++-----------------------------+ +| 1 | ++-----------------------------+ +1 row in set (0.00 sec) +``` + ### [`REGEXP_REPLACE()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace) 替换满足正则表达式的子字符串(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) +`REGEXP_REPLACE(str, regexp, replace, [start, [match, [match_type]]])` 函数可以用于基于正则表达式替换字符串。 + +示例: + +下面的示例中,两个 `o` 被替换为 `i`。 + +```sql +SELECT REGEXP_REPLACE('TooDB', 'o{2}', 'i'); +``` + +``` ++--------------------------------------+ +| REGEXP_REPLACE('TooDB', 'o{2}', 'i') | ++--------------------------------------+ +| TiDB | ++--------------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例从第三个字符开始匹配,导致正则表达式不匹配,不进行任何替换。 + +```sql +SELECT REGEXP_REPLACE('TooDB', 'o{2}', 'i',3); +``` + +``` ++----------------------------------------+ +| REGEXP_REPLACE('TooDB', 'o{2}', 'i',3) | ++----------------------------------------+ +| TooDB | ++----------------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例中,第五个参数用于设置替换第一个或第二个匹配的值。 + +```sql +SELECT REGEXP_REPLACE('TooDB', 'o', 'i',1,1); +``` + +``` ++---------------------------------------+ +| REGEXP_REPLACE('TooDB', 'o', 'i',1,1) | ++---------------------------------------+ +| TioDB | ++---------------------------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT REGEXP_REPLACE('TooDB', 'o', 'i',1,2); +``` + +``` ++---------------------------------------+ +| REGEXP_REPLACE('TooDB', 'o', 'i',1,2) | ++---------------------------------------+ +| ToiDB | ++---------------------------------------+ +1 row in set (0.00 sec) +``` + +下面示例中,第六个参数用于设置 `match_type` 为不区分大小写的匹配。更多关于正则表达式 `match_type` 的详细信息,请参阅 [`match_type` 兼容性](#匹配模式-match_type-兼容性)。 + +```sql +SELECT REGEXP_REPLACE('TooDB', 'O{2}','i',1,1); +``` + +``` ++-----------------------------------------+ +| REGEXP_REPLACE('TooDB', 'O{2}','i',1,1) | ++-----------------------------------------+ +| TooDB | ++-----------------------------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT REGEXP_REPLACE('TooDB', 'O{2}','i',1,1,'i'); +``` + +``` ++---------------------------------------------+ +| REGEXP_REPLACE('TooDB', 'O{2}','i',1,1,'i') | ++---------------------------------------------+ +| TiDB | ++---------------------------------------------+ +1 row in set (0.00 sec) +``` + ### [`REGEXP_SUBSTR()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr) 返回满足正则表达式的子字符串(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) +`REGEXP_SUBSTR(str, regexp, [start, [match, [match_type]]])` 函数用于基于正则表达式获取子字符串。 + +下面示例使用 `Ti.{2}` 正则表达式从 `This is TiDB` 字符串中获取 `TiDB` 子字符串。 + +```sql +SELECT REGEXP_SUBSTR('This is TiDB','Ti.{2}'); +``` + +``` ++----------------------------------------+ +| REGEXP_SUBSTR('This is TiDB','Ti.{2}') | ++----------------------------------------+ +| TiDB | ++----------------------------------------+ +1 row in set (0.00 sec) +``` + ### [`REPEAT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_repeat) `REPEAT()` 函数用于以指定次数重复一个字符串。 @@ -1886,6 +2245,15 @@ TiDB 与 MySQL 在 `match_type` 上的差异: - TiDB 不支持 `match_type` 为 `"u"`。 +| `match_type` | MySQL | TiDB | 描述 | +|:------------:|-------|------|----------------------------------------| +| c | Yes | Yes | 大小写敏感匹配 | +| i | Yes | Yes | 大小写不敏感匹配 | +| m | Yes | Yes | 匹配多行文本的模式 | +| s | No | Yes | 匹配新行,和 MySQL 中的 `n` 相同 | +| n | Yes | No | 匹配新行,和 TiDB 中的 `s` 相同 | +| u | Yes | No | UNIX&trade 换行符 | + ### 数据类型兼容性 TiDB 与 MySQL 在二进制字符串 (binary string) 数据类型上的差异: @@ -1907,3 +2275,7 @@ TiDB 与 MySQL 在二进制字符串 (binary string) 数据类型上的差异: ```sql SELECT REGEXP_REPLACE('abcd','(.*)(.{2})$','\\1') AS s; ``` + +### 已知问题 + +- [GitHub Issue #37981](https://github.com/pingcap/tidb/issues/37981) \ No newline at end of file From 5ccbf9c91744f90aab409ade12d3dd2c24366912 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Fri, 26 Apr 2024 15:45:15 +0800 Subject: [PATCH 7/9] translate 3 PRs for functions and operators (#17205) --- .../cast-functions-and-operators.md | 60 ++++++++++++-- .../numeric-functions-and-operators.md | 50 ++++++------ functions-and-operators/string-functions.md | 78 ++++++++++++++++++- 3 files changed, 158 insertions(+), 30 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index fa3c1c573087..752fe021caea 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -1,21 +1,71 @@ --- title: Cast 函数和操作符 aliases: ['/docs-cn/dev/functions-and-operators/cast-functions-and-operators/','/docs-cn/dev/reference/sql/functions-and-operators/cast-functions-and-operators/'] -summary: Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 支持使用 MySQL 5.7 中提供的所有 Cast 函数和操作符。包括 BINARY,将一个字符串转换成一个二进制字符串;CAST(),将一个值转换成一个确定类型;CONVERT(),将一个值转换成一个确定类型。TiDB 和 MySQL 对于 SELECT CAST(MeN AS CHAR) 的结果显示不一致,其中 MeN 是用科学计数法表示的双精度浮点数。MySQL 在 -15<=N<=14 时显示完整数值,在 N<-15 或 N>14 时显示科学计数法。而 TiDB 始终显示完整数值。例如,MySQL 对于 SELECT CAST(3.1415e15 AS CHAR) 的显示结果为 3.1415e15,而 TiDB 的显示结果为 3141500000000000。 +summary: Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 支持使用 MySQL 8.0 中提供的所有 Cast 函数和操作符。 --- # Cast 函数和操作符 -Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 支持使用 MySQL 5.7 中提供的所有 [Cast 函数和操作符](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html)。 +Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 支持使用 MySQL 8.0 中提供的所有 [Cast 函数和操作符](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html)。 ## Cast 函数和操作符表 | 函数和操作符名 | 功能描述 | | --------------- | ----------------------------------- | -| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | 将一个字符串转换成一个二进制字符串 | -| [`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) | 将一个值转换成一个确定类型 | -| [`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) | 将一个值转换成一个确定类型 | +| [`BINARY`](#binary) | 将一个字符串转换成一个二进制字符串 | +| [`CAST()`](#cast) | 将一个值转换成一个确定类型 | +| [`CONVERT()`](#convert) | 将一个值转换成一个确定类型 | > **注意:** > > TiDB 和 MySQL 对于 `SELECT CAST(MeN AS CHAR)`(或者等价的 `SELECT CONVERT(MeM, CHAR)`)的结果显示不一致,其中 `MeN` 是用科学计数法表示的双精度浮点数。MySQL 在 `-15 <= N <= 14` 时显示完整数值,在 `N < -15` 或 `N > 14` 时显示科学计数法。而 TiDB 始终显示完整数值。例如,MySQL 对于 `SELECT CAST(3.1415e15 AS CHAR)` 的显示结果为 `3.1415e15`,而 TiDB 的显示结果为 `3141500000000000`。 + +## BINARY + +[`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) 运算符从 MySQL 8.0.27 版本起已被废弃。建议在 TiDB 和 MySQL 中都改用 `CAST(... AS BINARY)`。 + +## CAST + +[`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) 函数用于将一个表达式的值转换为指定的数据类型。 + +此外,你还可以将该函数用于创建[多值索引](/sql-statements/sql-statement-create-index.md#多值索引)。 + +示例: + +```sql +SELECT CAST(0x54694442 AS CHAR); +``` + +```sql ++--------------------------+ +| CAST(0x54694442 AS CHAR) | ++--------------------------+ +| TiDB | ++--------------------------+ +1 row in set (0.0002 sec) +``` + +## CONVERT + +[`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) 函数用于在[字符集](/character-set-and-collation.md)之间进行转换。 + +示例: + +```sql +SELECT CONVERT(0x616263 USING utf8mb4); +``` + +```sql ++---------------------------------+ +| CONVERT(0x616263 USING utf8mb4) | ++---------------------------------+ +| abc | ++---------------------------------+ +1 row in set (0.0004 sec) +``` + +## MySQL 兼容性 + +- TiDB 不支持对空间类型 (`SPATIAL`) 进行转换操作。更多信息,请参考 [#6347](https://github.com/pingcap/tidb/issues/6347)。 +- TiDB 不支持在 `CAST()` 中使用 `AT TIME ZONE`。更多信息,请参考 [#51742](https://github.com/pingcap/tidb/issues/51742)。 +- `CAST(24 AS YEAR)` 在 TiDB 中返回的结果为两位数字,而在 MySQL 中返回的结果为四位数字。更多信息,请参考 [#29629](https://github.com/pingcap/tidb/issues/29629)。 \ No newline at end of file diff --git a/functions-and-operators/numeric-functions-and-operators.md b/functions-and-operators/numeric-functions-and-operators.md index cae19a6ff008..40d844375dc4 100644 --- a/functions-and-operators/numeric-functions-and-operators.md +++ b/functions-and-operators/numeric-functions-and-operators.md @@ -1,12 +1,12 @@ --- title: 数值函数与操作符 aliases: ['/docs-cn/dev/functions-and-operators/numeric-functions-and-operators/','/docs-cn/dev/reference/sql/functions-and-operators/numeric-functions-and-operators/'] -summary: TiDB 支持 MySQL 5.7 中的所有数值函数和操作符。包括加减乘除、整数除法、模运算、改变参数符号等算术操作符,以及返回乘方、自然对数、对数、正切值、余切值、正弦值、余弦值等数学函数。 +summary: TiDB 支持 MySQL 8.0 中的所有数值函数和操作符。 --- # 数值函数与操作符 -TiDB 支持使用 MySQL 5.7 中提供的所有[数值函数与操作符](https://dev.mysql.com/doc/refman/5.7/en/numeric-functions.html)。 +TiDB 支持使用 MySQL 8.0 中提供的所有[数值函数与操作符](https://dev.mysql.com/doc/refman/8.0/en/numeric-functions.html)。 ## 算术操作符 @@ -24,33 +24,37 @@ TiDB 支持使用 MySQL 5.7 中提供的所有[数值函数与操作符](https:/ | 函数名 | 功能描述 | |:----------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------| -| [`POW()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_pow) | 返回参数的指定乘方的结果值 | -| [`POWER()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_power) | 返回参数的指定乘方的结果值 | +| [`ABS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_abs) | 返回参数的绝对值 | +| [`ACOS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_acos) | 返回参数的反余弦值 | +| [`ASIN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_asin) | 返回参数的反正弦值 | +| [`ATAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_atan) | 返回参数的反正切值 | +| [`ATAN2(), ATAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_atan2) | 返回两个参数的反正切值 | +| [`CEIL()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_ceil) | 返回不小于参数的最小整数值 | +| [`CEILING()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_ceiling) | 返回不小于参数的最小整数值 | +| [`CONV()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_conv) | 不同数基间转换数字,返回数字的字符串表示 | +| [`COS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_cos) | 返回参数的余弦值 | +| [`COT()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_cot) | 返回参数的余切值 | +| [`CRC32()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_crc32) | 计算循环冗余码校验值并返回一个 32 位无符号值 | +| [`DEGREES()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_degrees) | 返回由弧度转化为度的参数 | | [`EXP()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_exp) | 返回 e(自然对数的底)的指定乘方后的值 | -| [`SQRT()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sqrt) | 返回非负数的二次方根 | +| [`FLOOR()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_floor) | 返回不大于参数的最大整数值 | | [`LN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_ln) | 返回参数的自然对数 | | [`LOG()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_log) | 返回第一个参数的自然对数 | -| [`LOG2()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_log2) | 返回参数以 2 为底的对数 | | [`LOG10()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_log10) | 返回参数以 10 为底的对数 | +| [`LOG2()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_log2) | 返回参数以 2 为底的对数 | +| [`MOD()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_mod) | 返回余数 | | [`PI()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_pi) | 返回 pi 的值 | -| [`TAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_tan) | 返回参数的正切值 | -| [`COT()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_cot) | 返回参数的余切值 | -| [`SIN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sin) | 返回参数的正弦值 | -| [`COS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_cos) | 返回参数的余弦值 | -| [`ATAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_atan) | 返回参数的反正切值 | -| [`ATAN2(), ATAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_atan2) | 返回两个参数的反正切值 | -| [`ASIN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_asin) | 返回参数的反正弦值 | -| [`ACOS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_acos) | 返回参数的反余弦值 | +| [`POW()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_pow) | 返回参数的指定乘方的结果值 | +| [`POWER()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_power) | 返回参数的指定乘方的结果值 | | [`RADIANS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_radians) | 返回由度转化为弧度的参数 | -| [`DEGREES()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_degrees) | 返回由弧度转化为度的参数 | -| [`MOD()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_mod) | 返回余数 | -| [`ABS()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_abs) | 返回参数的绝对值 | -| [`CEIL()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_ceil) | 返回不小于参数的最小整数值 | -| [`CEILING()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_ceiling) | 返回不小于参数的最小整数值 | -| [`FLOOR()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_floor) | 返回不大于参数的最大整数值 | -| [`ROUND()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_round) | 返回参数最近似的整数或指定小数位数的数值 | | [`RAND()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_rand) | 返回一个随机浮点值 | +| [`ROUND()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_round) | 返回参数最近似的整数或指定小数位数的数值 | | [`SIGN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sign) | 返回参数的符号 | -| [`CONV()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_conv) | 不同数基间转换数字,返回数字的字符串表示 | +| [`SIN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sin) | 返回参数的正弦值 | +| [`SQRT()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sqrt) | 返回非负数的二次方根 | +| [`TAN()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_tan) | 返回参数的正切值 | | [`TRUNCATE()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_truncate) | 返回被舍位至指定小数位数的数字 | -| [`CRC32()`](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_crc32)           | 计算循环冗余码校验值并返回一个 32 位无符号值                     | + +## 相关系统变量 + +通过 [`div_precision_increment`](/system-variables.md#div_precision_increment-从-v800-版本开始引入) 可以设置 `/` 运算符的精度。 diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index a4e6f8ebdac9..ab9e92f77623 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -415,11 +415,85 @@ SELECT CONCAT_WS(',', 'TiDB Server', 'TiKV', 'PD'); ### [`ELT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_elt) -返回指定位置的字符串 +`ELT()` 函数返回索引号对应的元素。 + +```sql +SELECT ELT(3, 'This', 'is', 'TiDB'); +``` + +```sql ++------------------------------+ +| ELT(3, 'This', 'is', 'TiDB') | ++------------------------------+ +| TiDB | ++------------------------------+ +1 row in set (0.00 sec) +``` + +在以上示例中,该函数返回第三个元素,即 `'TiDB'`。 ### [`EXPORT_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_export-set) -返回一个字符串,其中值位中设置的每个位,可以得到一个 on 字符串,而每个未设置的位,可以得到一个 off 字符串 +`EXPORT_SET()` 函数返回一个由指定数量 (`number_of_bits`) 的 `on`/`off` 值组成的字符串,各个值之间可以用 `separator` 分隔(可选)。这些值将基于输入的 `bits` 参数中的相应 bit 是否为 `1` 而确定,其中第一个值对应于 `bits` 中的最右边(即最低)的 bit。 + +语法: + +```sql +EXPORT_SET(bits, on, off, [separator[, number_of_bits]]) +``` + +- `bits`:一个代表 bits 值的整数。 +- `on`:如果对应的 bit 为 `1`,则返回该字符串。 +- `off`:如果对应的 bit 为 `0`,则返回该字符串。 +- `separator`(可选):输出字符串中的分隔符。 +- `number_of_bits`(可选):要处理的位数。如果未设置,则默认使用 `64`(最大位数),这意味着 `bits` 将被视为一个无符号 64 位整数。 + +示例: + +在以下示例中,`number_of_bits` 设置为 `5`,因此该函数返回由 `|` 分隔的 5 个值。`'101'` 里的 bit 值只有三位,所以其他位被视为未设置。因此,将 `number_of_bits` 设置为 `101` 或设置为 `00101` 的返回结果相同。 + +```sql +SELECT EXPORT_SET(b'101',"ON",'off','|',5); +``` + +```sql ++-------------------------------------+ +| EXPORT_SET(b'101',"ON",'off','|',5) | ++-------------------------------------+ +| ON|off|ON|off|off | ++-------------------------------------+ +1 row in set (0.00 sec) +``` + +在以下示例中,`bits` 设置为 `00001111`,`on` 设置为 `x`,`off` 设置为 `_`。这使函数在这些 `0` 位上返回 `____`,在这些 `1` 位上返回 `xxxx`。因此,从右到左处理 `00001111` 中的位时,该函数返回 `xxxx____`。 + +```sql +SELECT EXPORT_SET(b'00001111', 'x', '_', '', 8); +``` + +```sql ++------------------------------------------+ +| EXPORT_SET(b'00001111', 'x', '_', '', 8) | ++------------------------------------------+ +| xxxx____ | ++------------------------------------------+ +1 row in set (0.00 sec) +``` + +在以下示例中,`bits` 设置为 `00001111`,`on` 设置为 `x`,`off` 设置为 `_`。这使函数在每个 `1` 位上返回 `x`,在每个 `0` 位上返回 `_`。因此,从右到左处理 `01010101` 中的位时,该函数返回 `x_x_x_x_`。 + +```sql +SELECT EXPORT_SET(b'01010101', 'x', '_', '', 8); +``` + +```sql ++------------------------------------------+ +| EXPORT_SET(b'01010101', 'x', '_', '', 8) | ++------------------------------------------+ +| x_x_x_x_ | ++------------------------------------------+ +1 row in set (0.00 sec) +``` ### [`FIELD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_field) From 54ba4b8cdd8360dc4a7cc7bbf571ec57a120e075 Mon Sep 17 00:00:00 2001 From: Edwinmaster <87461911+Edwinmaster@users.noreply.github.com> Date: Fri, 26 Apr 2024 19:02:57 +0800 Subject: [PATCH 8/9] Update check-before-deployment.md (#17229) --- check-before-deployment.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/check-before-deployment.md b/check-before-deployment.md index a6d59b3ddc62..ec2ba93652d0 100644 --- a/check-before-deployment.md +++ b/check-before-deployment.md @@ -626,9 +626,17 @@ sudo systemctl enable ntpd.service echo "net.ipv4.tcp_tw_recycle = 0">> /etc/sysctl.conf echo "net.ipv4.tcp_syncookies = 0">> /etc/sysctl.conf echo "vm.overcommit_memory = 1">> /etc/sysctl.conf + echo "vm.min_free_kbytes = 1048576">> /etc/sysctl.conf sysctl -p ``` + > **注意:** + > + > - `vm.min_free_kbytes` 是 Linux 内核的一个参数,用于控制系统预留的最小空闲内存量,单位为 KiB。 + > - `vm.min_free_kbytes` 的设置会影响内存回收机制。设置得过大,会导致可用内存变少,设置得过小,可能会导致内存的申请速度超过后台的回收速度,进而导致内存回收并引起内存分配延迟。 + > - 建议将 `vm.min_free_kbytes` 最小设置为 `1048576` KiB(即 1 GiB)。如果[安装了 NUMA](/check-before-deployment.md#安装-numactl-工具),建议设置为 `NUMA 节点个数 * 1048576` KiB。 + > - 对于内存小于 16 GiB 的小规格服务器,保持 `vm.min_free_kbytes` 的默认值即可。 + 10. 执行以下命令配置用户的 limits.conf 文件。 {{< copyable "shell-regular" >}} From 32e6186880f4b6a82406558345c4314b5c66d593 Mon Sep 17 00:00:00 2001 From: JaySon Date: Sat, 27 Apr 2024 10:23:56 +0800 Subject: [PATCH 9/9] tiflash: Add note about mpp plan change (#17219) --- releases/release-7.3.0.md | 4 ++++ system-variables.md | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/releases/release-7.3.0.md b/releases/release-7.3.0.md index dd628c504220..d66095d0c24b 100644 --- a/releases/release-7.3.0.md +++ b/releases/release-7.3.0.md @@ -152,6 +152,10 @@ v7.3.0 引入了以下主要功能。[功能详情](#功能详情)中列出的 ### 行为变更 +* TiDB + + - MPP 是 TiFlash 引擎提供的分布式计算框架,允许节点之间的数据交换并提供高性能、高吞吐的 SQL 算法。相对其他协议,MPP 协议更加成熟,能提供更好的任务和资源管理。从 v7.3.0 起,当 TiDB 向 TiFlash 下推计算任务时,优化器默认只生成使用 MPP 协议的执行计划。如果设置了 [`tidb_allow_mpp`](/system-variables.md#tidb_allow_mpp-从-v50-版本开始引入) 为 `OFF`,在升级 TiDB 后查询可能会报错,建议在升级前检查 `tidb_allow_mpp` 的值并将其设置为 `ON`。如果仍然需要优化器根据成本估算从 Cop、BatchCop 和 MPP 协议中选择一个用于生成执行计划,可以将 [`tidb_allow_tiflash_cop`](/system-variables.md#tidb_allow_tiflash_cop-从-v730-版本开始引入) 变量设置为 `ON`。 + * Backup & Restore (BR) - 全量恢复前增加了空集群检查,默认不支持恢复到非空集群。如果强制恢复,可以使用 `--filter` 指定对应表名。 diff --git a/system-variables.md b/system-variables.md index 14e631d59155..a4948d2b4177 100644 --- a/system-variables.md +++ b/system-variables.md @@ -951,8 +951,8 @@ mysql> SHOW GLOBAL VARIABLES LIKE 'max_prepared_stmt_count'; - 类型:布尔型 - 默认值:`ON` - 这个变量用于控制是否使用 TiFlash 的 MPP 模式执行查询,可以设置的值包括: - - 0 或 OFF,代表从不使用 MPP 模式 - - 1 或 ON,代表由优化器根据代价估算选择是否使用 MPP 模式(默认) + - `0` 或 `OFF`,代表从不使用 MPP 模式。如果在 v7.3.0 及之后的版本将该变量值设置为 `0` 或 `OFF`,你需要同时开启 [`tidb_allow_tiflash_cop`](/system-variables.md#tidb_allow_tiflash_cop-从-v730-版本开始引入) 变量,否则可能遇到查询报错。 + - `1` 或 `ON`,代表由优化器根据代价估算选择是否使用 MPP 模式(默认)。 MPP 是 TiFlash 引擎提供的分布式计算框架,允许节点之间的数据交换并提供高性能、高吞吐的 SQL 算法。MPP 模式选择的详细说明参见[控制是否选择 MPP 模式](/tiflash/use-tiflash-mpp-mode.md#控制是否选择-mpp-模式)。