/** The tree cursor: the definition Appears here only for the compilerto know struct size! */struct btr_cur_t { btr_cur_t() { memset(this, 0, sizeof(*this)); } dict_index_t* index;/*!< index where positioned */ page_cur_t page_cur; /*!< page cursor */ purge_node_t* purge_node; /*!< purge node, for BTR_DELETE */ buf_block_t* left_block; /*!< this field is used to storea pointer to the left neighborpage, in the casesBTR_SEARCH_PREV andBTR_MODIFY_PREV */ /*------------------------------*/ que_thr_t* thr;/*!< this field is only usedwhen btr_cur_search_to_nth_levelis called for an index entryinsertion: the calling querythread is passed here to beused in the insert buffer */ /*------------------------------*/};其中:- page_cur_t page_cur,保存 page cursor。
/** Index page cursor */struct page_cur_t{ const dict_index_t* index; rec_t*rec; /*!< pointer to a record on page */ ulint*offsets; buf_block_t* block; /*!< pointer to the block containing rec */};其中:- rec_t* rec,表示游标查询得到的记录;
- buf_block_t* block,表示表示游标查询得到的记录所在块信息 。
/* The persistent B-tree cursor structure. This is used mainly for SQLselects, updates, and deletes. */struct btr_pcur_t{ btr_pcur_t() { memset(this, 0, sizeof(*this)); } /** a B-tree cursor */ btr_cur_t btr_cur;rec_t*old_rec;/** Return the index of this persistent cursor */ dict_index_t* index() const { return(btr_cur.index); }};其中:- rec_t* old_rec,持久化游标中保存查询得到的记录 。
insert 语句build_template从 server 层调用存储引擎的接口 handler 开始,具体是 ha_innobase::write_row 函数 。
// storage/innbase/handler/ha_innodb.cc/* Stores a row in an InnoDB database, to the table specified in this handle. */intha_innobase::write_row(/*===================*/ uchar* record) /*!< in: a row in MySQL format */{/* Step-4: Prepare INSERT graph that will be executed for actual INSERT (This is a one time operation) */ if (m_prebuilt->mysql_template == NULL|| m_prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) {/* Build the template used in converting quickly betweenthe two database formats */build_template(true); }/* Step-5: Execute insert graph that will result in actual insert. */ // 插入数据 error = row_insert_for_mysql((byte*) record, m_prebuilt);}其中:- 入参 uchar* record 指向 table->record[0],其中不包含表列的类型、列的长度、列数等信息 , 完全是客户端插入的数据;
- 调用 build_template 函数初始化 m_prebuilt 变量;
- 调用 row_insert_for_mysql 函数插入数据,入参中将 record 指针从 uchar 转换成 byte 类型 。
typedef unsigned char uchar; /* Short for unsigned char *//* Note that inside MySQL 'byte' is defined as char on linux! */#define byteunsigned charm_prebuilt 变量是 row_prebuilt_t 结构体指针类型,其中部分成员如下所示,包括表、索引、游标等各种信息 。/** Save CPU time with prebuilt/cached data structures */row_prebuilt_t*m_prebuilt;/** A struct for (sometimes lazily) prebuilt structures in an Innobase tablehandle used within MySQL; these are used to save CPU time. */struct row_prebuilt_t { dict_table_t* table;/*!< Innobase table handle */ dict_index_t* index;/*!< current index for a search, if any */ trx_t*trx;/*!< current transaction handle */unsigned n_template:10; /*!< number of elements in thetemplate */ins_node_t* ins_node; /*!< Innobase SQL insert nodeused to perform insertsto the table */byte*ins_upd_rec_buff;/*!< buffer for storing data convertedto the Innobase format from the MySQLformat */mysql_row_templ_t* mysql_template;/*!< template used to transformrows fast between MySQL and Innobaseformats; memory for this templateis not allocated from 'heap' */btr_pcur_t* pcur;/*!< persistent cursor used in selectsand updates */};
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MySQL:级联从库延迟数据库的延迟计算问题
- 提醒!微信、支付宝这个功能,建议关闭
- 支付宝2023年度报告发布,多巴胺经济、小攒青年、万事打卡成关键词
- 怎么减双下巴 怎么减双下巴最快最有效
- 驻点是什么意思 驻店是什么意思
- 电热水器安装方法及维修技巧
- 安顺十佳特色美食,安顺美食排名前十名
- 竹子是? 竹子实际是什么
- 整容脸、演戏烂,关系户三个字直接写在剧版《三大队》女六号脸上
- 裤腿大了怎么办 裤腿很大怎么办
