zhaiwx_yinfeng 2018-09-29 3096浏览量
Note:
通常情况下,InnoDB每获得一行记录会:
但在满足一定条件时,InnoDB会顺序读取一部分记录并放到一个cache中。
在之前的版本中,这个cache是由innodb来控制的,挂在row_prebuilt_t->fetch_cache数组中,数量也是固定的,最多预读8条记录。
在MySQL8.0中,对这部分逻辑做了修改(wl#7093), 由server层来为innodb提供一个Buffer,并告诉innodb需要预读多少条记录。这种做法相比之前的版本显然更加合理,因为只有server层才理解sql,知道随后是否是顺序scan,是否需要预读更多的数据。server层通过估算可以去决定buffer的大小。
根据worklog的描述,执行器和innodb部分都会去决定是否使用record buffer.
执行器在如下场景不会使用record buffer:(ref set_record_buffer(const QEP_TAB *tab)
)
- If the access type is not one of ref, ref_or_null, index_merge,
range, index or ALL.
- If the scan is estimated to return no more than one row.
- If the scan is a loose index scan, which typically doesn't read many
consecutive rows.
- If the scan is against an internally generated temporary table.
- If the storage engine reports that it won't use the buffer.
InnoDB在如下场景不会使用record buffer (ref row_prebuilt_t::can_prefetch_records()
):
- If the scan is not read-only.
- If the scan accesses BLOB-based columns (such as BLOB, TEXT, JSON,
GEOMETRY).
- If it is a fulltext query.
- If the table does not have a user-defined primary key or a unique
constraint that could be used as a primary key.
- Invoked from innodb api, aks: memcached plugin
- Invoked by Handler syntax
一些细节:
row_search_end_range_check
)其他相关函数:
row_sel_dequeue_cached_row_for_mysql() // 从buffer中读取出记录
row_sel_enqueue_cache_row_for_mysql() // 向buffer中缓存记录
row_sel_fetch_last_buf()
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。