Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 30 additions & 105 deletions sql-statements/sql-statement-trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,112 +21,37 @@ The `TRACE` statement provides detailed information about query execution. It is

## Examples

{{< copyable "sql" >}}

```sql
trace format='row' select * from mysql.user;
```

```
+--------------------------------------------+-----------------+------------+
| operation | startTS | duration |
+--------------------------------------------+-----------------+------------+
| trace | 17:03:31.938237 | 886.086µs |
| ├─session.Execute | 17:03:31.938247 | 507.812µs |
| │ ├─session.ParseSQL | 17:03:31.938254 | 22.504µs |
| │ ├─executor.Compile | 17:03:31.938321 | 278.931µs |
| │ │ └─session.getTxnFuture | 17:03:31.938337 | 1.515µs |
| │ └─session.runStmt | 17:03:31.938613 | 109.578µs |
| │ ├─TableReaderExecutor.Open | 17:03:31.938645 | 50.657µs |
| │ │ └─distsql.Select | 17:03:31.938666 | 21.066µs |
| │ │ └─RPCClient.SendRequest | 17:03:31.938799 | 158.411µs |
| │ └─session.CommitTxn | 17:03:31.938705 | 12.06µs |
| │ └─session.doCommitWitRetry | 17:03:31.938709 | 2.437µs |
| ├─*executor.TableReaderExecutor.Next | 17:03:31.938781 | 224.327µs |
| └─*executor.TableReaderExecutor.Next | 17:03:31.939019 | 6.266µs |
+--------------------------------------------+-----------------+------------+
13 rows in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
mysql> trace format='row' select * from mysql.user;
+---------------------------+-----------------+------------+
| operation | startTS | duration |
+---------------------------+-----------------+------------+
| session.getTxnFuture | 10:33:34.647148 | 3.847µs |
| ├─session.Execute | 10:33:34.647146 | 536.233µs |
| ├─session.ParseSQL | 10:33:34.647182 | 19.868µs |
| ├─executor.Compile | 10:33:34.647219 | 295.688µs |
| ├─session.runStmt | 10:33:34.647533 | 116.229µs |
| ├─session.CommitTxn | 10:33:34.647631 | 5.44µs |
| ├─recordSet.Next | 10:33:34.647707 | 833.103µs |
| ├─tableReader.Next | 10:33:34.647709 | 806.783µs |
| ├─recordSet.Next | 10:33:34.648572 | 19.367µs |
| └─tableReader.Next | 10:33:34.648575 | 1.783µs |
+---------------------------+-----------------+------------+
10 rows in set (0.00 sec)

mysql> CREATE TABLE t1 (id int not null primary key AUTO_INCREMENT);
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.02 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> TRACE FORMAT='json' SELECT * FROM t1 WHERE id = 2\G
operation: [
{"ID":{"Trace":"60d20d005593de87","Span":"44e5b309242ffe2f","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"c2Vzc2lvbi5nZXRUeG5GdXR1cmU="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE2MTQ3ODYtMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE2MjA0MDYtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":[
{"ID":{"Trace":"60d20d005593de87","Span":"4dbf8f2ca373b4b0","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"c2Vzc2lvbi5QYXJzZVNRTA=="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE2NjE1MTQtMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3MDYxNjgtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"6b6d6916df809604","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"ZXhlY3V0b3IuQ29tcGlsZQ=="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3NTcyODUtMDY6MDA="},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3MzE0MjYtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"3f1bcdd402a72911","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"c2Vzc2lvbi5Db21taXRUeG4="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3OTgyNjItMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE4MDU1NzYtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"58c1f7d66dc5afbc","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"c2Vzc2lvbi5ydW5TdG10"},
{"Key":"_schema:name","Value":null},
{"Key":"Msg","Value":"eyJzcWwiOiJTRUxFQ1QgKiBGUk9NIHQxIFdIRVJFIGlkID0gMiJ9"},
{"Key":"Time","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3ODA1NjgtMDY6MDA="},
{"Key":"_schema:log","Value":null},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE4MTk5MzMtMDY6MDA="},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE3NzcyNDItMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"6bd8cc440fb31ed7","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"c2Vzc2lvbi5FeGVjdXRl"},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE2MTEwODktMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE4NTU0My0wNjowMA=="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"61d0b809f6cc018b","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"cmVjb3JkU2V0Lk5leHQ="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDE4NzQ1NTYtMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDIyOTg4NjYtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null},
{"ID":{"Trace":"60d20d005593de87","Span":"2bd2c3d47ccb1133","Parent":"79d146dac9a29a7e"},
"Annotations":[
{"Key":"Name","Value":"cmVjb3JkU2V0Lk5leHQ="},
{"Key":"_schema:name","Value":null},
{"Key":"Span.Start","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDIzMjY0ODgtMDY6MDA="},
{"Key":"Span.End","Value":"MjAxOS0wNC0xN1QxMDozOToxMC45NDIzMjkwMDMtMDY6MDA="},
{"Key":"_schema:Timespan","Value":null}
],
"Sub":null}
]
}
]
1 row in set (0.00 sec)
trace format='json' select * from mysql.user;
```

The JSON formatted trace can be pasted into the trace viewer, which is accessed via the TiDB status port:
Expand Down
4 changes: 4 additions & 0 deletions sql-statements/sql-statement-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The `UPDATE` statement is used to modify data in a specified table.

![UpdateStmt](/media/sqlgram/UpdateStmt.png)

**PriorityOpt:**

![PriorityOpt](/media/sqlgram/PriorityOpt.png)

**TableRef:**

![TableRef](/media/sqlgram/TableRef.png)
Expand Down
46 changes: 25 additions & 21 deletions sql-statements/sql-statement-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,31 @@ You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+----------------------+
| Tables_in_mysql |
+----------------------+
| GLOBAL_VARIABLES |
| bind_info |
| columns_priv |
| db |
| default_roles |
| gc_delete_range |
| gc_delete_range_done |
| help_topic |
| role_edges |
| stats_buckets |
| stats_feedback |
| stats_histograms |
| stats_meta |
| tables_priv |
| tidb |
| user |
+----------------------+
16 rows in set (0.00 sec)
+-------------------------+
| Tables_in_mysql |
+-------------------------+
| GLOBAL_VARIABLES |
| bind_info |
| columns_priv |
| db |
| default_roles |
| expr_pushdown_blacklist |
| gc_delete_range |
| gc_delete_range_done |
| global_priv |
| help_topic |
| opt_rule_blacklist |
| role_edges |
| stats_buckets |
| stats_feedback |
| stats_histograms |
| stats_meta |
| stats_top_n |
| tables_priv |
| tidb |
| user |
+-------------------------+
20 rows in set (0.01 sec)

mysql> CREATE DATABASE newtest;
Query OK, 0 rows affected (0.10 sec)
Expand Down