MySQL insert 语句的函数调用栈,这个调用栈是用gdb调试MySQL时打印出来的,内容和格式上没做任何调整,MySQL的版本是5.7的最新版本5.7.35,调用的顺序是从下到上。存储引擎是innodb,学习和研究MySQL数据库源码时可以当作参考,里面的信息时相当完整的,调用的函数名称,调用函数所在的文件,调用函数在文件中具体位置(在文件中的哪一行)都十分清楚。
MySQL数据库innodb存储引擎在执行更新时可能会采用两种不同的方式,备份更新或者是乐观更新,innodb引擎总是首先对索引内存对象加上s-latch保护,然后进行页的操作,若insert、update、delete不会导致非叶子节点的变化,即不会发生
分裂、合并、树的高度变化,则立即释放索引对象的s-latch保护,称这种模式为乐观模式。否则,立即释放索引内存对象及页上的latch,并对索引内存对象和页加x-latch保护,这种方式称为悲观方式,由于对索引对象页加了x-latch,并发在此处受到了很大的限制。
从下面的函数跳用栈来看,这次更新使用了乐观更新,调用的函数是btr_cur_optimistic_insert。
0page_cur_insert_rec_low (current_rec=0x6<error: Cannotaccessmemoryataddress0x6>, index=0x7f24e569b6d0, rec=0x7f24e569b720"d", offsets=0x6, mtr=0x563e03dea7eb<rec_offs_n_fields(ulintconst*)+171>) at/root/mysql-5.7.35/storage/innobase/page/page0cur.cc:134210x0000563e03f4b9f1inpage_cur_tuple_insert (cursor=0x7f24e569be48, tuple=0x7f248001e420, index=0x7f2480012290, offsets=0x7f24e569bdf0, heap=0x7f24e569bde8, n_ext=0, mtr=0x7f24e569c270, use_cache=false) at/root/mysql-5.7.35/storage/innobase/include/page0cur.ic:28720x0000563e03f55a90inbtr_cur_optimistic_insert (flags=0, cursor=0x7f24e569be40, offsets=0x7f24e569bdf0, heap=0x7f24e569bde8, entry=0x7f248001e420, rec=0x7f24e569bdf8, big_rec=0x7f24e569bde0, n_ext=0, thr=0x7f2480021828, mtr=0x7f24e569c270) at/root/mysql-5.7.35/storage/innobase/btr/btr0cur.cc:321530x0000563e03e14beainrow_ins_clust_index_entry_low (flags=0, mode=2, index=0x7f2480012290, n_uniq=0, entry=0x7f248001e420, n_ext=0, thr=0x7f2480021828, dup_chk_only=false) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:261240x0000563e03e16cf7inrow_ins_clust_index_entry (index=0x7f2480012290, entry=0x7f248001e420, thr=0x7f2480021828, n_ext=0, dup_chk_only=false) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:329950x0000563e03e1720binrow_ins_index_entry (index=0x7f2480012290, entry=0x7f248001e420, thr=0x7f2480021828) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:343760x0000563e03e177b4inrow_ins_index_entry_step (node=0x7f2480021588, thr=0x7f2480021828) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:358770x0000563e03e17b47inrow_ins (node=0x7f2480021588, thr=0x7f2480021828) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:372580x0000563e03e17fb3inrow_ins_step (thr=0x7f2480021828) at/root/mysql-5.7.35/storage/innobase/row/row0ins.cc:386190x0000563e03e37a7finrow_insert_for_mysql_using_ins_graph (mysql_rec=0x7f2480010728"\370\001", prebuilt=0x7f2480020f90) at/root/mysql-5.7.35/storage/innobase/row/row0mysql.cc:1746100x0000563e03e38099inrow_insert_for_mysql (mysql_rec=0x7f2480010728"\370\001", prebuilt=0x7f2480020f90) at/root/mysql-5.7.35/storage/innobase/row/row0mysql.cc:1866110x0000563e03cce301inha_innobase::write_row (this=0x7f2480010430, record=0x7f2480010728"\370\001") at/root/mysql-5.7.35/storage/innobase/handler/ha_innodb.cc:7663120x0000563e0326b302inhandler::ha_write_row (this=0x7f2480010430, buf=0x7f2480010728"\370\001") at/root/mysql-5.7.35/sql/handler.cc:8173130x0000563e03b4a535inwrite_record (thd=0x7f2480000e10, table=0x7f2480020560, info=0x7f24e569d160, update=0x7f24e569d1e0) at/root/mysql-5.7.35/sql/sql_insert.cc:1895140x0000563e03b472c9inSql_cmd_insert::mysql_insert (this=0x7f2480006df0, thd=0x7f2480000e10, table_list=0x7f2480006840) at/root/mysql-5.7.35/sql/sql_insert.cc:776150x0000563e03b4e541inSql_cmd_insert::execute (this=0x7f2480006df0, thd=0x7f2480000e10) at/root/mysql-5.7.35/sql/sql_insert.cc:3142160x0000563e038fec32inmysql_execute_command (thd=0x7f2480000e10, first_level=true) at/root/mysql-5.7.35/sql/sql_parse.cc:3607170x0000563e03904b72inmysql_parse (thd=0x7f2480000e10, parser_state=0x7f24e569e530) at/root/mysql-5.7.35/sql/sql_parse.cc:5597180x0000563e038f9964indispatch_command (thd=0x7f2480000e10, com_data=0x7f24e569ede0, command=COM_QUERY) at/root/mysql-5.7.35/sql/sql_parse.cc:1491190x0000563e038f87e2indo_command (thd=0x7f2480000e10) at/root/mysql-5.7.35/sql/sql_parse.cc:1032200x0000563e03a41940inhandle_connection (arg=0x563e0756a440) at/root/mysql-5.7.35/sql/conn_handler/connection_handler_per_thread.cc:313210x0000563e041844c7inpfs_spawn_thread (arg=0x563e073cae70) at/root/mysql-5.7.35/storage/perfschema/pfs.cc:2197220x00007f24eb2e2609instart_thread (arg=<optimizedout>) atpthread_create.c:477