|
1 | 1 | # How to Measure Transaction Lock Waits in MySQL/InnoDB
|
2 | 2 |
|
3 | 3 | ## Overview
|
| 4 | +- Drilldown the transaction wait event |
4 | 5 |
|
5 |
| -### How query thread is executed |
| 6 | +## Related MySQL Source Code |
| 7 | + |
| 8 | +### Query Graphs |
| 9 | +```bash |
| 10 | +A query graph consists of nodes linked to each other in various ways. The |
| 11 | +execution starts at que_run_threads() which takes a que_thr_t parameter. |
| 12 | +que_thr_t contains two fields that control query graph execution: run_node |
| 13 | +and prev_node. run_node is the next node to execute and prev_node is the |
| 14 | +last node executed. |
| 15 | + |
| 16 | +Each node has a pointer to a 'next' statement, i.e., its brother, and a |
| 17 | +pointer to its parent node. The next pointer is NULL in the last statement |
| 18 | +of a block. |
| 19 | + |
| 20 | +Loop nodes contain a link to the first statement of the enclosed statement |
| 21 | +list. While the loop runs, que_thr_step() checks if execution to the loop |
| 22 | +node came from its parent or from one of the statement nodes in the loop. If |
| 23 | +it came from the parent of the loop node it starts executing the first |
| 24 | +statement node in the loop. If it came from one of the statement nodes in |
| 25 | +the loop, then it checks if the statement node has another statement node |
| 26 | +following it, and runs it if so. |
| 27 | + |
| 28 | +To signify loop ending, the loop statements (see e.g. while_step()) set |
| 29 | +que_thr_t->run_node to the loop node's parent node. This is noticed on the |
| 30 | +next call of que_thr_step() and execution proceeds to the node pointed to by |
| 31 | +the loop node's 'next' pointer. |
| 32 | +``` |
6 | 33 | - que_node_t* node : Gets information of an SQL query graph node.
|
| 34 | +- que_thr_move_to_run_state(): moves a thread state to QUE_THR_RUNNING state. |
7 | 35 | - que0que.cc : que_thr_end_lock_wait()
|
8 |
| -- thd_report_row_lock_wait() |
| 36 | +
|
| 37 | +### Lock |
9 | 38 | - lock_grant()
|
10 | 39 | - lock_trx_has_rec_x_lock()
|
11 |
| -- |
| 40 | +- thd_report_row_lock_wait() |
| 41 | +
|
| 42 | +### Transaction |
12 | 43 | - trx0trx.h: Transaction lock wait
|
13 | 44 | - QUE_THR_LOCK_WAIT
|
14 | 45 | -
|
@@ -117,6 +148,8 @@ struct trx_lock_t {
|
117 | 148 |
|
118 | 149 |
|
119 | 150 | ## Reference
|
| 151 | +- https://dev.mysql.com/blog-archive/innodb-data-locking-part-1-introduction/ |
| 152 | +- https://dev.mysql.com/blog-archive/innodb-data-locking-part-2-locks/ |
120 | 153 | - https://dev.mysql.com/doc/mysql-perfschema-excerpt/8.0/en/performance-schema-transaction-summary-tables.html
|
121 | 154 | - https://dev.mysql.com/doc/mysql-perfschema-excerpt/5.7/en/performance-schema-table-handles-table.html
|
122 | 155 | - https://dev.mysql.com/doc/mysql-perfschema-excerpt/5.7/en/performance-schema-table-lock-waits-summary-by-table-table.html
|
0 commit comments