Skip to content

Commit

Permalink
develop: fix simpletab (pingcap#10556)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreoxmt authored Jul 21, 2022
1 parent f4ee5e6 commit 8cc8165
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 149 deletions.
15 changes: 3 additions & 12 deletions develop/dev-guide-bookshop-schema-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ Bookshop 是一个虚拟的在线书店应用,你可以在 Bookshop 当中便

## 导入表结构和数据

你可以[通过 TiUP](#通过-tiup-demo-命令行)[通过 TiDB Cloud Import](#通过-tidb-cloud-import-功能) 两种方式导入 Bookshop 应用的表结构和数据。
你可以[通过 TiUP](#方法一通过-tiup-demo-命令行)[通过 TiDB Cloud Import](#方法二通过-tidb-cloud-import-功能) 两种方式导入 Bookshop 应用的表结构和数据。

<SimpleTab>
<div label="通过 `tiup demo` 命令行">

### 通过 `tiup demo` 命令行
### 方法一:通过 `tiup demo` 命令行

如果你使用 [TiUP](/tiup/tiup-reference.md#tiup-命令概览) 部署 TiDB 集群或者你可以直接连接到你的 TiDB 服务器,你可以通过如下命令快速生成并导入 Bookshop 应用的示例数据:

Expand Down Expand Up @@ -71,10 +68,7 @@ tiup demo bookshop prepare --users=200000 --books=500000 --authors=100000 --rati

通过 `--drop-tables` 参数你可以删除原有的表结构,更多的参数说明你可以通过命令 `tiup demo bookshop --help` 进行了解。

</div>
<div label="通过 TiDB Cloud Import 功能">

### 通过 TiDB Cloud Import 功能
### 方法二:通过 TiDB Cloud Import 功能

在 TiDB Cloud 的数据库详情页面,你可以通过点击 **Import** 按钮,进入到 **Data Import Task** 页面,在该页面当中,按照以下步骤将 Bookshop 示例数据从 AWS S3 中导入到你的 TiDB Cloud:

Expand Down Expand Up @@ -149,9 +143,6 @@ WHERE table_schema LIKE 'bookshop';
6 rows in set (0.03 sec)
```

</div>
</SimpleTab>

## 数据表详解

以下将详细介绍 Bookshop 应用程序的数据库表结构:
Expand Down
8 changes: 4 additions & 4 deletions develop/dev-guide-build-cluster-in-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ aliases: ['/zh/tidb/dev/build-cluster-in-cloud']

<div label="macOS">

如果你没有安装 Homebrew,请移步 [Homebrew 官网](https://brew.sh/index_zh-cn)进行安装。
对于 macOS 操作系统,如果你没有安装 Homebrew,请参考 [Homebrew 官网](https://brew.sh/index_zh-cn)进行安装。

{{< copyable "shell-regular" >}}

Expand Down Expand Up @@ -85,7 +85,7 @@ aliases: ['/zh/tidb/dev/build-cluster-in-cloud']

<div label="Linux">

CentOS 7 为例:
对于 Linux 操作系统,下面以 CentOS 7 为例:

{{< copyable "shell-root" >}}

Expand Down Expand Up @@ -137,13 +137,13 @@ aliases: ['/zh/tidb/dev/build-cluster-in-cloud']

<div label="本地默认集群">

无需更改
本地默认集群无需更改连接参数

</div>

<div label="非本地默认集群、TiDB Cloud 或其他远程集群">

更改 `plain-java-jdbc/src/main/java/com/pingcap/JDBCExample.java` 内关于 Host、Port、User、Password 的参数:
对于非本地默认集群、TiDB Cloud 或其他远程集群,需要更改 `plain-java-jdbc/src/main/java/com/pingcap/JDBCExample.java` 内关于 Host、Port、User、Password 的参数:

{{< copyable "" >}}

Expand Down
14 changes: 7 additions & 7 deletions develop/dev-guide-delete-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ SELECT COUNT(*) FROM `ratings` WHERE `rated_at` >= "2022-04-15 00:00:00" AND `r
```

- 若返回数量大于 1 万条,请参考[批量删除](#批量删除)
- 若返回数量小于 1 万条,可参考此处的示例进行删除
- 若返回数量小于 1 万条,可参考下面的示例进行删除

<SimpleTab>
<div label="SQL" href="delete-sql">
<div label="SQL">

{{< copyable "sql" >}}
在 SQL 中,删除数据的示例如下:

```sql
DELETE FROM `ratings` WHERE `rated_at` >= "2022-04-15 00:00:00" AND `rated_at` <= "2022-04-15 00:15:00";
```

</div>

<div label="Java" href="delete-java">
<div label="Java">

{{< copyable "" >}}
在 Java 中,删除数据的示例如下:

```java
// ds is an entity of com.mysql.cj.jdbc.MysqlDataSource
Expand All @@ -93,9 +93,9 @@ try (Connection connection = ds.getConnection()) {

</div>

<div label="Golang" href="delete-golang">
<div label="Golang">

{{< copyable "" >}}
在 Golang 中,删除数据的示例如下:

```go
package main
Expand Down
10 changes: 5 additions & 5 deletions develop/dev-guide-get-data-from-single-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ aliases: ['/zh/tidb/dev/get-data-from-single-table']
在 Bookshop 应用程序的数据库当中,`authors` 表存放了作家们的基础信息,可以通过 `SELECT ... FROM ...` 语句将数据从数据库当中调取出去。

<SimpleTab>
<div label="SQL" href="simple-sql">
<div label="SQL">

在 MySQL Client 等客户端输入并执行如下 SQL 语句:

Expand Down Expand Up @@ -57,7 +57,7 @@ SELECT id, name FROM authors;
```

</div>
<div label="Java" href="simple-java">
<div label="Java">

在 Java 语言当中,可以通过声明一个 `Author` 类来定义如何存放作者的基础信息,根据数据的[类型](/data-type-overview.md)[取值范围](/data-type-numeric.md)从 Java 语言当中选择合适的数据类型来存放对应的数据,例如:

Expand Down Expand Up @@ -122,9 +122,9 @@ public class AuthorDAO {
例如,想要查找众多作家当中找出在 1998 年出生的作家:

<SimpleTab>
<div label="SQL" href="filter-sql">
<div label="SQL">

可以在 `WHERE` 子句来添加筛选的条件
在 SQL 中,可以使用 `WHERE` 子句添加筛选的条件

{{< copyable "sql" >}}

Expand All @@ -133,7 +133,7 @@ SELECT * FROM authors WHERE birth_year = 1998;
```

</div>
<div label="Java" href="filter-java">
<div label="Java">

对于 Java 程序而言,可以通过同一个 SQL 来处理带有动态参数的数据查询请求。

Expand Down
4 changes: 2 additions & 2 deletions develop/dev-guide-hybrid-oltp-and-olap-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ HTAP 是 Hybrid Transactional / Analytical Processing 的缩写。传统意义

## 数据准备

在开始之前,你可以[通过 `tiup demo` 命令导入](/develop/dev-guide-bookshop-schema-design.md#通过-tiup-demo-命令行)更加大量的示例数据,例如:
在开始之前,你可以[通过 `tiup demo` 命令导入](/develop/dev-guide-bookshop-schema-design.md#方法一通过-tiup-demo-命令行)更加大量的示例数据,例如:

{{< copyable "shell-regular" >}}

```shell
tiup demo bookshop prepare --users=200000 --books=500000 --authors=100000 --ratings=1000000 --orders=1000000 --host 127.0.0.1 --port 4000 --drop-tables
```

[使用 TiDB Cloud 的 Import 功能导入](/develop/dev-guide-bookshop-schema-design.md#通过-tidb-cloud-import-功能)预先准备好的示例数据。
[使用 TiDB Cloud 的 Import 功能导入](/develop/dev-guide-bookshop-schema-design.md#方法二通过-tidb-cloud-import-功能)预先准备好的示例数据。

## 窗口函数

Expand Down
6 changes: 4 additions & 2 deletions develop/dev-guide-insert-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ aliases: ['/zh/tidb/dev/insert-data']
<SimpleTab>
<div label="SQL">

{{< copyable "sql" >}}
在 SQL 中插入多行数据的示例:

```sql
CREATE TABLE `player` (`id` INT, `coins` INT, `goods` INT);
Expand All @@ -57,7 +57,7 @@ INSERT INTO `player` (`id`, `coins`, `goods`) VALUES (1, 1000, 1), (2, 230, 2);

<div label="Java">

{{< copyable "" >}}
在 Java 中插入多行数据的示例:

```java
// ds is an entity of com.mysql.cj.jdbc.MysqlDataSource
Expand Down Expand Up @@ -132,6 +132,8 @@ jdbc:mysql://127.0.0.1:4000/test?user=root&useConfigs=maxPerformance&useServerPr
<div label="Golang">
在 Golang 中插入多行数据的示例:
```go
package main
Expand Down
12 changes: 6 additions & 6 deletions develop/dev-guide-join-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ aliases: ['/zh/tidb/dev/join-tables']
![Inner Join](/media/develop/inner-join.png)

<SimpleTab>
<div label="SQL" href="inner-join-sql">
<div label="SQL">

在下面的 SQL 语句当中,通过关键字 `JOIN` 声明要将左表 `authors` 和右表 `book_authors` 的数据行以内连接的方式进行连接,连接条件为 `a.id = ba.author_id`,那么连接的结果集当中将只会包含满足连接条件的行。假设有一个作家没有编写过任何书籍,那么他在 `authors` 表当中的记录将无法满足连接条件,因此也不会出现在结果集当中。

Expand Down Expand Up @@ -57,9 +57,9 @@ LIMIT 10;
```

</div>
<div label="Java" href="inner-join-java">
<div label="Java">

{{< copyable "" >}}
在 Java 中内连接的示例如下:

```java
public List<Author> getTop10AuthorsOrderByBooks() throws SQLException {
Expand Down Expand Up @@ -100,7 +100,7 @@ public List<Author> getTop10AuthorsOrderByBooks() throws SQLException {
例如,在 Bookshop 应用的首页,希望展示一个带有平均评分的最新书籍列表。在这种情况下,最新的书籍可能是还没有经过任何人评分的,如果使用内连接就会导致这些无人评分的书籍信息被过滤掉,而这并不是期望的结果。

<SimpleTab>
<div label="SQL" href="left-join-sql">
<div label="SQL">

在下面的 SQL 语句当中,通过 `LEFT JOIN` 关键字声明左表 `books` 将以左外连接的方式与右表 `ratings` 进行连接,从而确保 `books` 表当中的所有记录都能得到返回。

Expand Down Expand Up @@ -166,9 +166,9 @@ DELETE FROM ratings WHERE book_id = 3438991610;
如果改成使用的是内连接 `JOIN` 结果会怎样?这就交给你来尝试了。

</div>
<div label="Java" href="left-join-java">
<div label="Java">

{{< copyable "" >}}
在 Java 中左外连接的示例如下:

```java
public List<Book> getLatestBooksWithAverageScore() throws SQLException {
Expand Down
50 changes: 26 additions & 24 deletions develop/dev-guide-optimistic-and-pessimistic-transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ aliases: ['/zh/tidb/dev/optimistic-and-pessimistic-transaction']

<SimpleTab>

<div label="Java" href="pessimstic-concurrent-save-java">
<div label="Java">

当使用多个线程模拟多用户同时插入的情况时,需要使用一个线程安全的连接对象,这里使用 Java 当前较流行的连接池 [HikariCP](https://github.com/brettwooldridge/HikariCP)

</div>

<div label="Golang" href="pessimstic-concurrent-save-golang">
<div label="Golang">

Golang 的 `sql.DB` 是并发安全的,无需引入外部包。

Expand Down Expand Up @@ -100,11 +100,11 @@ func (tx *TiDBSqlTx) Rollback() error {

<SimpleTab>

<div label="Java" href="pessimstic-code-java">
<div label="Java">

**配置文件**

如果你使用 Maven 作为包管理,在 `pom.xml` 中的 `<dependencies>` 节点中,加入以下依赖来引入 `HikariCP`,同时设定打包目标,及 JAR 包启动的主类,完整的 `pom.xml` 如下所示:
在 Java 中,如果你使用 Maven 作为包管理,在 `pom.xml` 中的 `<dependencies>` 节点中,加入以下依赖来引入 `HikariCP`,同时设定打包目标,及 JAR 包启动的主类,完整的 `pom.xml` 如下所示:

{{< copyable "" >}}

Expand Down Expand Up @@ -333,9 +333,9 @@ public class TxnExample {

</div>

<div label="Golang" href="pessimstic-code-golang">
<div label="Golang">

首先设计一个帮助类 `helper.go`,封装了所需的数据库操作:
在 Golang 中,首先设计一个帮助类 `helper.go`,封装了所需的数据库操作:

{{< copyable "" >}}

Expand Down Expand Up @@ -665,9 +665,9 @@ Golang 的例子中,已经包含乐观事务。

<SimpleTab>

<div label="Java" href="pessimstic-not-oversell-java">
<div label="Java">

{{< copyable "shell-regular" >}}
在 Java 中运行示例程序:

```shell
mvn clean package
Expand All @@ -676,9 +676,9 @@ java -jar target/plain-java-txn-0.0.1-jar-with-dependencies.jar ALICE_NUM=4 BOB_

</div>

<div label="Golang" href="pessimstic-not-oversell-golang">
<div label="Golang">

{{< copyable "shell-regular" >}}
在 Golang 中运行示例程序:

```shell
go build -o bin/txn
Expand Down Expand Up @@ -746,9 +746,9 @@ mysql> SELECT * FROM users;

<SimpleTab>

<div label="Java" href="pessimstic-oversell-java">
<div label="Java">

{{< copyable "shell-regular" >}}
在 Java 中运行示例程序:

```shell
mvn clean package
Expand All @@ -757,9 +757,9 @@ java -jar target/plain-java-txn-0.0.1-jar-with-dependencies.jar ALICE_NUM=4 BOB_

</div>

<div label="Golang" href="pessimstic-oversell-golang">
<div label="Golang">

{{< copyable "shell-regular" >}}
在 Golang 中运行示例程序:

```shell
go build -o bin/txn
Expand Down Expand Up @@ -824,7 +824,9 @@ mysql> SELECT * FROM users;

<SimpleTab>

<div label="Java" href="optimistic-code-java">
<div label="Java">

使用 Java 编写乐观事务示例:

**代码编写**

Expand Down Expand Up @@ -1008,7 +1010,7 @@ public class TxnExample {

</div>

<div label="Golang" href="optimistic-code-golang">
<div label="Golang">

Golang 在[编写悲观事务示例](#1-编写悲观事务示例)章节中的例子已经支持了乐观事务,无需更改,可直接使用。

Expand All @@ -1022,9 +1024,9 @@ Golang 在[编写悲观事务示例](#1-编写悲观事务示例)章节中的例

<SimpleTab>

<div label="Java" href="optimistic-not-oversell-java">
<div label="Java">

{{< copyable "shell-regular" >}}
在 Java 中运行示例程序:

```shell
mvn clean package
Expand All @@ -1033,9 +1035,9 @@ java -jar target/plain-java-txn-0.0.1-jar-with-dependencies.jar ALICE_NUM=4 BOB_

</div>

<div label="Golang" href="optimistic-not-oversell-golang">
<div label="Golang">

{{< copyable "shell-regular" >}}
在 Golang 中运行示例程序:

```shell
go build -o bin/txn
Expand Down Expand Up @@ -1111,9 +1113,9 @@ mysql> SELECT * FROM users;

<SimpleTab>

<div label="Java" href="optimistic-oversell-java">
<div label="Java">

{{< copyable "shell-regular" >}}
在 Java 中运行示例程序:

```shell
mvn clean package
Expand All @@ -1122,9 +1124,9 @@ java -jar target/plain-java-txn-0.0.1-jar-with-dependencies.jar ALICE_NUM=4 BOB_

</div>

<div label="Golang" href="optimistic-oversell-golang">
<div label="Golang">

{{< copyable "shell-regular" >}}
在 Golang 中运行示例程序:

```shell
go build -o bin/txn
Expand Down
Loading

0 comments on commit 8cc8165

Please sign in to comment.