本节讨论MySQL是如何进行数据查询和读取的。首先看一下调用过程:
JOIN::exec()-->
do_select()-->
sub_select()-->
read_record()实际上是join_read_next()或join_read_first()-->
ha_index_next-->
index_next()实际上是ha_innobase::index_next()-->
general_fetch()-->
row_search_mvcc()
ha_innobase是从handler派生出来的,用来做实际查询的。里面的重要结构有:
/** Save CPU time with prebuilt/cached data structures */
row_prebuilt_t* m_prebuilt;
/** Thread handle of the user currently using the handler;
this is set in external_lock function */
THD* m_user_thd;
这里面最重要的是m_prebuilt结构,其中比较重要的几项:
btr_pcur_t* pcur; /*!< persistent cursor used in selects
and updates */
innodb_session_t*
session; /*!< InnoDB session handler. */
/** The MySQL table object */
TABLE* m_mysql_table;
/** The