建一张表,插入一行大数据。
CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 BLOB, f3 TEXT); INSERT INTO t1 VALUES(3, REPEAT( 'a', 20000), REPEAT( 'b', 20000));
gdb查看mysql代码堆栈如下。
#0 dtuple_convert_big_rec (index=0x7fa8cc3497b8, upd=0x0, entry=0x7fa8cc36f128) at /home/data/dev/mysql-8.0.26/storage/innobase/data/data0data.cc:423
#1 0x00000000055870fc in btr_cur_optimistic_insert (flags=0, cursor=0x7faa0013fa00, offsets=0x7faa0013f1b8, heap=0x7faa0013f4e8, entry=0x7fa8cc36f128, rec=0x7faa0013ec80, big_rec=0x7faa0013f9f0, thr=0x7fa8cc342ec8, mtr=0x7faa0013f4f0)
at /home/data/dev/mysql-8.0.26/storage/innobase/btr/btr0cur.cc:2721
#2 0x00000000053c1442 in row_ins_clust_index_entry_low (flags=0, mode=2, index=0x7fa8cc3497b8, n_uniq=1, entry=0x7fa8cc36f128, thr=0x7fa8cc342ec8, dup_chk_only=false) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:2536
#3 0x00000000053c313f in row_ins_clust_index_entry (index=0x7fa8cc3497b8, entry=0x7fa8cc36f128, thr=0x7fa8cc342ec8, dup_chk_only=false) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:3115
#4 0x00000000053c388e in row_ins_index_entry (index=0x7fa8cc3497b8, entry=0x7fa8cc36f128, multi_val_pos=@0x7fa8cc342c68: 0, thr=0x7fa8cc342ec8) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:3307
#5 0x00000000053c3e64 in row_ins_index_entry_step (node=0x7fa8cc342bb0, thr=0x7fa8cc342ec8) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:3443
#6 0x00000000053c41e0 in row_ins (node=0x7fa8cc342bb0, thr=0x7fa8cc342ec8) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:3562
#7 0x00000000053c464c in row_ins_step (thr=0x7fa8cc342ec8) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0ins.cc:3686
#8 0x00000000053e2664 in row_insert_for_mysql_using_ins_graph (mysql_rec=0x7fa8cc25b018 "374 03", prebuilt=0x7fa8cc342338) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0mysql.cc:1583
#9 0x00000000053e2c56 in row_insert_for_mysql (mysql_rec=0x7fa8cc25b018 "374 03", prebuilt=0x7fa8cc342338) at /home/data/dev/mysql-8.0.26/storage/innobase/row/row0mysql.cc:1713
#10 0x00000000051c8365 in ha_innobase::write_row (this=0x7fa8cc340be8, record=0x7fa8cc25b018 "374 03") at /home/data/dev/mysql-8.0.26/storage/innobase/handler/ha_innodb.cc:8801
#11 0x0000000003cf2de8 in handler::ha_write_row (this=0x7fa8cc340be8, buf=0x7fa8cc25b018 "374 03") at /home/data/dev/mysql-8.0.26/sql/handler.cc:7894
#12 0x0000000003fe9d0d in write_record (thd=0x7fa8cc000da0, table=0x7fa8cc33f870, info=0x7faa00141230, update=0x7faa001411b0) at /home/data/dev/mysql-8.0.26/sql/sql_insert.cc:2188
#13 0x0000000003fe5967 in Sql_cmd_insert_values::execute_inner (this=0x7fa8cc36c928, thd=0x7fa8cc000da0) at /home/data/dev/mysql-8.0.26/sql/sql_insert.cc:660
#14 0x00000000039e3f55 in Sql_cmd_dml::execute (this=0x7fa8cc36c928, thd=0x7fa8cc000da0) at /home/data/dev/mysql-8.0.26/sql/sql_select.cc:574
#15 0x0000000003965376 in mysql_execute_command (thd=0x7fa8cc000da0, first_level=true) at /home/data/dev/mysql-8.0.26/sql/sql_parse.cc:3450
#16 0x000000000396a532 in dispatch_sql_command (thd=0x7fa8cc000da0, parser_state=0x7faa00142b10) at /home/data/dev/mysql-8.0.26/sql/sql_parse.cc:5033
#17 0x0000000003960aa2 in dispatch_command (thd=0x7fa8cc000da0, com_data=0x7faa00143bc0, command=COM_QUERY) at /home/data/dev/mysql-8.0.26/sql/sql_parse.cc:1863
#18 0x000000000395eec9 in do_command (thd=0x7fa8cc000da0) at /home/data/dev/mysql-8.0.26/sql/sql_parse.cc:1342
#19 0x0000000003b3c1cf in handle_connection (arg=0xb95c450) at /home/data/dev/mysql-8.0.26/sql/conn_handler/connection_handler_per_thread.cc:301
#20 0x00000000058e0ea6 in pfs_spawn_thread (arg=0xb98dc90) at /home/data/dev/mysql-8.0.26/storage/perfschema/pfs.cc:2898
#21 0x00007faa1671add5 in start_thread () from /lib64/libpthread.so.0
#22 0x00007faa14d8002d in clone () from /lib64/libc.so.6
其中dtuple_convert_big_rec是找到需要external存储的field,通过返回值返回到row_ins_clust_index_entry_low。
big_rec_t *dtuple_convert_big_rec(dict_index_t *index, upd_t *upd,
dtuple_t *entry)
row_ins_clust_index_entry_low调用row_ins_index_entry_big_rec,最后来到btr_store_big_rec_extern_fields进行大对象存储。
dberr_t btr_store_big_rec_extern_fields(trx_t *trx, btr_pcur_t *pcur,
const upd_t *upd, ulint *offsets,
const big_rec_t *big_rec_vec,
mtr_t *btr_mtr, opcode op)


