Skip to content

Commit c3cf864

Browse files
authored
sql: align multiple PRs from docs-cn (pingcap#6930)
1 parent bcbbcc5 commit c3cf864

8 files changed

+35
-16
lines changed

best-practices/tidb-best-practices.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ As mentioned before, TiDB limits the size of a single transaction in the Key-Val
160160
161161
It is recommended to split statements into batches or add a limit to the statements, whether they are `INSERT`, `UPDATE` or `DELETE` statements.
162162

163-
When deleting a large amount of data, it is recommended to use `Delete * from t where xx limit 5000;`. It deletes through the loop and use `Affected Rows == 0` as a condition to end the loop.
163+
When deleting a large amount of data, it is recommended to use `Delete from t where xx limit 5000;`. It deletes through the loop and use `Affected Rows == 0` as a condition to end the loop.
164164

165165
If the amount of data that needs to be deleted at a time is large, this loop method gets slower and slower because each deletion traverses backward. After deleting the previous data, lots of deleted flags remain for a short period (then all is cleared by Garbage Collection) and affect the following `DELETE` statement. If possible, it is recommended to refine the `WHERE` condition. Assume that you need to delete all data on `2017-05-26`, you can use the following statements:
166166

167167
```sql
168168
for i from 0 to 23:
169169
while affected_rows > 0:
170-
delete * from t where insert_time >= i:00:00 and insert_time < (i+1):00:00 limit 5000;
170+
delete from t where insert_time >= i:00:00 and insert_time < (i+1):00:00 limit 5000;
171171
affected_rows = select affected_rows()
172172
```
173173

faq/migration-tidb-faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Deleting a large amount of data leaves a lot of useless keys, affecting the quer
174174
175175
### What is the most efficient way of deleting data?
176176
177-
When deleting a large amount of data, it is recommended to use `Delete * from t where xx limit 5000;`. It deletes through the loop and uses `Affected Rows == 0` as a condition to end the loop, so as not to exceed the limit of transaction size. With the prerequisite of meeting business filtering logic, it is recommended to add a strong filter index column or directly use the primary key to select the range, such as `id >= 5000*n+m and id < 5000*(n+1)+m`.
177+
When deleting a large amount of data, it is recommended to use `Delete from t where xx limit 5000;`. It deletes through the loop and uses `Affected Rows == 0` as a condition to end the loop, so as not to exceed the limit of transaction size. With the prerequisite of meeting business filtering logic, it is recommended to add a strong filter index column or directly use the primary key to select the range, such as `id >= 5000*n+m and id < 5000*(n+1)+m`.
178178
179179
If the amount of data that needs to be deleted at a time is very large, this loop method will get slower and slower because each deletion traverses backward. After deleting the previous data, lots of deleted flags remain for a short period (then all will be processed by Garbage Collection) and influence the following Delete statement. If possible, it is recommended to refine the Where condition. See [details in TiDB Best Practices](https://pingcap.com/blog/2017-07-24-tidbbestpractice/#write).
180180

information-schema/information-schema-statistics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Fields in the `STATISTICS` table are described as follows:
5151
* `SEQ_IN_INDEX`: The column number in the index, starting from `1`.
5252
* `COLUMN_NAME`: The column name. See the description of the `Expression` column.
5353
* `COLLATION`: The sorting method of the columns in the index. The value can be `A` (ascending order), `D` (descending order) or `NULL` (unsorted).
54-
* `CARDINALITY`: The estimated number of unique values ​​in the index. To update this value, execute `ANALYZE TABLE`.
54+
* `CARDINALITY`: TiDB does not use this field. The field value is always `0`.
5555
* `SUB_PART`: The prefix of the index. If only part of the prefix of the column is indexed, the value is the number of indexed characters; if the entire column is indexed, the value is `NULL`.
5656
* `PACKED`: TiDB does not use this field. This value is always `NULL`.
5757
* `NULLABLE`: If the column might contain a `NULL` value, the value is `YES`; if not, the value is `''`.

releases/release-5.0.0-rc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Related issue: [#18005](https://github.com/pingcap/tidb/issues/18005)
138138

139139
### Other performance optimizations
140140

141-
+ Improve the execution performance of `delete * from table where id <?` statement. Its P99 performance improves by four times. [#18028](https://github.com/pingcap/tidb/issues/18028)
141+
+ Improve the execution performance of `delete from table where id <?` statement. Its P99 performance improves by four times. [#18028](https://github.com/pingcap/tidb/issues/18028)
142142
+ TiFlash supports concurrently reading and writing data in multiple local disks to improve performance.
143143

144144
## High availability and disaster recovery

releases/release-5.0.0.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ In 5.0 GA, the Coprocessor cache feature is enabled by default. After this featu
261261

262262
To disable the Coprocessor cache feature, you can modify the `capacity-mb` configuration item of `tikv-client.copr-cache` to `0.0`.
263263

264-
### Improve the execution performance of `delete * from table where id <? Limit ?` statement
264+
### Improve the execution performance of `delete from table where id <? Limit ?` statement
265265

266266
[#18028](https://github.com/pingcap/tidb/issues/18028)
267267

268-
The p99 performance of the `delete * from table where id <? limit ?` statement is improved by 4 times.
268+
The p99 performance of the `delete from table where id <? limit ?` statement is improved by 4 times.
269269

270270
### Optimize load base split strategy to solve the performance problem that data cannot be split in some small table hotspot read scenarios
271271

sql-plan-management.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,30 @@ If you do not specify the scope when creating an execution plan binding, the def
8686

8787
```sql
8888
select * from t where a > 1
89-
-- Normalized:
89+
-- After normalization, the above statement is as follows:
9090
select * from test . t where a > ?
9191
```
9292

93+
> **Note:**
94+
>
95+
> Multiple constants joined by commas `,` are normalized as `...` instead of `?`.
96+
>
97+
> For example:
98+
>
99+
> ```sql
100+
> select * from t limit 10
101+
> select * from t limit 10, 20
102+
> select * from t where a in (1)
103+
> select * from t where a in (1,2,3)
104+
> -- After normalization, the above statements are as follows:
105+
> select * from test . t limit ?
106+
> select * from test . t limit ...
107+
> select * from test . t where a in ( ? )
108+
> select * from test . t where a in ( ... )
109+
> ```
110+
>
111+
> When bindings are created, TiDB treats SQL statements that contain a single constant and SQL statements that contain multiple constants joined by commas differently. Therefore, you need to create bindings for the two SQL types separately.
112+
93113
When a SQL statement has bound execution plans in both GLOBAL and SESSION scopes, because the optimizer ignores the bound execution plan in the GLOBAL scope when it encounters the SESSION binding, the bound execution plan of this statement in the SESSION scope shields the execution plan in the GLOBAL scope.
94114
95115
For example:

sql-statements/sql-statement-show-indexes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mysql> SHOW KEYS FROM t1;
7272

7373
## MySQL compatibility
7474

75-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
75+
The `Cardinality` column in MySQL shows the number of different values on the index. In TiDB, the `Cardinality` column always shows `0`.
7676

7777
## See also
7878

sql-statements/sql-statement-show-processlist.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ This statement lists the current sessions connected to the same TiDB server. The
2222

2323
```sql
2424
mysql> SHOW PROCESSLIST;
25-
+------+------+-----------+------+---------+------+-------+------------------+
26-
| Id | User | Host | db | Command | Time | State | Info |
27-
+------+------+-----------+------+---------+------+-------+------------------+
28-
| 1 | root | 127.0.0.1 | test | Query | 0 | 2 | SHOW PROCESSLIST |
29-
| 2 | root | 127.0.0.1 | | Sleep | 4 | 2 | |
30-
+------+------+-----------+------+---------+------+-------+------------------+
31-
2 rows in set (0.00 sec)
25+
+------+------+-----------------+------+---------+------+------------+------------------+
26+
| Id | User | Host | db | Command | Time | State | Info |
27+
+------+------+-----------------+------+---------+------+------------+------------------+
28+
| 5 | root | 127.0.0.1:45970 | test | Query | 0 | autocommit | SHOW PROCESSLIST |
29+
+------+------+-----------------+------+---------+------+------------+------------------+
30+
1 rows in set (0.00 sec)
3231
```
3332

3433
## MySQL compatibility

0 commit comments

Comments
 (0)