diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
index 3d14b8a64..4cedf15a4 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-centos7-foe-56
-sidebar_position: 5.12.1
+sidebar_position: 5.121
---
# Compile StoneDB for MySQL5.6 on CentOS 7
diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
index 470dd78c1..46e30bbfa 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-centos7-for-57
-sidebar_position: 5.12.2
+sidebar_position: 5.122
---
# Compile StoneDB for MySQL5.7 on CentOS 7
diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
index f4dc2e5dc..863dcf313 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-redhat7-for-56
-sidebar_position: 5.13.1
+sidebar_position: 5.131
---
# Compile StoneDB for MySQL5.6 on RHEL 7
diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
index 1bd178dd6..23a0a73fa 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-redhat7-for-57
-sidebar_position: 5.13.2
+sidebar_position: 5.132
---
# Compile StoneDB for MySQL5.7 on RHEL 7
diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
index ac3c3a998..32ce550de 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-ubuntu20.04-for-56
-sidebar_position: 5.14.1
+sidebar_position: 5.141
---
# Compile StoneDB for MySQL5.6 on Ubuntu 20.04
diff --git a/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md b/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
index 96bbd09f9..54c9e2abc 100644
--- a/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
+++ b/Docs/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-ubuntu20.04-for-57
-sidebar_position: 5.14.2
+sidebar_position: 5.142
---
# Compile StoneDB for MySQL5.7 on Ubuntu 20.04
diff --git a/README_zh-hans.md b/README_zh-hans.md
index 42312a6a1..95e9e55db 100644
--- a/README_zh-hans.md
+++ b/README_zh-hans.md
@@ -133,7 +133,7 @@ mysqld_safe --defaults-file=/path/to/my.cnf --user=mysql &
## 用 StoneDB 创建表
```sql
---The example code for creating a table with 'stonedb' engine.
+--The example code for creating a table with 'tianmu' engine.(For version 5.7 or later)
CREATE TABLE `example_table` (
`id1` bigint(20) NOT NULL DEFAULT '0',
`id1_type` int(10) NOT NULL DEFAULT '0',
@@ -142,8 +142,8 @@ CREATE TABLE `example_table` (
`data` varchar(255) NOT NULL DEFAULT '',
`time` bigint(20) NOT NULL DEFAULT '0',
`version` int(11) NOT NULL DEFAULT '0',
-) ENGINE=stonedb;
-
+) ENGINE=tianmu;
+-- For version 5.6, the engine should be set to 'stonedb'
```
这个例子展示了 StoneDB 中的一些重要特性和限制。有关限制的更多信息,请参见 [StoneDB Limitations](https://stonedb.io/docs/about-stonedb/limits).
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/architecture.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/architecture.md
index f87da2f54..0255484cc 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/architecture.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/architecture.md
@@ -5,7 +5,7 @@ sidebar_position: 1.2
# 整体架构
-![image.png](./stonedb-V1-zhCN.png)
+![StoneDB V1.0 架构](./stonedb-V1-zhCN.png)
StoneDB 是一个 HTAP 数据库,其存储引擎 Tianmu 是一个高性能、高压缩比的列式存储引擎,适用于 OLAP 应用。和其他的存储引擎如 InnoDB、MyISAM 一样,Tianmu 提供了存储引擎所具有的一切功能。从架构上可以看出,逻辑上分为应用层、服务层和存储引擎层。在 StoneDB 中,一个 SQL 从发起到最终返回结果,会经历每个逻辑层的不同组件。
## 应用层
@@ -42,18 +42,18 @@ StoneDB 有自己的优化器,优化器会对 SQL 语句进行优化,如表
粗糙集是一门数学学科,用来研究不完整的数据,不精确的知识表达、学习、归纳等的一套理论。在 StoneDB 中,粗糙集用于对数据包的划分,根据 SQL 的查询条件的数据在数据包中的确认范围,数据包分为以下几类:
-1)不相关的数据包:表示不满足查询条件的数据包,这类数据包直接被忽略。
+1. 不相关的数据包:表示不满足查询条件的数据包,这类数据包直接被忽略。
-2)相关的数据包:表示满足查询条件的数据包,如果要查询相关的数据包里面的具体数据,需要对数据包进行解压缩,如果根据数据包的元数据节点就能得到数据,那么就不需要解压缩数据包。
+2. 相关的数据包:表示满足查询条件的数据包,如果要查询相关的数据包里面的具体数据,需要对数据包进行解压缩,如果根据数据包的元数据节点就能得到数据,那么就不需要解压缩数据包。
-3)可疑的数据包:表示数据包中的数据部分满足查询条件,需要进一步解压缩数据包才能得到满足条件的数据。
+3. 可疑的数据包:表示数据包中的数据部分满足查询条件,需要进一步解压缩数据包才能得到满足条件的数据。
#### Data Pack Node
数据包节点也称为元数据节点,记录了每个数据包中列的最大值、最小值、平均值、总和、总记录数、null 值的数量、压缩方式、占用的字节数。每一个元数据节点对应一个数据包。
#### Knowledge Node
元数据节点的上一层是知识节点,除了记录数据包之间或者列之间关系的元数据集合,比如数据包的最小值与最大值范围、列之间的关联关系外,还记录了数据特征以及更深度的统计信息。大部分的知识节点数据是装载数据的时候产生的,另外一部分是查询的时候产生的。
知识节点的3种基本类型:
-##### 1)Histogram
+##### 1. Histogram
数据类型为整型、日期型、浮点型的列的统计值以直方图的形式存在。将一个数据包的最小值到最大值之间分为1024段,每段占用一个 bit,如果数据包中的实际值处于段中的范围,则标记为1,否则标记为0。Histogam 在数据被加载时自动创建。
如下的例子中,说明数据包中有值落在0~100和102301~102400两个区间。
@@ -67,7 +67,7 @@ StoneDB 有自己的优化器,优化器会对 SQL 语句进行优化,如表
select * from table where id>199 and id<299;
```
通过直方图可知,这个查询没有在这个数据包命中,即当前数据包不满足查询条件,这个数据包直接被丢弃。
-##### 2)Character Map
+##### 2. Character Map
数据类型为字符串的列的字符映射表。统计当前数据包内 1~64 长度中 ASCII 字符是否存在。如果存在,则标记为1,否则标记为0。字符检索时,按照字符顺序依次对比字符标识值即可知道该数据包是否包含匹配数据。Character Map 在数据被加载时自动创建。
如下的例子中,说明 A 在字符串的第1个和第64个位置。
@@ -79,7 +79,7 @@ select * from table where id>199 and id<299;
| C | 1 | 1 | ... | 1 |
| ... | ... | ... | ... | ... |
-##### 3)Pack to Pack
+##### 3. Pack to Pack
包对包关系表示不同表的两个列之间的等值映射表,并以二进制矩阵的形式进行存储,如果符合表关联条件,则标记为1,否则标记为0。包对包关系能帮助在表关联查询的时候快速判断出符合查询条件的数据包,从而提升表关联查询的效率。表关联查询时,Pack to Pack 被自动创建。
如下的例子中,表关联的查询条件是"A.C=B.D",在 A.C1 这个数据包中,只有 B.D2 和 B.D5 这两个数据包中有符合表关联条件的值。
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/intro.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/intro.md
index fbafebff5..8125adbbc 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/intro.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/intro.md
@@ -15,36 +15,36 @@ StoneDB 采用基于知识网格技术和列式存储引擎,该存储引擎为
## 产品优势
-- 完全兼容 MySQL
+### 完全兼容 MySQL
StoneDB 支持标准数据库接口,包括 ODBC、JDBC 和本地连接。支持 API 接口,包括 C、C++、C#、Java、PHP、Perl 等。StoneDB 全面支持 ANSI SQL-92 标准和 SQL-99 扩展标准中视图和存储过程,这种支持使得现有应用程序无需修改应用代码即可使用 StoneDB,从而可实现与 MySQL 的无缝切换。
-- 高性能查询
+### 高性能查询
在千万、亿级甚至更多数据量下进行复杂查询时,StoneDB 相比其他行式存储引擎的关系型数据库,其查询速度提升了十倍以上。
-- 低存储成本
+### 低存储成本
对数据最高可实现40倍压缩,极大的节省了数据存储空间和企业的成本。
## 核心技术
-- 列式存储
+### 列式存储
StoneDB 创建的表在磁盘上是以列模式进行存储的,由于关系型数据库中每一列的数据类型都相同,所以这种连续的空间存储与行式存储相比,更加能够实现数据的高压缩比。在读取数据方面,如果只想查询一个字段的结果,在行式存储中,引擎层向服务层返回的是一整行的数据,需要消耗更多的网络带宽和 IO。而列式存储只需要返回一个字段,极大减少了网络带宽和 IO 的消耗。另外,列式存储无需再为列创建索引和维护索引。
-- 高效的数据压缩比
+### 高效的数据压缩比
StoneDB 会根据不同的数据类型选择不同的压缩算法,目前支持的压缩算法主要有 PPM、LZ4、B2、Delta 等。数据被压缩后,数据量变得更小,在读取数据时,对网络带宽和磁盘 IO 的压力也就越小。由于列式存储相比行式存储有十倍甚至更高的压缩比,StoneDB 可以节省大量的存储空间,降低存储成本。
-- 知识网格
+### 知识网格
在 StoneDB 中,数据包根据粗糙集概念划分为不相关数据包、可疑数据包、相关数据包。StoneDB 根据知识网格技术过滤掉不相关的数据包,对可疑数据包需要进一步解压缩才能得到满足条件的数据。如果能从相关数据包的元数据节点得到结果,无需再解压缩数据包。这样就消除了解压缩数据包的过程和降低 IO 消耗,提高了查询响应时间和网络利用率。
-- 高性能导入
+### 高性能导入
StoneDB 提供独立的数据导入客户端,支持不同的数据源环境,支持多语言架构。数据在导入前,首先会进行预处理,如数据压缩和知识节点的构建。数据经过预处理后,进入存储引擎无需再次执行解析、数据验证以及事务处理等操作。
-- 基于推送的矢量化查询处理
+### 基于推送的矢量化查询处理
StoneDB 通过执行计划将矢量块(列式数据切片)从一个运算符推送到另一个运算符来处理查询,与基于元组的处理模型相比,基于推送的执行模型避免了深度调用堆栈,并节省了资源。
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/stonedb-V1-zhCN.png b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/stonedb-V1-zhCN.png
index 54c86d3b9..42eb15113 100644
Binary files a/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/stonedb-V1-zhCN.png and b/website/i18n/zh/docusaurus-plugin-content-docs/current/00-about-stonedb/stonedb-V1-zhCN.png differ
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/02-getting-started/basic-operations.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/02-getting-started/basic-operations.md
index b371247cb..515bbf6aa 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/02-getting-started/basic-operations.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/02-getting-started/basic-operations.md
@@ -47,7 +47,10 @@ age smallint,
birthday DATE
) engine=stonedb;
```
-注:1)StoneDB 5.6 的存储引擎名是 stonedb,5.7 的存储引擎名是 tianmu。
2)如果 SQL 语句中未指定“engine=stonedb”,则所创建的表的存储引擎由参数 default_storage_engine 决定,详情参见[设置参数](../04-developer-guide/05-appendix/configuration-parameters.md)。
+:::info
+1. StoneDB-5.6 的存储引擎名是 `stonedb`;StoneDB-5.7 的存储引擎名是 `tianmu`。
+2。 如果 SQL 语句中未指定“engine=stonedb”,则所创建的表的存储引擎由参数 default_storage_engine 决定,详情参见[设置参数](../04-developer-guide/05-appendix/configuration-parameters.md)。
+:::
### 2)查看表
查看表结构使用以下 SQL 语句:
```sql
@@ -90,7 +93,9 @@ select name,birthday from student order by birthday;
```sql
create user 'tiger'@'%' identified by '123456';
```
-注:用户名和主机名('username'@'host')唯一表示一个用户,'tiger'@'%'和'tiger'@'localhost'是两个不同的用户。
+:::info
+用户名和主机名('username'@'host')唯一表示一个用户,'tiger'@'%'和'tiger'@'localhost'是两个不同的用户。
+:::
### 2)向用户授权
例如:向用户 tiger 授予可查询数据库 test_db 所有的表,可以使用以下 SQL 语句:
```sql
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mydumper-full-backup.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mydumper-full-backup.md
index d80f2c02b..90808520a 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mydumper-full-backup.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mydumper-full-backup.md
@@ -5,36 +5,38 @@ sidebar_position: 4.32
# MySQL全量数据备份-mydumper
-mydumper项目地址:[https://github.com/mydumper/mydumper](https://github.com/mydumper/mydumper)
-## Mydumper介绍
-### 什么是Mydumper?
-Mydumper 是一个 MySQL 逻辑备份工具。它有 2 个工具:
+mydumper 项目地址:[https://github.com/mydumper/mydumper](https://github.com/mydumper/mydumper)
+## mydumper 介绍
+### 什么是 mydumper?
+mydumper 是一个 MySQL 逻辑备份工具,它有 2 个工具:
-- mydumper负责导出 MySQL 数据库的一致备份
-- myloader从 mydumper 读取备份,连接到目标数据库并导入备份。两种工具都使用多线程功能
-### Mydumper优势
+- mydumper 负责导出数据。
+- myloader 从 mydumper 读取备份,连接到目标数据库并导入备份,两种工具都可以使用多线程。
+### mydumper 优势
-- 并行性(因此,速度)和性能(避免昂贵的字符集转换例程,整体高效的代码)
-- 更易于管理输出(表的单独文件、转储元数据等,易于查看/解析数据)
-- 一致性 - 维护所有线程的快照,提供准确的主从日志位置等
-- 可管理性 - 支持 PCRE 以指定数据库和表的包含和排除
-### Mydumper主要特性
+- 并行性和性能
+- 更易于管理输出,表的单独文件、转储元数据等,易于查看/解析数据
+- 一致性,维护所有线程的快照,提供准确的主从日志位置等
+- 可管理性,支持 PCRE 以指定数据库和表的包含和排除
+### mydumper 主要特性
- 多线程备份,备份后会生成多个备份文件
-- 事务性和非事务性表一致的快照(适用于0.2.2以上版本)
+- 事务性和非事务性表一致的快照(适用于0.2.2以上版本)
- 快速的文件压缩
-- 支持导出binlog
-- 多线程恢复(适用于0.2.1以上版本)
-- 以守护进程的工作方式,定时快照和连续二进制日志(适用于0.5.0以上版本)
-- 开源 (GNU GPLv3)
-## Mydumper使用
-### Mydumer 参数
+- 支持导出 binlog
+- 多线程恢复(适用于0.2.1以上版本)
+- 以守护进程的工作方式,定时快照和连续二进制日志(适用于0.5.0以上版本)
+- 开源(GNU GPLv3)
+## mydumper使用
+### mydumer 参数
```bash
mydumper --help
Usage:
mydumper [OPTION…] multi-threaded MySQL dumping
+
Help Options:
-?, --help Show help options
+
Application Options:
-B, --database Database to dump
-o, --outputdir Directory to output files to
@@ -105,13 +107,15 @@ Application Options:
-S, --socket UNIX domain socket file to use for connection
-x, --regex Regular expression for 'db.table' matching
```
-### Myloader参数
+### myloader参数
```bash
myloader --help
Usage:
myloader [OPTION…] multi-threaded MySQL loader
+
Help Options:
-?, --help Show help options
+
Application Options:
-d, --directory Directory of the dump to import
-q, --queries-per-transaction Number of queries per transaction, default 1000
@@ -148,20 +152,22 @@ Application Options:
-S, --socket UNIX domain socket file to use for connection
-x, --regex Regular expression for 'db.table' matching
--skip-definer Removes DEFINER from the CREATE statement. By default, statements are not modified
+
```
### 安装使用
```bash
-#到项目github 上下载机器对应的rpm包或者源码包,源码包需要进行编译,rpm包安装简单建议使用,本文以centos 7系统为例,所以下载el7版本
+# 到项目 github 上下载机器对应的 rpm 包或者源码包,源码包需要进行编译,rpm 包安装简单建议使用,本文以 CentOS 7 系统为例,所以下载 el7 版本
[root@dev tmp]# wget https://github.com/mydumper/mydumper/releases/download/v0.12.1/mydumper-0.12.1-1-zstd.el7.x86_64.rpm
-#由于下载的mydumper是zstd类型的,所以需要下载libzstd依赖
+# 由于下载的 mydumper 是 zstd 类型的,所以需要下载 libzstd 依赖
[root@dev tmp]# yum install libzstd.x86_64 -y
-[root@dev tmp]#rpm -ivh mydumper-0.12.1-1-zstd.el7.x86_64.rpm
+[root@dev tmp]# rpm -ivh mydumper-0.12.1-1-zstd.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mydumper-0.12.1-1 ################################# [100%]
-#备份库
+
+# 备份库
[root@dev home]# mydumper -u root -p xxx -P 3306 -h 127.0.0.1 -B zz -o /home/dumper/
-#恢复库
+# 恢复库
[root@dev home]# myloader -u root -p xxx -P 3306 -h 127.0.0.1 -S /stonedb/install/tmp/mysql.sock -B zz -d /home/dumper
```
**备份所生成的文件**
@@ -179,6 +185,7 @@ SHOW MASTER STATUS:
Log: mysql-bin.000002
Pos: 4737113
GTID:
+
Finished dump at: 2022-03-23 15:51:40
[root@dev-myos dumper]# cat zz-schema-create.sql
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `zz` /*!40100 DEFAULT CHARACTER SET utf8 */;
@@ -194,6 +201,7 @@ INSERT INTO `t_user` VALUES(1,"e1195afd-aa7d-11ec-936e-00155d840103","kAMXjvtFJy
[root@dev-myos dumper]# cat zz.t_user-schema.sql
/*!40101 SET NAMES binary*/;
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
+
/*!40103 SET TIME_ZONE='+00:00' */;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
@@ -206,37 +214,31 @@ CREATE TABLE `t_user` (
KEY `idx_user_id` (`c_user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8;
```
+
目录
-metadata文件
+
+metadata 文件
+
- 记录了备份数据库在备份时间点的二进制日志文件名,日志的写入位置,
- 如果是在从库进行备份,还会记录备份时同步至主库的二进制日志文件及写入位置
+
每个表有两个备份文件:
-database-schema-create 库创建语句文件
-database.table-schema.sql 表结构文件
-database.table.00000.sql 表数据文件
-database.table-metadata 表元数据文件
-***扩展***
-如果要导入数据到StoneDB,需要把Mydumper的database.table-schema.sql 表结构文件中建表语句engine=innodb 改成 engine=stonedb,并检查表结构是否有StoneDB不兼容的语法:类似unsigned 之类的限制。修改后结构示例:
-```
-[root@dev-myos dumper]# cat zz.t_user-schema.sql
-/*!40101 SET NAMES binary*/;
-/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
-/*!40103 SET TIME_ZONE='+00:00' */;
-CREATE TABLE `t_user` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `c_user_id` varchar(36) NOT NULL DEFAULT '',
- `c_name` varchar(22) NOT NULL DEFAULT '',
- `c_province_id` int(11) NOT NULL,
- `c_city_id` int(11) NOT NULL,
- `create_time` datetime NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=STONEDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8;
-```
+
+- database-schema-create 库创建语句文件
+
+- database.table-schema.sql 表结构文件
+
+- database.table.00000.sql 表数据文件
+
+- database.table-metadata 表元数据文件
+
### 备份原理
- - 主线程 FLUSH TABLES WITH READ LOCK, 施加全局只读锁,保证数据的一致性
- - 读取当前时间点的二进制日志文件名和日志写入的位置并记录在metadata文件中,以供全量恢复后追加binlog恢复使用
- - N个(线程数可以指定,默认是4)dump线程把事务隔离级别改为可重复读 并开启一致性读事务
+
+ - 主线程 FLUSH TABLES WITH READ LOCK,施加全局只读锁,保证数据的一致性
+ - 读取当前时间点的二进制日志文件名和日志写入的位置并记录在 metadata 文件中,以供全量恢复后追加 binlog 恢复使用
+ - N个(线程数可以指定,默认是4)dump 线程把事务隔离级别改为可重复读 并开启一致性读事务
- dump non-InnoDB tables, 首先导出非事物引擎的表
- 主线程 UNLOCK TABLES 非事物引擎备份完后,释放全局只读锁
- - dump InnoDB tables, 基于事物导出InnoDB表
- - 事物结束
\ No newline at end of file
+ - dump InnoDB tables,基于事物导出 InnoDB 表
+ - 事物结束
+
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mysqldump-backup-and-restore.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mysqldump-backup-and-restore.md
index 7bed6bc4b..b645c29d3 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mysqldump-backup-and-restore.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/03-O&M-Guide/01-backup-and-recovery/use-mysqldump-backup-and-restore.md
@@ -6,363 +6,19 @@ sidebar_position: 4.31
# 使用mysqldump备份恢复StoneDB
## mysqldump介绍
-mysqldump是MySQL 执行逻辑备份的工具,执行mysqldump后会生成一组SQL语句,可以通过这些语句来重现原始数据库定义的库表数据,它可以转储一个或者多个本地MySQL数据库或者远程可访问的数据库备份。mysqldump使用可以参考MySQL官方文档说明:[4.5.4 mysqldump — A Database Backup Program](https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html),或者参考以下mysqldump 使用参数:
-```bash
-# mysqldump --help
-mysqldump Ver 10.13 Distrib 5.6.24-StoneDB, for Linux (x86_64)
-Copyright (c) 2000, 2022 StoneAtom Group Holding Limited
-Dumping structure and contents of MySQL databases and tables.
-Usage: mysqldump [OPTIONS] database [tables]
-OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
-OR mysqldump [OPTIONS] --all-databases [OPTIONS]
-Default options are read from the following files in the given order:
-/etc/stonedb.cnf /etc/mysql/stonedb.cnf /stonedb56/install/stonedb.cnf ~/.stonedb.cnf
-The following groups are read: mysqldump client
-The following options may be given as the first argument:
---print-defaults Print the program argument list and exit.
---no-defaults Don't read default options from any option file,
- except for login file.
---defaults-file=# Only read default options from the given file #.
---defaults-extra-file=# Read this file after the global files are read.
---defaults-group-suffix=#
- Also read groups with concat(group, suffix)
---login-path=# Read this path from the login file.
- -A, --all-databases Dump all the databases. This will be same as --databases
- with all databases selected.
- -Y, --all-tablespaces
- Dump all the tablespaces.
- -y, --no-tablespaces
- Do not dump any tablespace information.
- --add-drop-database Add a DROP DATABASE before each create.
- --add-drop-table Add a DROP TABLE before each create.
- (Defaults to on; use --skip-add-drop-table to disable.)
- --add-drop-trigger Add a DROP TRIGGER before each create.
- --add-locks Add locks around INSERT statements.
- (Defaults to on; use --skip-add-locks to disable.)
- --allow-keywords Allow creation of column names that are keywords.
- --apply-slave-statements
- Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START
- SLAVE' to bottom of dump.
- --bind-address=name IP address to bind to.
- --character-sets-dir=name
- Directory for character set files.
- -i, --comments Write additional information.
- (Defaults to on; use --skip-comments to disable.)
- --compatible=name Change the dump to be compatible with a given mode. By
- default tables are dumped in a format optimized for
- MySQL. Legal modes are: ansi, mysql323, mysql40,
- postgresql, oracle, mssql, db2, maxdb, no_key_options,
- no_table_options, no_field_options. One can use several
- modes separated by commas. Note: Requires MySQL server
- version 4.1.0 or higher. This option is ignored with
- earlier server versions.
- --compact Give less verbose output (useful for debugging). Disables
- structure comments and header/footer constructs. Enables
- options --skip-add-drop-table --skip-add-locks
- --skip-comments --skip-disable-keys --skip-set-charset.
- -c, --complete-insert
- Use complete insert statements.
- -C, --compress Use compression in server/client protocol.
- -a, --create-options
- Include all MySQL specific create options.
- (Defaults to on; use --skip-create-options to disable.)
- -B, --databases Dump several databases. Note the difference in usage; in
- this case no tables are given. All name arguments are
- regarded as database names. 'USE db_name;' will be
- included in the output.
- -#, --debug[=#] This is a non-debug version. Catch this and exit.
- --debug-check Check memory and open file usage at exit.
- --debug-info Print some debug info at exit.
- --default-character-set=name
- Set the default character set.
- --delayed-insert Insert rows with INSERT DELAYED.
- --delete-master-logs
- Delete logs on master after backup. This automatically
- enables --master-data.
- -K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and
- '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put
- in the output.
- (Defaults to on; use --skip-disable-keys to disable.)
- --dump-slave[=#] This causes the binary log position and filename of the
- master to be appended to the dumped data output. Setting
- the value to 1, will printit as a CHANGE MASTER command
- in the dumped data output; if equal to 2, that command
- will be prefixed with a comment symbol. This option will
- turn --lock-all-tables on, unless --single-transaction is
- specified too (in which case a global read lock is only
- taken a short time at the beginning of the dump - don't
- forget to read about --single-transaction below). In all
- cases any action on logs will happen at the exact moment
- of the dump.Option automatically turns --lock-tables off.
- -E, --events Dump events.
- -e, --extended-insert
- Use multiple-row INSERT syntax that include several
- VALUES lists.
- (Defaults to on; use --skip-extended-insert to disable.)
- --fields-terminated-by=name
- Fields in the output file are terminated by the given
- string.
- --fields-enclosed-by=name
- Fields in the output file are enclosed by the given
- character.
- --fields-optionally-enclosed-by=name
- Fields in the output file are optionally enclosed by the
- given character.
- --fields-escaped-by=name
- Fields in the output file are escaped by the given
- character.
- -F, --flush-logs Flush logs file in server before starting dump. Note that
- if you dump many databases at once (using the option
- --databases= or --all-databases), the logs will be
- flushed for each database dumped. The exception is when
- using --lock-all-tables or --master-data: in this case
- the logs will be flushed only once, corresponding to the
- moment all tables are locked. So if you want your dump
- and the log flush to happen at the same exact moment you
- should use --lock-all-tables or --master-data with
- --flush-logs.
- --flush-privileges Emit a FLUSH PRIVILEGES statement after dumping the mysql
- database. This option should be used any time the dump
- contains the mysql database and any other database that
- depends on the data in the mysql database for proper
- restore.
- -f, --force Continue even if we get an SQL error.
- -?, --help Display this help message and exit.
- --hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in
- hexadecimal format.
- -h, --host=name Connect to host.
- --ignore-table=name Do not dump the specified table. To specify more than one
- table to ignore, use the directive multiple times, once
- for each table. Each table must be specified with both
- database and table names, e.g.,
- --ignore-table=database.table.
- --include-master-host-port
- Adds 'MASTER_HOST=, MASTER_PORT=' to 'CHANGE
- MASTER TO..' in dump produced with --dump-slave.
- --insert-ignore Insert rows with INSERT IGNORE.
- --lines-terminated-by=name
- Lines in the output file are terminated by the given
- string.
- -x, --lock-all-tables
- Locks all tables across all databases. This is achieved
- by taking a global read lock for the duration of the
- whole dump. Automatically turns --single-transaction and
- --lock-tables off.
- -l, --lock-tables Lock all tables for read.
- (Defaults to on; use --skip-lock-tables to disable.)
- --log-error=name Append warnings and errors to given file.
- --master-data[=#] This causes the binary log position and filename to be
- appended to the output. If equal to 1, will print it as a
- CHANGE MASTER command; if equal to 2, that command will
- be prefixed with a comment symbol. This option will turn
- --lock-all-tables on, unless --single-transaction is
- specified too (in which case a global read lock is only
- taken a short time at the beginning of the dump; don't
- forget to read about --single-transaction below). In all
- cases, any action on logs will happen at the exact moment
- of the dump. Option automatically turns --lock-tables
- off.
- --max-allowed-packet=#
- The maximum packet length to send to or receive from
- server.
- --net-buffer-length=#
- The buffer size for TCP/IP and socket communication.
- --no-autocommit Wrap tables with autocommit/commit statements.
- -n, --no-create-db Suppress the CREATE DATABASE ... IF EXISTS statement that
- normally is output for each dumped database if
- --all-databases or --databases is given.
- -t, --no-create-info
- Don't write table creation info.
- -d, --no-data No row information.
- -N, --no-set-names Same as --skip-set-charset.
- --opt Same as --add-drop-table, --add-locks, --create-options,
- --quick, --extended-insert, --lock-tables, --set-charset,
- and --disable-keys. Enabled by default, disable with
- --skip-opt.
- --order-by-primary Sorts each table's rows by primary key, or first unique
- key, if such a key exists. Useful when dumping a MyISAM
- table to be loaded into an InnoDB table, but will make
- the dump itself take considerably longer.
- -p, --password[=name]
- Password to use when connecting to server. If password is
- not given it's solicited on the tty.
- -P, --port=# Port number to use for connection.
- --protocol=name The protocol to use for connection (tcp, socket, pipe,
- memory).
- -q, --quick Don't buffer query, dump directly to stdout.
- (Defaults to on; use --skip-quick to disable.)
- -Q, --quote-names Quote table and column names with backticks (`).
- (Defaults to on; use --skip-quote-names to disable.)
- --replace Use REPLACE INTO instead of INSERT INTO.
- -r, --result-file=name
- Direct output to a given file. This option should be used
- in systems (e.g., DOS, Windows) that use carriage-return
- linefeed pairs (\r\n) to separate text lines. This option
- ensures that only a single newline is used.
- -R, --routines Dump stored routines (functions and procedures).
- --set-charset Add 'SET NAMES default_character_set' to the output.
- (Defaults to on; use --skip-set-charset to disable.)
- --set-gtid-purged[=name]
- Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
- values for this option are ON, OFF and AUTO. If ON is
- used and GTIDs are not enabled on the server, an error is
- generated. If OFF is used, this option does nothing. If
- AUTO is used and GTIDs are enabled on the server, 'SET
- @@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
- are disabled, AUTO does nothing. If no value is supplied
- then the default (AUTO) value will be considered.
- --single-transaction
- Creates a consistent snapshot by dumping all tables in a
- single transaction. Works ONLY for tables stored in
- storage engines which support multiversioning (currently
- only InnoDB does); the dump is NOT guaranteed to be
- consistent for other storage engines. While a
- --single-transaction dump is in process, to ensure a
- valid dump file (correct table contents and binary log
- position), no other connection should use the following
- statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
- TRUNCATE TABLE, as consistent snapshot is not isolated
- from them. Option automatically turns off --lock-tables.
- --dump-date Put a dump date to the end of the output.
- (Defaults to on; use --skip-dump-date to disable.)
- --skip-opt Disable --opt. Disables --add-drop-table, --add-locks,
- --create-options, --quick, --extended-insert,
- --lock-tables, --set-charset, and --disable-keys.
- -S, --socket=name The socket file to use for connection.
- --secure-auth Refuse client connecting to server if it uses old
- (pre-4.1.1) protocol.
- (Defaults to on; use --skip-secure-auth to disable.)
- --ssl Enable SSL for connection (automatically enabled with
- other flags).
- --ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
- --ssl).
- --ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
- --ssl-cert=name X509 cert in PEM format (implies --ssl).
- --ssl-cipher=name SSL cipher to use (implies --ssl).
- --ssl-key=name X509 key in PEM format (implies --ssl).
- --ssl-crl=name Certificate revocation list (implies --ssl).
- --ssl-crlpath=name Certificate revocation list path (implies --ssl).
- --ssl-verify-server-cert
- Verify server's "Common Name" in its cert against
- hostname used when connecting. This option is disabled by
- default.
- -T, --tab=name Create tab-separated textfile for each table to given
- path. (Create .sql and .txt files.) NOTE: This only works
- if mysqldump is run on the same machine as the mysqld
- server.
- --tables Overrides option --databases (-B).
- --triggers Dump triggers for each dumped table.
- (Defaults to on; use --skip-triggers to disable.)
- --tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of
- TIMESTAMP data when a server has data in different time
- zones or data is being moved between servers with
- different time zones.
- (Defaults to on; use --skip-tz-utc to disable.)
- -u, --user=name User for login if not current user.
- -v, --verbose Print info about the various stages.
- -V, --version Output version information and exit.
- -w, --where=name Dump only selected records. Quotes are mandatory.
- -X, --xml Dump a database as well formed XML.
- --plugin-dir=name Directory for client-side plugins.
- --default-auth=name Default authentication client-side plugin to use.
-Variables (--variable-name=value)
-and boolean options {FALSE|TRUE} Value (after reading options)
---------------------------------- ----------------------------------------
-all-databases FALSE
-all-tablespaces FALSE
-no-tablespaces FALSE
-add-drop-database FALSE
-add-drop-table TRUE
-add-drop-trigger FALSE
-add-locks TRUE
-allow-keywords FALSE
-apply-slave-statements FALSE
-bind-address (No default value)
-character-sets-dir (No default value)
-comments TRUE
-compatible (No default value)
-compact FALSE
-complete-insert FALSE
-compress FALSE
-create-options TRUE
-databases FALSE
-debug-check FALSE
-debug-info FALSE
-default-character-set utf8
-delayed-insert FALSE
-delete-master-logs FALSE
-disable-keys TRUE
-dump-slave 0
-events FALSE
-extended-insert TRUE
-fields-terminated-by (No default value)
-fields-enclosed-by (No default value)
-fields-optionally-enclosed-by (No default value)
-fields-escaped-by (No default value)
-flush-logs FALSE
-flush-privileges FALSE
-force FALSE
-hex-blob FALSE
-host (No default value)
-include-master-host-port FALSE
-insert-ignore FALSE
-lines-terminated-by (No default value)
-lock-all-tables FALSE
-lock-tables TRUE
-log-error (No default value)
-master-data 0
-max-allowed-packet 536870912
-net-buffer-length 1046528
-no-autocommit FALSE
-no-create-db FALSE
-no-create-info FALSE
-no-data FALSE
-order-by-primary FALSE
-port 3308
-quick TRUE
-quote-names TRUE
-replace FALSE
-routines FALSE
-set-charset TRUE
-single-transaction FALSE
-dump-date TRUE
-socket /stonedb56/install/tmp/mysql.sock
-secure-auth TRUE
-ssl FALSE
-ssl-ca (No default value)
-ssl-capath (No default value)
-ssl-cert (No default value)
-ssl-cipher (No default value)
-ssl-key (No default value)
-ssl-crl (No default value)
-ssl-crlpath (No default value)
-ssl-verify-server-cert FALSE
-tab (No default value)
-triggers TRUE
-tz-utc TRUE
-user (No default value)
-verbose FALSE
-where (No default value)
-plugin-dir (No default value)
-default-auth (No default value)
+mysqldump 是 MySQL 逻辑备份工具,执行 mysqldump 后会生成一组SQL语句,可以通过这些语句来重现原始数据库定义的库表数据,它可以转储一个或者多个本地 MySQL 数据库或者远程可访问的数据库备份。mysqldump 的使用可以参考 MySQL 官方文档说明:[4.5.4 mysqldump — A Database Backup Program](https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html),或者参考以下 mysqldump 使用参数。
+```shell
+/stonedb56/install/bin/mysqldump --help
```
-## 备份StoneDB注意事项
-StoneDB不支持lock tables 操作,所以需要在备份时加上--skip-opt 或者--skip-add-locks 参数,去除备份文件中的LOCK TABLES `xxxx` WRITE; 否则备份数据将无法导入到StoneDB。
+## 备份 StoneDB 注意事项
+StoneDB 不支持 lock tables 操作,所以需要在备份时加上 --skip-opt 或者 --skip-add-locks 参数,去除备份文件中的 LOCK TABLES `xxxx` WRITE, 否则备份数据将无法导入到 StoneDB。
## 使用示例
### 备份
#### 创建备份库表和测试数据
```bash
-# /stonedb56/install/bin/mysql -uroot -p***** -P3306
-mysql: [Warning] Using a password on the command line interface can be insecure.
-Welcome to the MySQL monitor. Commands end with ; or \g.
-Your MySQL connection id is 878
-Server version: 5.7.36-StoneDB-log build-
-Copyright (c) 2000, 2022 StoneAtom Group Holding Limited
-No entry for terminal type "xterm";
-using dumb terminal settings.
-Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database dumpdb;
Query OK, 1 row affected (0.00 sec)
+
mysql> show databases;
+--------------------+
| Database |
@@ -377,13 +33,17 @@ mysql> show databases;
| test |
+--------------------+
8 rows in set (0.00 sec)
+
mysql> use dumpdb
Database changed
+
mysql> create table dumptb(id int primary key,vname varchar(20))engine=StoneDB;
Query OK, 0 rows affected (0.00 sec)
+
mysql> insert into dumpdb.dumptb(id,vname) values(1,'zhangsan'),(2,'lisi'),(3,'wangwu');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
+
mysql> select * from dumpdb.dumptb;
+----+----------+
| id | vname |
@@ -394,28 +54,14 @@ mysql> select * from dumpdb.dumptb;
+----+----------+
3 rows in set (0.01 sec)
```
-#### 使用mysqldump 备份指定库
+#### 使用 mysqldump 备份指定库
```bash
/stonedb56/install/bin/mysqldump -uroot -p***** -P3306 --skip-opt --master-data=2 --single-transaction --set-gtid-purged=off --databases dumpdb > /tmp/dumpdb.sql
```
-#### 备份指定库的表结构
-```
-/stonedb56/install/bin/mysqldump -uroot -p***** -P3306 -d --databases dumpdb > /tmp/dumpdb_table.sql
-```
-#### 备份指定库的表数据(不包含表结构)
-```
-/stonedb56/install/bin/mysqldump -uroot -p***** -P3306 --skip-opt --master-data=2 --single-transaction --set-gtid-purged=off -t dumpdb > /tmp/dumpdb_table.sql
-```
-#### 使用mysqldump 备份除系统库(mysql、performation_schema、information_schema)外其他库
+#### 使用 mysqldump 备份除系统库(mysql、performation_schema、information_schema)外其他库
```bash
-/stonedb56/install/bin/mysql -uroot -p****** -P3306 -e "show databases;" | grep -Ev "sys|performance_schema|information_schema|Database|test" | xargs /stonedb56/install/bin/mysqldump -uroot -p****** -P3306 --master-data=1 --skip-opt --databases > /tmp/ig_sysdb.sql
-```
-***扩展***
-使用Mysqldump 备份innodb 导入StoneDB 表小的可以基于上面的mysqldump 备份,大表建议单独备份表结构和数据备份文件,然后使用`sed -i 's/原字符串/新字符串/g' 文件` 命令修改备份文件中的引擎,例如:
-```
-sed -i 's/ENGINE=InnoDB/ENGINE=STONEDB/g' 文件
+/stonedb56/install/bin/mysql -uroot -p****** -P3306 -e "show databases;" | grep -Ev "sys|performance_schema|information_schema|Database|test" | xargs /stonedb57/install/bin/mysqldump -uroot -p****** -P3306 --master-data=1 --skip-opt --databases > /tmp/ig_sysdb.sql
```
-修改引擎后按照下面恢复方式导入到StoneDB。
### 恢复
#### 数据导入到StoneDB
```bash
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
index e4f8224fb..eaf8f0cdc 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-centos7-56
-sidebar_position: 5.12.1
+sidebar_position: 5.121
---
# CentOS 7 下编译 StoneDB for MySQL5.6
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
index 6d42c3fcc..ebd642c92 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-centos7-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-centos7-57
-sidebar_position: 5.12.2
+sidebar_position: 5.122
---
# CentOS 7 下编译 StoneDB for MySQL5.7
@@ -261,4 +261,6 @@ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'stonedb123';
```
-注:管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::info
+管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
index 92abe5d29..cb5acdbbf 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-redhat7-for-56
-sidebar_position: 5.13.1
+sidebar_position: 5.131
---
# RedHat 7 下编译 StoneDB for MySQL5.6
@@ -149,7 +149,7 @@ cd boost_1_66_0
boost 的安装路径可以根据实际情况指定,示例中的安装路径是 /usr/local/stonedb-boost。
:::info
-注:在编译过程中,除非有关键字 "error" 报错自动退出,否则出现关键字 "warning"、"failed"是正常的,安装 boost 大概需要25分钟左右。
+在编译过程中,除非有关键字 "error" 报错自动退出,否则出现关键字 "warning"、"failed"是正常的,安装 boost 大概需要25分钟左右。
:::
## 第四步:执行编译
StoneDB 现有 5.6 和 5.7 两个分支,下载的源码包默认是 5.7 分支。下载的源码包存放路径可根据实际情况指定,示例中的源码包存放路径是在根目录下,并且是切换为 5.6 分支的编译安装。
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
index f967a40b2..077f5708c 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-redhat7-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-redhat7-for-56
-sidebar_position: 5.13.2
+sidebar_position: 5.132
---
# RedHat 7 下编译 StoneDB for MySQL5.7
@@ -149,7 +149,7 @@ cd boost_1_66_0
boost 的安装路径可以根据实际情况指定,示例中的安装路径是 /usr/local/stonedb-boost。
:::info
-注:在编译过程中,除非有关键字 "error" 报错自动退出,否则出现关键字 "warning"、"failed"是正常的,安装 boost 大概需要25分钟左右。
+在编译过程中,除非有关键字 "error" 报错自动退出,否则出现关键字 "warning"、"failed"是正常的,安装 boost 大概需要25分钟左右。
:::
### 6. 安装 gtest
```shell
@@ -191,7 +191,9 @@ install_target=/stonedb57/install
###执行编译脚本
sh stonedb_build.sh
```
-注:如果是 CentOS/RedHat ,需要注释 os_dist 和 os_dist_release,并且修改 build_tag ,这是因为 "lsb_release -a" 返回的结果中,Distributor、Release、Codename 显示的是 n/a。注释 os_dist 和 os_dist_release 只会影响产生的日志名和 tar 包名,不会影响编译结果。
+:::info
+如果是 CentOS/RedHat ,需要注释 os_dist 和 os_dist_release,并且修改 build_tag ,这是因为 "lsb_release -a" 返回的结果中,Distributor、Release、Codename 显示的是 n/a。注释 os_dist 和 os_dist_release 只会影响产生的日志名和 tar 包名,不会影响编译结果。
+:::
## 第五步:启动实例
用户可按照手动安装和自动安装两种方式启动 StoneDB。
### 1. 创建用户
@@ -259,4 +261,6 @@ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'stonedb123';
```
-注:管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::info
+管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
index 5c79ebd8b..abbc3f405 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-56.md
@@ -1,6 +1,6 @@
---
id: compile-using-ubuntu20.04-for-56
-sidebar_position: 5.14.1
+sidebar_position: 5.141
---
# Ubuntu 20.04 下编译 StoneDB for MySQL5.6
@@ -58,8 +58,9 @@ sudo apt install -y libjemalloc-dev
sudo apt install -y libssl-dev
sudo apt install -y pkg-config
```
-注:依赖包必须都装上,否则后面有很多报错。
-
+:::info
+依赖包必须都装上,否则后面有很多报错。
+:::
## 第二步:安装第三方库
安装第三库前需要确认 cmake 版本是3.7.2以上,make 版本是3.82以上,如果低于这两个版本,需要进行安装。StoneDB 依赖 marisa、rocksdb、boost,在编译 marisa、rocksdb、boost 时,建议指定安装路径。示例中我们指定了 marisa、rocksdb、boost 的安装路径。
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
index 6a249f8a9..a69edcfbf 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/04-developer-guide/00-compiling-methods/compile-using-ubuntu2004-for-57.md
@@ -1,6 +1,6 @@
---
id: compile-using-ubuntu20.04-for-56
-sidebar_position: 5.14.2
+sidebar_position: 5.142
---
# Ubuntu 20.04 下编译 StoneDB for MySQL5.7
@@ -57,7 +57,9 @@ sudo apt install -y libjemalloc-dev
sudo apt install -y libssl-dev
sudo apt install -y pkg-config
```
-注:依赖包必须都装上,否则后面有很多报错。
+:::info
+依赖包必须都装上,否则后面有很多报错。
+:::
## 第二步:安装第三方库
安装第三库前需要确认 cmake 版本是3.7.2以上,make 版本是3.82以上,如果低于这两个版本,需要进行安装。StoneDB 依赖 marisa、rocksdb、boost,在编译 marisa、rocksdb、boost 时,建议指定安装路径。示例中我们指定了 marisa、rocksdb、boost 的安装路径。
### 1. 安装 cmake
@@ -250,4 +252,6 @@ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'stonedb123';
```
-注:管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::info
+管理员用户的临时密码在 mysqld.log 中,第一次登陆后需要修改管理员用户的密码。
+:::
\ No newline at end of file
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/advanced-functions.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/advanced-functions.md
index 455192f32..00e45c59a 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/advanced-functions.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/advanced-functions.md
@@ -5,22 +5,22 @@ sidebar_position: 6.44
# 高级函数
-| **Function** | **Description** | **Example** |
-| --- | --- | :-- |
-| BIN(x) | Returns the binary string equivalent to _x_. | SELECT BIN(28);
->11100 |
-| BINARY(s) | Converts string _s_ to a binary string. | SELECT BINARY('STONEDB');
-> STONEDB |
-| CASE expression
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
WHEN conditionN THEN resultN
ELSE result
END | **CASE** specifies the start of the function and **END** specifies the end of the function.
If _condition1_ is met, _result1_ is returned. If _condition2_ is met, _result2_ is returned. If all conditions are not met, _result_ is returned.
This function stops checking subsequent conditions immediately after a condition is met and returns the corresponding result. | SELECT CASE
WHEN 1>0
THEN '1 > 0'
WHEN 2>0
THEN '2 > 0'
ELSE '3 > 0'
END;
->1>0 |
-| CAST(x AS type) | Converts the data type of _x_. | SELECT CAST('2022-06-11' AS DATE);
->2022-06-11 |
-| COALESCE(expr1, expr2, ...., expr_n) | Returns the first non-null value in the specified list. | SELECT COALESCE(NULL, NULL,'CHINA', NULL, NULL,'STONEDB');
->CHINA |
-| CONNECTION_ID() | Returns the ID of the current connection. | SELECT CONNECTION_ID();
->5 |
-| CONV(x,f1,f2) | Converts _x_ from base _f1_ to_ f2_. | SELECT CONV(28,10,16);
->1C |
-| CONVERT(s USING cs) | Changes the character set of string _s_ to character set _cs_. | SELECT CHARSET('ABC');
->utf8
SELECT CHARSET(CONVERT('ABC' USING gbk));
->gbk |
-| CURRENT_USER() | Returns the current user. | SELECT CURRENT_USER();
->root@localhost |
-| DATABASE() | Returns the name of the current database. | SELECT DATABASE();
->test |
-| IF(expr,v1,v2) | Returns value _v1_ if expression _expr_ is true or value _v2_ if expression _expr_ is false. | SELECT IF(1>10,'true','false') ;
->false |
-| IFNULL(v1,v2) | Returns value _v1_ if value _v1_ is not **null**. Otherwise, value _v2_ is returned. | SELECT IFNULL(null,'Hello Word');
->HelloWord |
-| ISNULL(expression) | Checks whether _expression_ is **NULL**. | SELECT ISNULL(NULL);
->1 |
-| LAST_INSERT_ID() | Returns the last AUTO_INCREMENT value. | SELECT LAST_INSERT_ID();
->0 |
-| NULLIF(expr1, expr2) | Compares two strings _expr1_ and _expr2_.
If they are the same, **NULL** is returned. Otherwise, _expr1_ is returned. | SELECT NULLIF(25,25);
->NULL |
-| SESSION_USER()
SYSTEM_USER()
USER() | Returns the current user. | SELECT SESSION_USER();
->root@localhost |
-| VERSION() | Returns the version number of the database. | SELECT VERSION();
->5.6.24-StoneDB-log |
\ No newline at end of file
+| **函数名** | **描述** | **示例** |
+| --- | --- | --- |
+| BIN(x) | 返回 x 的二进制编码 | SELECT BIN(28);
->11100 |
+| BINARY(s) | 将字符串 s 转换为二进制字符串 | SELECT BINARY('STONEDB');
-> STONEDB |
+| CASE expression
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
WHEN conditionN THEN resultN
ELSE result
END | CASE 表示函数开始,END 表示函数结束。如果 condition1 成立,则返回 result1, 如果 condition2 成立,则返回 result2,当全部不成立则返回 result,而当有一个成立之后,后面的就不执行了 | SELECT CASE
WHEN 1>0
THEN '1 > 0'
WHEN 2>0
THEN '2 > 0'
ELSE '3 > 0'
END;
->1>0 |
+| CAST(x AS type) | 转换数据类型 | SELECT CAST('2022-06-11' AS DATE);
->2022-06-11 |
+| COALESCE(expr1, expr2, ...., expr_n) | 返回参数中的第一个非空表达式(从左向右) | SELECT COALESCE(NULL, NULL,'CHINA', NULL, NULL,'STONEDB');
->CHINA |
+| CONNECTION_ID() | 返回当前线程 ID | SELECT CONNECTION_ID();
->5 |
+| CONV(x,f1,f2) | 返回 f1 进制数变成 f2 进制数 | SELECT CONV(28,10,16);
->1C |
+| CONVERT(s USING cs) | 函数将字符串 s 的字符集变成 cs | SELECT CHARSET('ABC');
->utf8
SELECT CHARSET(CONVERT('ABC' USING gbk));
->gbk |
+| CURRENT_USER() | 返回当前用户 | SELECT CURRENT_USER();
->root@localhost |
+| DATABASE() | 返回当前数据库名 | SELECT DATABASE();
->test |
+| IF(expr,v1,v2) | 如果表达式 expr 成立,返回结果 v1;否则返回结果 v2 | SELECT IF(1>10,'true','false') ;
->false |
+| IFNULL(v1,v2) | 如果 v1 的值不为 NULL,则返回 v1,否则返回 v2 | SELECT IFNULL(null,'Hello Word');
->HelloWord |
+| ISNULL(expression) | 判断表达式是否为 NULL | SELECT ISNULL(NULL);
->1 |
+| LAST_INSERT_ID() | 返回最近生成的 AUTO_INCREMENT 值 | SELECT LAST_INSERT_ID();
->0 |
+| NULLIF(expr1, expr2) | 比较两个字符串,如果字符串 expr1 与 expr2 相等,返回 NULL,否则返回 expr1 | SELECT NULLIF(25,25);
->NULL |
+| SESSION_USER()
SYSTEM_USER()
USER()| 返回当前用户 | SELECT SESSION_USER();
->root@localhost |
+| VERSION() | 返回数据库的版本号 | SELECT VERSION();
->5.6.24-StoneDB-log |
\ No newline at end of file
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/date-and-time-functions.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/date-and-time-functions.md
index a35153e5d..9c7302177 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/date-and-time-functions.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/date-and-time-functions.md
@@ -5,50 +5,49 @@ sidebar_position: 6.41
# 日期与时间函数
-| **Function** | **Description** | **Example** |
+| **函数名** | **描述** | **示例** |
| --- | --- | --- |
-| ADDDATE(d,n) | Adds time value (interval) _n_ to date _d_. | SELECT ADDDATE('2022-06-10', INTERVAL 5 DAY);
->2022-06-15 |
-| ADDTIME(t,n) | Adds time _n_ to time _t_. | SELECT ADDTIME('2022-06-10 10:00:00',5);
->2022-06-10 10:00:05 |
-| CURDATE()
CURRENT_DATE() | Returns the current date. | SELECT CURDATE();
->2022-06-10 |
-| CURRENT_TIME
CURTIME() | Returns the current time. | SELECT CURRENT_TIME();
->17:10:31 |
-| CURRENT_TIMESTAMP()
LOCALTIME()
LOCALTIMESTAMP()
NOW()
SYSDATE() | Returns the current date and time. | SELECT CURRENT_TIMESTAMP();
->2022-06-10 17:11:06 |
-| DATE() | Extracts the date part of a date or datetime expression. | SELECT DATE('2022-06-10');
->2022-06-10 |
-| DATEDIFF(d1,d2) | Subtracts two dates. _d1_ and _d2_ each specify a date. | SELECT DATEDIFF('2022-06-10','2021-06-10');
->365 |
-| DATE_ADD(d,INTERVAL expr type) | Add time values (intervals) to date _d_.
_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT DATE_ADD('2022-06-10 17:17:21', INTERVAL -3 HOUR);
->2022-06-10 14:17:21 |
-| DATE_FORMAT(d,f) | Formats date _d_ based on expression _f_. | SELECT DATE_FORMAT('2022-06-10 17:21:11','%Y-%m-%d %r');
->2022-06-10 05:21:11 PM |
-| DATE_SUB(date,INTERVAL expr type) | Subtracts a time value (interval) from date _date_.
_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT DATE_SUB(
CURRENT_DATE(),INTERVAL 2 DAY);
->2022-06-08 |
-| DAY(d) | Returns the day in date _d_. | SELECT DAY('2022-06-10');
->10 |
-| DAYNAME(d) | Returns the name of the weekday from date** **_d_, for example, **Monday**. | SELECT DAYNAME('2022-06-10 17:30:30');
->Friday |
-| DAYOFMONTH(d) | Returns the day of the month from date _d_. | SELECT DAYOFMONTH('2022-06-10 17:31:11');
->10 |
-| DAYOFWEEK(d) | Returns the weekday index from date _d_.
The return value ranges from 1 to 7 and value 1 indicates Sunday. | SELECT DAYOFWEEK('2022-06-10 17:35:11');
->6 |
-| DAYOFYEAR(d) | Returns the day of the year from date _d_. | SELECT DAYOFYEAR('2022-06-10 18:02:11');
->161 |
-| EXTRACT(type FROM d) | Extracts part of date _d_.
_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT EXTRACT(MONTH FROM '2022-06-10 18:02:33') ;
->6 |
-| HOUR(t) | Extracts the hour from time _t_. | SELECT HOUR('18:06:31');
->18 |
-| LAST_DAY(d) | Returns the last day of the month from date _d_. | SELECT LAST_DAY("2022-06-10");
->2022-06-30 |
-| MAKEDATE(year, day-of-year) | Creates a date based on the given year and day of year.
_year_ specifies the year. _day-of-year_ specifies the day of year. | SELECT MAKEDATE(2022,161);
->2022-06-10 |
-| MAKETIME(hour, minute, second) | Creates time based on the given hour, minute, and second. | SELECT MAKETIME(11,35,4);
->11:35:04 |
-| MICROSECOND(date) | Returns the microseconds from date _date_. | SELECT MICROSECOND('2022-06-10 18:12:00.000023');
->23 |
-| MINUTE(t) | Returns the minute from time _t_. | SELECT MINUTE('18:12:31');
->12 |
-| MONTHNAME(d) | Returns the name of the month from date _d_, such as **November**. | SELECT MONTHNAME('2022-06-10 18:13:19');
->June |
-| MONTH(d) | Returns the month from date _d_.
The return value ranges from 1 to 12. | SELECT MONTH('2022-06-10 18:14:11');
->6 |
-| PERIOD_ADD(period, number) | Adds a period (expressed in months) to a year-month.
_period_ specifies the year-month. _number_ specifies the period to add. | SELECT PERIOD_ADD(202206,5);
->202211 |
-| PERIOD_DIFF(period1, period2) | Returns the number of months between periods. | SELECT PERIOD_DIFF(202204,202012);
->16 |
-| QUARTER(d) | Returns the quarter from date _d_.
The return value ranges from 1 to 4. | SELECT QUARTER('2022-06-10 18:16:29');
->2 |
-| SECOND(t) | Returns the second from time _t_. | SELECT SECOND('18:17:36');
->36 |
-| SEC_TO_TIME(s) | Converts time _s_ which is expressed in seconds to the hh:mm:ss format. | SELECT SEC_TO_TIME(4320);
->01:12:00 |
-| STR_TO_DATE(string, format_mask) | Converts a string to a date. | SELECT STR_TO_DATE('June 10 2022','%M %d %Y');
->2022-06-10 |
-| SUBDATE(d,n) | Subtracts interval _n_ from date _d_. | SELECT SUBDATE('2022-06-10 18:19:27',15);
->2022-05-26 18:19:27 |
-| SUBTIME(t,n) | Subtracts period_ n_ from time _t_. n is expressed in seconds. | SELECT SUBTIME('2022-06-10 18:21:11',5);
->2022-06-10 18:21:06 |
-| TIME(expression) | Extracts the time portion of an expression. | SELECT TIME('18:22:10');
->18:22:10 |
-| TIME_FORMAT(t,f) | Formats time _t_ based on expression _f_. | SELECT TIME_FORMAT('18:22:59','%r');
->06:22:59 PM |
-| TIME_TO_SEC(t) | Converts time _t_ to seconds. | SELECT TIME_TO_SEC('18:24:00');
->66240 |
-| TIMEDIFF(time1, time2) | Subtracts two points in time.
_time1_ and _time2_ each specify a point in time. | SELECT TIMEDIFF('18:24:11','13:10:10');
->05:14:01 |
-| TIMESTAMP(expression, interval) | With a single argument, this function returns the date or datetime expression. With two arguments, this function returns the sum of the arguments. | SELECT TIMESTAMP('2022-06-10', '18:25:17');
->2022-06-10 18:25:17 |
-| TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) | Subtracts two datetime expressions.
_datetime_expr1_ and _datetime_expr2_ each specify a datetime expression. _unit_ specifies the unit of the return value. |
1. SELECT TIMESTAMPDIFF(DAY,'2020-12-23','2022-04-02');
->465
2. SELECT TIMESTAMPDIFF(MONTH,'2020-12-23','2022-04-02');
->15
|
-| TO_DAYS(d) | Converts date _d_ to the number of days since date 0000-01-01. | SELECT TO_DAYS('2022-06-10 00:00:00');
->738681 |
-| WEEK(d) | Returns the week number of date_ d_.
The return value ranges from 0 to 53. | SELECT WEEK('2022-06-10 00:00:00');
->23 |
-| WEEKDAY(d) | Returns the weekday index of date _d_.
For example, return value **0** indicates Monday and **1** indicates Tuesday. | SELECT WEEKDAY('2022-06-10');
->4 |
-| WEEKOFYEAR(d) | Returns the calendar week of date _d_.
The return value ranges from 0 to 53. | SELECT WEEKOFYEAR('2022-06-10 11:11:11');
->23 |
-| YEAR(d) | Returns the year of date _d_. | SELECT YEAR('2022-06-10');
->2022 |
-| YEARWEEK(date, mode) | Returns the year and week number (value range: 0 to 53).
_mode_ is optional and specifies what day a week starts on. For example, return value **0** indicates Sunday and **1** indicates Monday. | SELECT YEARWEEK('2022-06-10');
->202223 |
-
+| ADDDATE(d,n) | 计算起始日期 d 加上 n 天的日期 | SELECT ADDDATE('2022-06-10', INTERVAL 5 DAY);
->2022-06-15 |
+| ADDTIME(t,n) | n 是一个时间表达式,时间 t 加上时间表达式 n | SELECT ADDTIME('2022-06-10 10:00:00',5);
->2022-06-10 10:00:05 |
+| CURDATE()
CURRENT_DATE() | 返回当前日期 | SELECT CURDATE();
->2022-06-10 |
+| CURRENT_TIME
CURTIME() | 返回当前时间 | SELECT CURRENT_TIME();
->17:10:31 |
+| CURRENT_TIMESTAMP()
LOCALTIME()
LOCALTIMESTAMP()
NOW()
SYSDATE() | 返回当前日期和时间 | SELECT CURRENT_TIMESTAMP();
->2022-06-10 17:11:06 |
+| DATE() | 从日期或日期时间表达式中提取日期值 | SELECT DATE('2022-06-10');
->2022-06-10 |
+| DATEDIFF(d1,d2) | 计算日期 d1 与 d2 之间相隔的天数 | SELECT DATEDIFF('2022-06-10','2021-06-10');
->365 |
+| DATE_ADD(d,INTERVAL expr type) | 计算起始日期 d 加上一个时间段后的日期,type 可以是second、minute、hour、day、week、month、year 等 | SELECT DATE_ADD('2022-06-10 17:17:21', INTERVAL -3 HOUR);
->2022-06-10 14:17:21 |
+| DATE_FORMAT(d,f) | 按表达式 f 的要求显示日期 d | SELECT DATE_FORMAT('2022-06-10 17:21:11','%Y-%m-%d %r');
->2022-06-10 05:21:11 PM |
+| DATE_SUB(date,INTERVAL expr type) | 函数从日期减去指定的时间间隔 | SELECT DATE_SUB(
CURRENT_DATE(),INTERVAL 2 DAY);
->2022-06-08 |
+| DAY(d) | 返回日期值 d 的日期部分 | SELECT DAY('2022-06-10');
->10 |
+| DAYNAME(d) | 返回日期 d 是星期几,如 Monday,Tuesday | SELECT DAYNAME('2022-06-10 17:30:30');
->Friday |
+| DAYOFMONTH(d) | 计算日期 d 是本月的第几天 | SELECT DAYOFMONTH('2022-06-10 17:31:11');
->10 |
+| DAYOFWEEK(d) | 计算日期 d 是星期几,1 表示星期日,2 表示星期一,以此类推 | SELECT DAYOFWEEK('2022-06-10 17:35:11');
->6 |
+| DAYOFYEAR(d) | 计算日期 d 是本年的第几天 | SELECT DAYOFYEAR('2022-06-10 18:02:11');
->161 |
+| EXTRACT(type FROM d) | 从日期 d 中获取指定的值,type 指定返回的值。type 可以是second、minute、hour、day、week、month、year 等 | SELECT EXTRACT(MONTH FROM '2022-06-10 18:02:33') ;
->6 |
+| HOUR(t) | 返回 t 中的小时值 | SELECT HOUR('18:06:31');
->18 |
+| LAST_DAY(d) | 返回给定日期的月份的最后一天 | SELECT LAST_DAY("2022-06-10");
->2022-06-30 |
+| MAKEDATE(year, day-of-year) | 返回给定参数年份 year 和所在年中的天数序号,返回的是一个日期 | SELECT MAKEDATE(2022,161);
->2022-06-10 |
+| MAKETIME(hour, minute, second) | 组合时间,参数分别为小时、分钟、秒 | SELECT MAKETIME(11,35,4);
->11:35:04 |
+| MICROSECOND(date) | 返回日期参数所对应的微秒数 | SELECT MICROSECOND('2022-06-10 18:12:00.000023');
->23 |
+| MINUTE(t) | 返回 t 中的分钟值 | SELECT MINUTE('18:12:31');
->12 |
+| MONTHNAME(d) | 返回日期当中的月份,如 November | SELECT MONTHNAME('2022-06-10 18:13:19');
->June |
+| MONTH(d) | 返回日期 d 中的月份值 | SELECT MONTH('2022-06-10 18:14:11');
->6 |
+| PERIOD_ADD(period, number) | 给 年-月 组合日期添加一个时段 | SELECT PERIOD_ADD(202206,5);
->202211 |
+| PERIOD_DIFF(period1, period2) | 返回两个时段之间的月份差值 | SELECT PERIOD_DIFF(202204,202012);
->16 |
+| QUARTER(d) | 返回日期 d 是第几季节 | SELECT QUARTER('2022-06-10 18:16:29');
->2 |
+| SECOND(t) | 返回 t 中的秒钟值 | SELECT SECOND('18:17:36');
->36 |
+| SEC_TO_TIME(s) | 以秒为单位的时间 s 转换为时分秒的格式 | SELECT SEC_TO_TIME(4320);
->01:12:00 |
+| STR_TO_DATE(string, format_mask) | 将字符串转变为日期 | SELECT STR_TO_DATE('June 10 2022','%M %d %Y');
->2022-06-10 |
+| SUBDATE(d,n) | 日期 d 减去 n 天后的日期 | SELECT SUBDATE('2022-06-10 18:19:27',15);
->2022-05-26 18:19:27 |
+| SUBTIME(t,n) | 时间 t 减去 n 秒的时间 | SELECT SUBTIME('2022-06-10 18:21:11',5);
->2022-06-10 18:21:06 |
+| TIME(expression) | 提取传入表达式的时间部分 | SELECT TIME('18:22:10');
->18:22:10 |
+| TIME_FORMAT(t,f) | 按表达式 f 的要求显示时间 t | SELECT TIME_FORMAT('18:22:59','%r');
06:22:59 PM |
+| TIME_TO_SEC(t) | 将时间 t 转换为秒 | SELECT TIME_TO_SEC('18:24:00');
->66240 |
+| TIMEDIFF(time1, time2) | 计算时间差值 | SELECT TIMEDIFF('18:24:11','13:10:10');
->05:14:01 |
+| TIMESTAMP(expression, interval) | 单个参数时,返回日期时间表达式,2个参数时,返回日期时间表达式和参数 | SELECT TIMESTAMP('2022-06-10', '18:25:17');
->2022-06-10 18:25:17 |
+| TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) | 计算时间差,返回 datetime_expr2 − datetime_expr1 的时间差 | SELECT TIMESTAMPDIFF(DAY,'2020-12-23','2022-04-02');
->465
SELECT TIMESTAMPDIFF(MONTH,'2020-12-23','2022-04-02');
->15 |
+| TO_DAYS(d) | 计算日期 d 距离 0000 年 1 月 1 日的天数 | SELECT TO_DAYS('2022-06-10 00:00:00');
->738681 |
+| WEEK(d) | 计算日期 d 是本年的第几个星期,范围是 0 到 53 | SELECT WEEK('2022-06-10 00:00:00');
->23 |
+| WEEKDAY(d) | 日期 d 是星期几,0 表示星期一,1 表示星期二 | SELECT WEEKDAY('2022-06-10');
->4 |
+| WEEKOFYEAR(d) | 计算日期 d 是本年的第几个星期,范围是 0 到 53 | SELECT WEEKOFYEAR('2022-06-10 11:11:11');
->23 |
+| YEAR(d) | 返回年份 | SELECT YEAR('2022-06-10');
->2022 |
+| YEARWEEK(date, mode) | 返回年份及第几周(0到53),mode 中 0 表示周日,1 表示周一,以此类推 | SELECT YEARWEEK('2022-06-10');
->202223 |
\ No newline at end of file
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/mathematical-functions.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/mathematical-functions.md
index be62e86ab..c384dfe96 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/mathematical-functions.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/mathematical-functions.md
@@ -5,33 +5,45 @@ sidebar_position: 6.43
# 数学函数
-| **Function** | **Description** | **Example** |
+| **函数名** | **描述** | **示例** |
| --- | --- | --- |
-| ABS(x) | Returns the absolute value. | SELECT ABS(-1);
->1 |
-| ACOS(x) | Returns the arc cosine of numeral value _x_. | SELECT ACOS(0.5);
->1.0471975511965979 |
-| ASIN(x) | Returns the arc sine of numeral value _x_. | SELECT ASIN(0.5);
->0.5235987755982989 |
-| ATAN(x) | Returns the arc tangent of numeral value _x_. | SELECT ATAN(2.5);
->1.1902899496825317 |
-| ATAN2(n, m) | Returns the arc tangent of two numeral values. | SELECT ATAN2(1,2);
->0.4636476090008061 |
-| COS(x) | Returns the cosine of radian _x_. | SELECT COS(2);
->-0.4161468365471424 |
-| COT(x) | Returns the cotangent of radian _x_. | SELECT COT(2);
->-0.45765755436028577 |
-| TAN(x) | Returns the tangent of radian _x_. | SELECT TAN(45);
->1.6197751905438615 |
-| SIN(x) | Returns the sine of radian _x_. | SELECT SIN(RADIANS(30));
->0.49999999999999994 |
-| CEIL(x)
CEILING(x) | Returns the smallest integer value that is not smaller than _x_. | SELECT CEIL(4.19);
->5 |
-| DEGREES(x) | Converts radian _x_ to a degree. | SELECT DEGREES(3.1415926535898);
->180.0000000000004 |
-| EXP(x) | Returns the natural exponential of _x_. | SELECT EXP(2);
->7.38905609893065 |
-| FLOOR(x) | Returns the largest integer value that is not greater than _x_. | SELECT FLOOR(3.24);
->3 |
-| GREATEST(expr1, expr2, expr3, ...) | Returns the greatest value within the specified list. | SELECT GREATEST(79,36,3,8,1);
->79
SELECT GREATEST('Hello','CHINA','STONEDB');
->STONEDB |
-| LEAST(expr1, expr2, expr3, ...) | Returns the smallest value within the specified list. | SELECT LEAST(79,36,3,8,1);
->1
SELECT LEAST('Hello','CHINA','STONEDB');
->CHINA |
-| LN(x) | Returns the natural logarithm of _x_. | SELECT LN(3);
->1.0986122886681098 |
-| LOG(x,y) | Returns the base-x logarithm of_ y_. | SELECT LOG(3,81);
->4 |
-| LOG2(x) | Returns the base-2 logarithm of_ x_. | SELECT LOG2(64);
->6 |
-| PI() | Returns the value of pi. | SELECT PI();
->3.141593 |
-| POW(x,y),
POWER(x,y) | Returns _x_ raised to the specified power of _y_. | SELECT POW(2,4);
->16 |
-| RAND() | Returns a random number between 0 and 1. | SELECT RAND();
->0.12216221831940322 |
-| ROUND(x) | Returns the value of _x_ rounded to the nearest integer. | SELECT ROUND(-5.26);
->-5 |
-| SIGN(x) | Returns the sign of _x_.
- If _x_ is a negative value, **-1** is returned.
- If_ x_ is 0, **0** is returned.
- If _x_ is a positive value, **1** is returned.
| SELECT SIGN(-10);
->(-1) |
-| SQRT(x) | Returns the square root of _x_. | SELECT SQRT(81);
->9 |
-| TRUNCATE(x,y) | Truncates _x_ to retain _y_ decimal places. | SELECT TRUNCATE(2.2849106,3);
->2.284 |
+| ABS(x) | 求绝对值 | SELECT ABS(-1);
->1 |
+| | |
+| ASIN(x) | 求反正弦值(单位为弧度),x 为一个数值 | SELECT ASIN(0.5);
->0.5235987755982989 |
+| | |
+| ATAN2(n, m) | 求反正切值(单位为弧度) | SELECT ATAN2(1,2);
->0.4636476090008061 |
+| COS(x) | 求余弦值(参数是弧度) | SELECT COS(2);
->-0.4161468365471424 |
+| COT(x) | 求余切值(参数是弧度) | SELECT COT(2);
->-0.45765755436028577 |
+| TAN(x) | 求正切值(参数是弧度) | SELECT TAN(45);
->1.6197751905438615 |
+| SIN(x) | 求正弦值(参数是弧度) | SELECT SIN(RADIANS(30));
->0.49999999999999994 |
+| CEIL(x)
CEILING(x) | 返回大于或等于 x 的最小整数 | SELECT CEIL(4.19);
->5 |
+| DEGREES(x) | 将弧度转换为角度 | SELECT DEGREES(3.1415926535898);
->180.0000000000004 |
+| EXP(x) | 返回 e 的 x 次方 | SELECT EXP(2);
->7.38905609893065 |
+| FLOOR(x) | 返回小于或等于 x 的最大整数 | SELECT FLOOR(3.24);
->3 |
+| GREATEST(expr1, expr2, expr3, ...) | 返回列表中的最大值 | SELECT GREATEST(79,36,3,8,1);
->79 |
+| | |
+| LEAST(expr1, expr2, expr3, ...) | 返回列表中的最小值 | SELECT LEAST(79,36,3,8,1);
->1 |
+| | |
+| LN | 返回数字的自然对数,以 e 为底 | SELECT LN(3);
->1.0986122886681098 |
+| LOG(x,y) | 返回以 x 为低的对数 | SELECT LOG(3,81);
->4 |
+| LOG2(x) | 返回以 2 为底的对数 | SELECT LOG2(64);
->6 |
+| | |
+| PI() | 返回圆周率 | SELECT PI();
->3.141593 |
+| POW(x,y)
POWER(x,y) | 返回 x 的 y 次方 | SELECT POW(2,4);
->16 |
+| RAND() | 返回 0 到 1 的随机数 | SELECT RAND();
->0.12216221831940322 |
+| ROUND(x) | 返回离 x 最近的整数 | SELECT ROUND(-5.26);
->-5 |
+| | |
+| SQRT(x) | 返回 x 的平方根 | SELECT SQRT(81);
->9 |
+| TRUNCATE(x,y) | 返回数值 x 保留到小数点后 y 位的值,与 ROUND 最大的区别是不会进行四舍五入 | SELECT TRUNCATE(2.2849106,3);
->2.284 |
+| | |
+| ABS(x) | 求绝对值 | SELECT ABS(-1);
->1 |
+| | |
+| ASIN(x) | 求反正弦值(单位为弧度),x 为一个数值 | SELECT ASIN(0.5);
->0.5235987755982989 |
+| ATAN(x) | 求反正切值(单位为弧度),x 为一个数值 | SELECT ATAN(2.5);
->1.1902899496825317 |
+| ATAN2(n, m) | 求反正切值(单位为弧度) | SELECT ATAN2(1,2);
->0.4636476090008061 |
+| COS(x) | 求余弦值(参数是弧度) | SELECT COS(2);
->-0.4161468365471424 |
+| | |
+| TAN(x) | 求正切值(参数是弧度) | SELECT TAN(45);
->1.6197751905438615 |
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/string-functions.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/string-functions.md
index 7eaea7b3b..f5262ae53 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/string-functions.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/05-SQL-reference/04-functions/string-functions.md
@@ -4,32 +4,31 @@ sidebar_position: 6.42
---
# 字符串函数
-
-| **Function** | **Description** | **Example** |
+| **函数** | **描述** | **示例** |
| --- | --- | --- |
-| ASCII(s) | Returns the numeric value of the leftmost character of string _s_. | select ASCII('CHINA');
->67 |
-| CHAR_LENGTH(s)
CHARACTER_LENGTH(s) | Returns the number of characters in string _s_. | SELECT CHAR_LENGTH('CHINA');
->5 |
-| CONCAT(s1,s2...sn)
CONCAT_WS(x, s1,s2...sn) | Concatenates strings _s1_, _s2_, … _Sn_. | SELECT CONCAT('Welcome to ','CHINA');
->Welcome to CHINA |
-| FIELD(s,s1,s2...) | Returns the index of the first string _s_ in the list of subsequent strings (_s1_, _s2_, …). | SELECT FIELD("c","a","b","c","d","e");
->3 |
-| FIND_IN_SET(s1,s2) | Returns the index of the first string _s1_ within the second string _s2_. | SELECT FIND_IN_SET("c","a,b,c,d,e");
->3 |
-| FORMAT(x,n) | Returns a number formatted to _n_ decimal places.
_x_ specifies the number to format. The return value is in the #,###.## format. | SELECT FORMAT(9105885500.534,2);
->9,105,885,500.53 |
-| INSERT(s1,x,len,s2) | Inserts substring _s2_ at a given position up to the specified number of characters in string _s1_.
_x_ specifies position to insert. _len_ specifies the number of characters. | SELECT INSERT('Welcome to CHINA',1,6,'I love');
->I lovee to CHINA |
-| LOCATE(s1,s) | Returns the position of the first occurrence of substring s1 in string s. | SELECT LOCATE('db','stonedb');
->6 |
-| LCASE(s)
LOWER(s) | Returns every character in string _s_ in lowercase. | SELECT LCASE('STONEDB');
->stonedb |
-| LEFT(s,n) | Returns the leftmost n characters in string_ s_. | SELECT LEFT('stonedb',5);
->stone |
-| LPAD(s1,len,s2) | Left-pads string _s2_ with string _s1_ to the specified length _len_. | SELECT LPAD('one',5,'st');
->stone |
-| LTRIM(s) | Remove leading spaces in string _s_. | SELECT LTRIM(' STONEDB');
->STONEDB |
-| MID(s,n,len) | Returns a substring of string s starting from a given position.
_n_ specifies the position. _len_ specifies the length of the substring. This function is the Synonym for SUBSTRING(s,n,len). | SELECT MID('stonedb',2,3);
->ton |
-| POSITION(s1 IN s) | Returns the position of the first occurrence of substring _s1_ in string _s_. | SELECT POSITION('db'in'stonedb');
->6 |
-| REPEAT(s,n) | Repeats string _s_ for _n_ times. | SELECT REPEAT('hello',3);
->hellohellohello |
-| REPLACE(s,s1,s2) | Replaces substring _s1_ in string _s_ with substring _s2_. | SELECT REPLACE('stonedb','db','x');
->stonex |
-| REVERSE(s) | Reverses the characters in string _s_. | SELECT REVERSE('stonedb');
->bdenots |
-| RIGHT(s,n) | Returns _n_ rightmost characters in string _s_. | SELECT RIGHT('stonedb',5);
->onedb |
-| RPAD(s1,len,s2) | Right-pads string _s2_ to string _s1_ to the specified length _len_. | SELECT RPAD('stone',7,'db');
->stonedb |
-| RTRIM(s) | Remove trailing spaces in string _s_. | SELECT RTRIM('STONEDB ');
->STONEDB |
-| SPACE(n) | Returns _n_ spaces. | SELECT SPACE(10);
-> |
-| STRCMP(s1,s2) | Compares the lengths of strings _s1_ and_ s2_.
- If _s1_ = _s2_, **0** is returned.
- If _s1_ > _s2_, **1** is returned.
- If _s1_ < _s2_, **-1** is returned.
| SELECT STRCMP('stonedb','stone');
->1 |
-| SUBSTR(s, start, length) | Returns a substring of the specified length within string _s_.
_start_ specifies the position from which the substring starts. | SELECT SUBSTR('STONEDB',2,3);
->TON |
-| SUBSTRING_INDEX(s, delimiter, number) | Returns a substring from string _s_ before the specified number of occurrences of the delimiter. | SELECT SUBSTRING_INDEX('stonedb','n',1);
->sto |
-| TRIM(s) | Removes leading and trailing spaces in string _s_. | SELECT TRIM(' STONEDB ');
->STONEDB |
-| UCASE(s)
UPPER(s) | Returns every character in string _s_ in uppercase. | SELECT UCASE('stonedb');
->STONEDB |
+| ASCII(s) | 返回字符串 s 的第一个字符的 ASCII 码 | select ASCII('CHINA');
->67 |
+| CHAR_LENGTH(s)
CHARACTER_LENGTH(s) | 返回字符串 s 的字符数 | SELECT CHAR_LENGTH('CHINA');
->5 |
+| CONCAT(s1,s2...sn)
CONCAT_WS(x, s1,s2...sn) | 字符串 s1,s2 等多个字符串合并为一个字符串 | SELECT CONCAT('Welcome to ','CHINA');
->Welcome to CHINA |
+| FIELD(s,s1,s2...) | 返回第一个字符串 s 在字符串列表(s1,s2...)中的位置 | SELECT FIELD("c","a","b","c","d","e");
->3 |
+| FIND_IN_SET(s1,s2) | 返回在字符串 s2 中与 s1 匹配的字符串的位置 | SELECT FIND_IN_SET("c","a,b,c,d,e");
->3 |
+| FORMAT(x,n) | 函数可以将数字 x 进行格式化 "#,###.##", 将 x 保留到小数点后 n 位,最后一位四舍五入 | SELECT FORMAT(9105885500.534,2);
->9,105,885,500.53 |
+| INSERT(s1,x,len,s2) | 字符串 s2 替换 s1 的 x 位置开始长度为 len 的字符串 | SELECT INSERT('Welcome to CHINA',1,6,'I love');
->I lovee to CHINA |
+| LOCATE(s1,s) | 从字符串 s 中获取 s1 的开始位置 | SELECT LOCATE('db','stonedb');
->6 |
+| LCASE(s)
LOWER(s) | 将字符串 s 的所有字母变成小写字母 | SELECT LCASE('STONEDB');
->stonedb |
+| LEFT(s,n) | 返回字符串 s 的前 n 个字符 | SELECT LEFT('stonedb',5);
->stone |
+| LPAD(s1,len,s2) | 在字符串 s1 的开始处填充字符串 s2,使字符串长度达到 len | SELECT LPAD('one',5,'st');
->stone |
+| LTRIM(s) | 去掉字符串 s 开始处的空格 | SELECT LTRIM(' STONEDB');
->STONEDB |
+| MID(s,n,len) | 从字符串 s 的 n 位置截取长度为 len 的子字符串,同 SUBSTRING(s,n,len) | SELECT MID('stonedb',2,3);
->ton |
+| POSITION(s1 IN s) | 从字符串 s 中获取 s1 的开始位置 | SELECT POSITION('db'in'stonedb');
->6 |
+| REPEAT(s,n) | 将字符串 s 重复 n 次 | SELECT REPEAT('hello',3);
->hellohellohello |
+| REPLACE(s,s1,s2) | 将字符串 s2 替代字符串 s 中的字符串 s1 | SELECT REPLACE('stonedb','db','x');
->stonex |
+| REVERSE(s) | 将字符串s的顺序反过来 | SELECT REVERSE('stonedb');
->bdenots |
+| RIGHT(s,n) | 返回字符串 s 的后 n 个字符 | SELECT RIGHT('stonedb',5);
->onedb |
+| RPAD(s1,len,s2) | 在字符串 s1 的结尾处添加字符串 s2,使字符串的长度达到 len | SELECT RPAD('stone',7,'db');
->stonedb |
+| RTRIM(s) | 去掉字符串 s 结尾处的空格 | SELECT RTRIM('STONEDB ');
->STONEDB |
+| SPACE(n) | 返回 n 个空格 | SELECT SPACE(10);
-> |
+| STRCMP(s1,s2) | 比较字符串 s1 和 s2,如果 s1 与 s2 相等返回 0 ,如果 s1>s2 返回 1,如果 s1->1 |
+| SUBSTR(s, start, length) | 从字符串 s 的 start 位置截取长度为 length 的子字符串 | SELECT SUBSTR('STONEDB',2,3);
->TON |
+| SUBSTRING_INDEX(s, delimiter, number) | 返回从字符串 s 的第 number 个出现的分隔符 delimiter 之后的子串 | SELECT SUBSTRING_INDEX('stonedb','n',1);
->sto |
+| TRIM(s) | 去掉字符串 s 开始和结尾处的空格 | SELECT TRIM(' STONEDB ');
->STONEDB |
+| UCASE(s)
UPPER(s) | 将字符串转换为大写 | SELECT UCASE('stonedb');
->STONEDB |
\ No newline at end of file
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/06-performance-tuning/04-database-tuning/sql-best-practices.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/06-performance-tuning/04-database-tuning/sql-best-practices.md
index ce9034761..96cb3e7fd 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/06-performance-tuning/04-database-tuning/sql-best-practices.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/06-performance-tuning/04-database-tuning/sql-best-practices.md
@@ -6,38 +6,43 @@ sidebar_position: 7.41
# SQL编写规范
## 一、表设计规范
-1)StoneDB的表无需创建索引,但主键是关系型数据库中唯一确定一条记录的依据,建议给表定义主键。
-2)使用自增类型主键,严禁使用uuid类型主键,自增主键能有效提高插入的性能,避免过多的数据页分裂和碎片的增加,提高了空间的使用率,而uuid类型主键不仅无序,而且占用空间更大。
-3)严禁使用外键约束,有外键的表在每次插入、更新和删除后,需要进行完整性的检查,额外的检查工作对性能来说是有损的。
-4)定长字符型字段使用CHAR类型,不定长字符型字段使用VARCHAR类型。
-5)合理定义字段长度,若实际存储长度与定义长度差异过大,不仅占用空间,而且影响访问效率。
-6)字段尽量定义为NOT NULL,并且提供默认值。
-7)表中应包含时间戳的字段,时间戳是获取增量数据的一种方法,可预估一个时间范围内的行数,也可更方便的进行数据清理和归档。
-8)字段尽量不使用大对象类型,如果查询出现大对象类型的字段,就会消耗大量的网络和IO带宽,如有需要,可考虑在外部进行存储。
-9)无论是表名还是字段名,都不能使用数据库的关键字,如desc、order、group、distinct等。
-10)无论是表还是字段,字符集建议一致。
-11)无论是表还是字段,有必要加入注释,有注释更易于维护和易读。
+1. StoneDB的表无需创建索引,但主键是关系型数据库中唯一确定一条记录的依据,建议给表定义主键。
+2. 使用自增类型主键,严禁使用uuid类型主键,自增主键能有效提高插入的性能,避免过多的数据页分裂和碎片的增加,提高了空间的使用率,而uuid类型主键不仅无序,而且占用空间更大。
+3. 严禁使用外键约束,有外键的表在每次插入、更新和删除后,需要进行完整性的检查,额外的检查工作对性能来说是有损的。
+4. 定长字符型字段使用CHAR类型,不定长字符型字段使用VARCHAR类型。
+5. 合理定义字段长度,若实际存储长度与定义长度差异过大,不仅占用空间,而且影响访问效率。
+6. 字段尽量定义为NOT NULL,并且提供默认值。
+7. 表中应包含时间戳的字段,时间戳是获取增量数据的一种方法,可预估一个时间范围内的行数,也可更方便的进行数据清理和归档。
+8. 字段尽量不使用大对象类型,如果查询出现大对象类型的字段,就会消耗大量的网络和IO带宽,如有需要,可考虑在外部进行存储。
+9. 无论是表名还是字段名,都不能使用数据库的关键字,如desc、order、group、distinct等。
+10. 无论是表还是字段,字符集建议一致。
+11. 无论是表还是字段,有必要加入注释,有注释更易于维护和易读。
## 二、SQL编写规范
### 2.1 避免`select *`
查询尽量用确定的字段名,不因图方便用*来代替,理由:
-1)将不需要的字段从服务端传输到客户端,额外增加了网络开销;
-2)影响SQL的执行计划,例如:用select *进行查询时,很可能不会使用到覆盖索引,就会造成回表查询。
-反例:
+
+1. 将不需要的字段从服务端传输到客户端,额外增加了网络开销;
+
+2. 影响SQL的执行计划,例如:用select *进行查询时,很可能不会使用到覆盖索引,就会造成回表查询。
+
+**反例:**
```sql
select * from test;
```
-正例:
+**正例:**
```sql
select id,name from test;
```
### 2.2 避免在`where`子句中使用`or`
多个字段进行or查询时,建议用union all联结,分成多次查询。
+
理由:使用or可能会导致索引失效
-反例:
+
+**反例:**
```sql
select * from test where group_id='40' or user_id='uOrzp9ojhfgqcwRCiume';
```
-正例:
+**正例:**
```sql
select * from test where group_id='40'
union all
@@ -45,32 +50,36 @@ select * from test where user_id='uOrzp9ojhfgqcwRCiume';
```
### 2.3 避免对索引列运算
理由:对索引列进行运算会导致索引失效
-反例:
+
+**反例:**
```sql
select * from test where id-1=99;
```
-正例:
+**正例:**
```sql
select * from test where id=100;
```
### 2.4 避免在索引列上使用函数
理由:在索引列上使用函数会导致索引失效
-反例:
+
+**反例:**
```sql
select * from test where date_add(create_time,interval 10 minute)=now();
```
-正例:
+**正例:**
```sql
select * from test where create_time=date_add(now(),interval - 10 minute);
```
### 2.5 避免出现索引列自动转换
如果字段的数据类型是字符串,代入变量一定要用引号括起来。
+
理由:对索引列进行转换会导致索引失效。
-反例:
+
+**反例:**
```sql
select * from test where group_id=40;
```
-正例:
+**正例:**
```sql
select * from test where group_id='40';
```
@@ -90,11 +99,12 @@ select * from test where group_id='40';
理由:减少加锁时间。
### 2.13 尽量少用having过滤数据
理由:having会在最后一步对结果集进行过滤,这个处理需要排序、汇总等操作,如果能通过where过滤就不用having过滤。
-反例:
+
+**反例:**
```sql
select job,avg(salary) from test group by job having job = 'managent';
```
-正例:
+**正例:**
```sql
select job,avg(salary) from test where job = 'managent' group by job;
```
@@ -102,13 +112,14 @@ select job,avg(salary) from test where job = 'managent' group by job;
理由:如果SQL语句中调用函数,则返回多少结果集,函数就会被调用多少次。
### 2.15 慎用标量子查询
理由:主查询返回多少行,标量子查询就需要执行多少次,如果主查询的结果集很大,SQL的性能就会很差。
-反例:
+
+**反例:**
```sql
select e.empno, e.ename, e.sal,e.deptno,
(select d.dname from dept d where d.deptno = e.deptno) as dname
from emp e;
```
-正例:
+**正例:**
```sql
select e.empno, e.ename, e.sal, e.deptno, d.dname
from emp e
@@ -117,12 +128,14 @@ on e.deptno = d.deptno;
```
### 2.16 排序字段顺序最好保持一致
理由:排序保持一致,能充分利用索引的有序性来消除排序带来的CPU开销。
+
例如:组合索引(a,b),在反例中,由于字段a要升序,字段b要降序,优化器就不能选择索引来消除排序。
-反例:
+
+**反例:**
```sql
select a,b from test order by a,b desc;
```
-正例:
+**正例:**
```sql
select a,b from test order by a,b;
select a,b from test order by a desc,b desc;
@@ -131,7 +144,8 @@ select a,b from test order by a desc,b desc;
理由:表连接越多,编译的时间和开销也就越大,而且优化器容易选错执行计划。
### 2.18 嵌套层次尽量少
理由:容易产生临时表和较差的执行计划。
-反例:
+
+**反例:**
```sql
select * from t1 a where a.proj_no in
(select b.proj_no from t2 b where b.proj_name = 'xxx'
@@ -141,21 +155,23 @@ and a.oper_type <> 'D';
```
### 2.19 避免出现笛卡尔积关联
理由:如果两表进行关联,且没有关联条件,就会发生笛卡尔积关联,如果两表的数据量都很大,这种连接是极其消耗CPU和内存的。
-反例:
+
+**反例:**
```sql
select * from a,b;
```
-正例:
+**正例:**
```sql
select * from a,b where a.id=b.id;
```
### 2.20 limit分页的偏移量不宜过大
理由:由于先获取的是偏移量的数据,然后获取分页的数据,最后再把偏移量这一段的数据抛弃返回分页的数据,因此当偏移量很大时,SQL的性能就会很差。
-反例:
+
+**反例:**
```sql
select id,name from test limit 10000,10;
```
-正例:
+**正例:**
```sql
select id,name from test where id>10000 limit 10;
```
@@ -169,13 +185,14 @@ select id,name from test where id>10000 limit 10;
区别:left join返回的是左表所有行,右表不匹配的行用null来填充,inner join返回的是两表完全匹配的行。
### 2.25 要分清left join中on...and与on...where的区别
区别:
-1)on...and没有起到过滤作用,不匹配的行还是用null来填充,on...where有过滤作用;
-2)left右边的表谓词条件不管放在on还是where后面,都会对右表先过滤再连接,但是放在where后left join会转换为inner join。
+1. `on...and`没有起到过滤作用,不匹配的行还是用`null`来填充,`on...where`有过滤作用;
+2. left右边的表谓词条件不管放在on还是where后面,都会对右表先过滤再连接,但是放在where后left join会转换为inner join。
### 2.26 要分清inner join中on...and与on...where的区别
-区别:on...and与on...where是等价的,都有过滤作用。
+区别:`on...and`与`on...where`是等价的,都有过滤作用。
### 2.27 不必要的排序
理由:用于统计条数,那么排序就是多此一举的。
-反例:
+
+**反例:**
```sql
select count(*) as totalCount from
(select * from enquiry e where 1 = 1
@@ -183,7 +200,7 @@ AND status = 'closed'
AND is_show = 1
order by id desc, expire_date asc) _xx;
```
-正例:
+**正例:**
```sql
select count(*) from enquiry e where 1 = 1
AND status = 'closed'
@@ -191,7 +208,8 @@ AND is_show = 1;
```
### 2.28 不必要的嵌套
理由:能用一条select就满足的查询条件,避免了外层的嵌套select查询。
-反例:
+
+**反例:**
```sql
select count(*) as totalCount from
(select * from enquiry e where 1 = 1
@@ -199,7 +217,7 @@ AND status = 'closed'
AND is_show = 1
order by id desc, expire_date asc) _xx;
```
-正例:
+**正例:**
```sql
select count(*) from enquiry e where 1 = 1
AND status = 'closed'