当前位置:网站首页>Analysis on the specific execution process of an insert statement in MySQL 8.0 (3)
Analysis on the specific execution process of an insert statement in MySQL 8.0 (3)
2022-06-29 10:27:00 【A ray of sunshine a】
Code version :mysql 8.0.22
programing language :c++ && c++11 && c++14 && c++17
Last article :mysql 8.0 One insert Analysis of the specific execution process of the statement ( Two )_ A ray of sunshine blog -CSDN Blog
It mainly introduces the storage engine , This chapter mainly introduces insert Which interfaces need to be called when a statement has a secondary index , The order of calling interfaces is as follows :
The following interfaces can be understood basically from the source code , Don't repeat .
Let's take clustered indexes and secondary indexes as examples , Clustered index The calling interface is as follows :
| > row_ins_clust_index_entry
| | > row_ins_clust_index_entry_low
| | | > btr_cur_optimistic_insert
| | | | > btr_cur_ins_lock_and_undo
| | | | | > trx_undo_report_row_operation
| | | | | | > trx_undo_page_report_insert
| | | | | | | > trx_undo_page_set_next_prev_and_add
| | | | | | | | > trx_undof_page_add_undo_rec_log
| | | | > page_cur_tuple_insert
| | | | | > rec_convert_dtuple_to_rec
> rec_convert_dtuple_to_rec_new
> rec_convert_dtuple_to_rec_old
> rec_convert_dtuple_to_rec_comp
| | | | | > page_cur_insert_rec_low
> page_cur_insert_rec_write_log(12)、row_ins_clust_index_entry : Insert entry To a clustered index , Would call 13 The interface
(13)、row_ins_clust_index_entry_low : Try to entry Insert into clustered index , Ignore foreign key constraints .
(14)、btr_cur_optimistic_insert : Insert a page To an index tree
(15)、btr_cur_ins_lock_and_undo : Check lock And write undo log
(16)、page_cur_tuple_insert : Take one record Append to current page, Need and 17 The function in completes
(17)、page_cur_insert_rec_low : Take one record Append to current page, Write uncompressed
Secondary indexes The calling interface is as follows :
| > row_ins_sec_index_entry
| | > row_ins_sec_index_entry_low
| | | > btr_cur_search_to_nth_level
> ibuf_should_try
| | | > row_ins_scan_sec_index_for_duplicate(18)、row_ins_sec_index_entry : Insert... In the secondary index entry
(19)、row_ins_sec_index_entry_low : Try to entry Insert secondary index . If you find a record with exactly the same field , The other record must be marked as deleted , Then insert it into the secondary index
(20)、btr_cur_search_to_nth_level : In the index tree Given in level Find the current location on
(21)、row_ins_scan_sec_index_for_duplicate : Scans for unique nonclustered indexes at a given index entry , To determine whether the key value of the item has a uniqueness conflict . Set the shared lock for possible duplicate records
Last , After all breakpoints have been executed , Use bt The command prints the stack information , Because there are too many breakpoints , Some of the main functions are printed , as follows :
(gdb) bt
#0 btr_cur_optimistic_insert (flags=0, cursor=0x7fffe83d4ae0, offsets=0x7fffe83d4a78,
heap=0x7fffe83d4a70, entry=0x7fff300cb370, rec=0x7fffe83d4a80, big_rec=0x7fffe83d4a68,
thr=0x7fff3029c6f8, mtr=0x7fffe83d50a0)
at /storage/innobase/btr/btr0cur.cc:2833
#1 0x000055555a4c7571 in row_ins_clust_index_entry_low (flags=0, mode=2, index=0x7fff3028a640,
n_uniq=1, entry=0x7fff300cb370, thr=0x7fff3029c6f8, dup_chk_only=false)
at storage/innobase/row/row0ins.cc:2518
#2 0x000055555a4c945c in row_ins_clust_index_entry (index=0x7fff3028a640, entry=0x7fff300cb370,
thr=0x7fff3029c6f8, dup_chk_only=false)
at /storage/innobase/row/row0ins.cc:3097
#3 0x000055555a4c9c14 in row_ins_index_entry (index=0x7fff3028a640, entry=0x7fff300cb370,
[email protected]: 0, thr=0x7fff3029c6f8)
at /storage/innobase/row/row0ins.cc:3289
#4 0x000055555a4ca26f in row_ins_index_entry_step (node=0x7fff3029c338, thr=0x7fff3029c6f8)
at /storage/innobase/row/row0ins.cc:3425
#5 0x000055555a4ca616 in row_ins (node=0x7fff3029c338, thr=0x7fff3029c6f8)
at /storage/innobase/row/row0ins.cc:3544
#6 0x000055555a4caa92 in row_ins_step (thr=0x7fff3029c6f8)
at /storage/innobase/row/row0ins.cc:3668
#7 0x000055555a4ea804 in row_insert_for_mysql_using_ins_graph (mysql_rec=0x7fff302892c8 "\376\005",
prebuilt=0x7fff3029b830) at /storage/innobase/row/row0mysql.cc:1581
#8 0x000055555a4eae9a in row_insert_for_mysql (mysql_rec=0x7fff302892c8 "\376\005",
prebuilt=0x7fff3029b830) at /storage/innobase/row/row0mysql.cc:1711
#9 0x000055555a2a9ad9 in ha_innobase::write_row (this=0x7fff30287bf8, record=0x7fff302892c8 "\376\005")
at /storage/innobase/handler/ha_innodb.cc:8629
#10 0x0000555558d4ace2 in handler::ha_write_row (this=0x7fff30287bf8, buf=0x7fff302892c8 "\376\005")
at /sql/handler.cc:7831
#11 0x00005555590a14a7 in write_record (thd=0x7fff30001040, table=0x7fff30287270, info=0x7fffe83d64f0,
update=0x7fffe83d6570) at /sql/sql_insert.cc:2148
#12 0x000055555909cb7e in Sql_cmd_insert_values::execute_inner (this=0x7fff302becc8, thd=0x7fff30001040)
at /sql/sql_insert.cc:633
#13 0x00005555589ff8fc in Sql_cmd_dml::execute (this=0x7fff302becc8, thd=0x7fff30001040)
at /sql/sql_select.cc:612
#14 0x000055555897bd6e in mysql_execute_command (thd=0x7fff30001040, first_level=true)
at /sql/sql_parse.cc:3420
#15 0x00005555589810b9 in dispatch_sql_command (thd=0x7fff30001040, parser_state=0x7fffe83d7b90)
at /sql/sql_parse.cc:4988
#16 0x0000555558977226 in dispatch_command (thd=0x7fff30001040, com_data=0x7fffe83d8b80,
command=COM_QUERY) at /sql/sql_parse.cc:1836
#17 0x00005555589756df in do_command (thd=0x7fff30001040)
at /sql/sql_parse.cc:1320
#18 0x0000555558b6ee3d in handle_connection (arg=0x55556006bbe0)
at /sql/conn_handler/connection_handler_per_thread.cc:301
#19 0x000055555aa337b6 in pfs_spawn_thread (arg=0x55555fee7ae0)
at /storage/perfschema/pfs.cc:2900
--Type <RET> for more, q to quit, c to continue without paging--
#20 0x00007ffff7f95609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x00007ffff76e0293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95Only this and nothing more , stay MySQL in insert One record The basic process of has been sorted out , The process is quite clear , Those who have primary database experience can sort it out .
The next few articles are mainly about MySQL in redo.log Medium mtr.
边栏推荐
猜你喜欢
随机推荐
2020-9-14 introduction to advertising system
1146 topological order (25 points)
Add/modify/drop column of alter table operation in MySQL
Six dimensional space BFS
We can't tell the difference between distributed and cluster. Let's tell the story of two cooks cooking
HDU 6778 car (group enumeration -- > shape pressure DP)
Related problems of pointer array, array pointer and parameter passing
2019.11.17 training summary
Application of Pgp in encryption technology
Implementation of iequalitycomparer interface in C #
Rikka with cake (segment tree + segment tree)
Recurrence of vulnerability analysis for Cisco ASA, FTD and hyperflex HX
Weight recursion of complete binary tree -- the last programming challenge
PGP在加密技术中的应用
Is it safe to open a stock account with the QR code given by the manager of a securities firm? I want to open an account
Using rancher to build kubernetes cluster
在实践中学习Spark计算框架(01)
Wandering --- 最后的编程挑战
Solve the problem that zxing's QR code contains Chinese garbled code
Dev使用过程中的基本操作








