Skip to content

Commit

Permalink
develop: fix simpletab (#9621) (#9667)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed Jul 21, 2022
1 parent 22d9eb7 commit 4869496
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 96 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 @@ -10,12 +10,9 @@ To make your reading on the application developer guide more smoothly, we presen

## Import table structures and data

You can import Bookshop table structures and data either [via TiUP](#via-tiup-demo) or [via the import feature of TiDB Cloud](#via-tidb-cloud-import).
You can import Bookshop table structures and data either [via TiUP](#method-1-via-tiup-demo) or [via the import feature of TiDB Cloud](#method-2-via-tidb-cloud-import).

<SimpleTab>
<div label="Via `TiUP demo`">

### Via `tiup demo`
### Method 1: Via `tiup demo`

If your TiDB cluster is deployed using [TiUP](/tiup/tiup-reference.md#tiup-reference) or you can connect to your TiDB server, you can quickly generate and import sample data for the Bookshop application by running the following command:

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

You can delete the original table structure through the `--drop-tables` parameter. For more parameter descriptions, run the `tiup demo bookshop --help` command.

</div>
<div label="Via TiDB Cloud Import">

### Via TiDB Cloud Import
### Method 2: Via TiDB Cloud Import

On the database details page of TiDB Cloud, click the **Import** button to enter the **Data Import Task** page. On this page, perform the following steps to import the Bookshop sample data from AWS S3 to TiDB Cloud.

Expand Down Expand Up @@ -159,9 +153,6 @@ The result is as follows:
6 rows in set (0.03 sec)
```

</div>
</SimpleTab>

## Description of the tables

This section describes the database tables of the Bookshop application in detail.
Expand Down
4 changes: 2 additions & 2 deletions develop/dev-guide-build-cluster-in-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you need to run TiDB on your local machine, see [Starting TiDB Locally](/quic

<div label="macOS">

Install [Homebrew](https://brew.sh/index) if you do not have it, and then run the following command to install the MySQL client:
For macOS, install [Homebrew](https://brew.sh/index) if you do not have it, and then run the following command to install the MySQL client:

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

Expand Down Expand Up @@ -88,7 +88,7 @@ mysql Ver 8.0.28 for macos12.0 on arm64 (Homebrew)

<div label="Linux">

Take CentOS 7 as an example:
For Linux, the following takes CentOS 7 as an example:

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

Expand Down
12 changes: 6 additions & 6 deletions develop/dev-guide-delete-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ If more than 10,000 records are returned, use [Bulk-Delete](#bulk-delete) to del
If fewer than 10,000 records are returned, use the following example to delete them.

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

{{< copyable "sql" >}}
In SQL, the example is as follows:

```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 "" >}}
In Java, the example is as follows:

```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 "" >}}
In Golang, the example is as follows:

```go
package main
Expand Down
8 changes: 4 additions & 4 deletions develop/dev-guide-get-data-from-single-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Before querying data, make sure that you have completed the following steps:
In the database of the Bookshop application, the `authors` table stores the basic information of authors. You can use the `SELECT ... FROM ...` statement to query data from the database.

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

Execute the following SQL statement in a MySQL client:

Expand Down Expand Up @@ -56,7 +56,7 @@ The output is as follows:
```

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

In Java, authors' basic information can be stored by declaring a class `Author`. You should choose appropriate Java data types according to the [type](/data-type-overview.md) and [value range](/data-type-numeric.md) in the database. For example:

Expand Down Expand Up @@ -121,7 +121,7 @@ You can use the `WHERE` statement to filter query results.
For example, the following command will query authors who were born in 1998 among all authors:

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

Add filter conditions in the `WHERE` statement:

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

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

In Java, you can use the same SQL to handle data query requests with dynamic parameters.

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 @@ -13,15 +13,15 @@ The [Create a table](/develop/dev-guide-create-table.md#use-htap-capabilities) s

## Data preparation

Before starting, you can import more sample data [via the `tiup demo` command](/develop/dev-guide-bookshop-schema-design.md#via-tiup-demo). For example:
Before starting, you can import more sample data [via the `tiup demo` command](/develop/dev-guide-bookshop-schema-design.md#method-1-via-tiup-demo). For example:

{{< 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
```

Or you can [use the Import function of TiDB Cloud](/develop/dev-guide-bookshop-schema-design.md#via-tidb-cloud-import) to import the pre-prepared sample data.
Or you can [use the Import function of TiDB Cloud](/develop/dev-guide-bookshop-schema-design.md#method-2-via-tidb-cloud-import) to import the pre-prepared sample data.

## Window functions

Expand Down
8 changes: 4 additions & 4 deletions develop/dev-guide-join-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The join result of an inner join returns only rows that match the join condition
For example, if you want to know the most prolific author, you need to join the author table named `authors` with the book author table named `book_authors`.

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

In the following SQL statement, use the keyword `JOIN` to declare that you want to join the rows of the left table `authors` and the right table `book_authors` as an inner join with the join condition `a.id = ba.author_id`. The result set will only contain rows that satisfy the join condition. If an author has not written any books, then his record in `authors` table will not satisfy the join condition and will therefore not appear in the result set.

Expand Down Expand Up @@ -56,7 +56,7 @@ The query results are as follows:
```

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

{{< copyable "java" >}}

Expand Down Expand Up @@ -99,7 +99,7 @@ In some cases, you want to use multiple tables to complete the data query, but d
For example, on the homepage of the Bookshop app, you want to display a list of new books with average ratings. In this case, the new books may not have been rated by anyone yet. Using inner joins will cause the information of these unrated books to be filtered out, which is not what you expect.

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

In the following SQL statement, use the `LEFT JOIN` keyword to declare that the left table `books` will be joined to the right table `ratings` in a left outer join, thus ensuring that all rows in the `books` table are returned.

Expand Down Expand Up @@ -165,7 +165,7 @@ Query again. The book _The Documentary of lion_ still appears in the result set,
What happens if you use `INNER JOIN`? It's up to you to have a try.

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

{{< copyable "java" >}}

Expand Down
28 changes: 14 additions & 14 deletions develop/dev-guide-optimistic-and-pessimistic-transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ The following code uses two threads to simulate the process that two users buy t

<SimpleTab>

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

Because you use multiple threads to simulate the situation that multiple users insert data simultaneously, you need to use a connection object with safe threads. Here use Java's popular connection pool [HikariCP](https://github.com/brettwooldridge/HikariCP) for demo.

</div>

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

`sql.DB` in Golang is concurrency-safe, so there is no need to import a third-party package.

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

<SimpleTab>

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

**Configuration file**

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

</div>

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

Write a `helper.go` file that contains the required database operations:

Expand Down Expand Up @@ -664,7 +664,7 @@ Run the sample program:

<SimpleTab>

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

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

Expand All @@ -675,7 +675,7 @@ 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" >}}

Expand Down Expand Up @@ -745,7 +745,7 @@ Run the sample program:

<SimpleTab>

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

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

Expand All @@ -756,7 +756,7 @@ 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" >}}

Expand Down Expand Up @@ -823,7 +823,7 @@ The following code uses two threads to simulate the process that two users buy t

<SimpleTab>

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

**Coding**

Expand Down Expand Up @@ -1005,7 +1005,7 @@ Change it to the following to point to the optimistic transaction example.

</div>

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

The Golang example in the [Write a pessimistic transaction example](#write-a-pessimistic-transaction-example) section already supports optimistic transactions and can be used directly without changes.

Expand All @@ -1019,7 +1019,7 @@ Run the sample program:

<SimpleTab>

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

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

Expand All @@ -1030,7 +1030,7 @@ 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" >}}

Expand Down Expand Up @@ -1108,7 +1108,7 @@ Run the sample program:

<SimpleTab>

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

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

Expand All @@ -1119,7 +1119,7 @@ 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" >}}

Expand Down
4 changes: 2 additions & 2 deletions develop/dev-guide-optimize-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ This document introduces some common reasons for slow SQL statements and techniq

## Before you begin

You can use [`tiup demo` import](/develop/dev-guide-bookshop-schema-design.md#via-tiup-demo) to prepare data:
You can use [`tiup demo` import](/develop/dev-guide-bookshop-schema-design.md#method-1-via-tiup-demo) to prepare data:

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

```shell
tiup demo bookshop prepare --host 127.0.0.1 --port 4000 --books 1000000
```

Or [using the Import feature of TiDB Cloud](/develop/dev-guide-bookshop-schema-design.md#via-tidb-cloud-import) to import the pre-prepared sample data.
Or [using the Import feature of TiDB Cloud](/develop/dev-guide-bookshop-schema-design.md#method-2-via-tidb-cloud-import) to import the pre-prepared sample data.

## Issue: Full table scan

Expand Down
8 changes: 4 additions & 4 deletions develop/dev-guide-paginate-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SELECT * FROM table_a t ORDER BY gmt_modified DESC LIMIT offset, row_count;
When pagination is used, it is recommended that you sort query results with the `ORDER BY` statement unless there is a need to display data randomly.

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

For example, to let users of the [Bookshop](/develop/dev-guide-bookshop-schema-design.md) application view the latest published books in a paginated manner, you can use the `LIMIT 0, 10` statement, which returns the first page of the result list, with a maximum of 10 records per page. To get the second page, you can change the statement to `LIMIT 10, 10`, and so on.

Expand All @@ -36,7 +36,7 @@ LIMIT 0, 10;
```

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

In application development, the backend program receives the `page_number` parameter (which means the number of the page being requested) and the `page_size` parameter (which controls how many records per page) from the frontend instead of the `offset` parameter. Therefore, some conversions needed to be done before querying.

Expand Down Expand Up @@ -81,7 +81,7 @@ Usually, you can write a pagination SQL statement using a primary key or unique
The following introduces a more efficient paging batching method:

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

First, sort the data by primary key and call the window function `row_number()` to generate a row number for each row. Then, call the aggregation function to group row numbers by the specified page size and calculate the minimum and maximum values of each page.

Expand Down Expand Up @@ -132,7 +132,7 @@ ORDER BY id;
```

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

In Java, define a `PageMeta` class to store page meta information.

Expand Down
8 changes: 4 additions & 4 deletions develop/dev-guide-prepared-statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ For example, you need to query a book with `id = 1` in the [`bookshop` applicati

<SimpleTab>

<div label="SQL" href="read-sql">
<div label="SQL">

{{< copyable "sql" >}}

Expand Down Expand Up @@ -119,7 +119,7 @@ Running result:

</div>

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

{{< copyable "" >}}

Expand Down Expand Up @@ -153,7 +153,7 @@ Using the [`books` table](/develop/dev-guide-bookshop-schema-design.md#books-tab

<SimpleTab>

<div label="SQL" href="write-sql">
<div label="SQL">

{{< copyable "sql" >}}

Expand Down Expand Up @@ -197,7 +197,7 @@ Query OK, 1 row affected (0.03 sec)

</div>

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

{{< copyable "" >}}

Expand Down

0 comments on commit 4869496

Please sign in to comment.