MySQL DBA's Blog

Archive for the ‘MySQL Internals’ Category

handler和handlerton

Friday, July 9th, 2010

很久之前看过Understanding MySQL Internals的一些片段。最近很烦,于是又翻了翻(纯发泄)。

handlerton提供的是存储引擎的一些特性。比如记录点、提交、回滚。同一个引擎跨表的操作需要在handlerton里面完成,比如说引擎的初始化,跨表的事务。
handler提供了表的基本操作。比如打开关闭表、扫描数据索引,都可以在handler里面找到相应的接口。每个handler的子类进行初始化对象的时候,必须向构造函数传递一个handlerton对象的引用。
handler类有很多纯虚函数,必须要在handler的子类里面实现。这些函数决定了存储引擎的底层io方式,包括数据存取和索引。
ha_example.h里可以很方便地找到这些纯虚函数:
int open(const char *name, int mode, uint test_if_locked); // required
int close(void); // required
int rnd_init(bool scan); //required
int rnd_next(uchar *buf); ///< required
int rnd_pos(uchar *buf, uchar *pos); ///< required
void position(const uchar *record); ///< required
int info(uint); ///< required
int external_lock(THD *thd, int lock_type); ///< required
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); ///< required
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); ///< required

貌似有点困了。改日用GDB调试一下EXAMPLE引擎,再上来写一个~

MEMORY引擎的哈希索引不支持最左原则

Thursday, April 1st, 2010

MySQL的官方文档并没有过多提及哈希索引,以致于很多书上写着“只有MEMORY引擎才支持哈希索引”。
通过测试发现,InnoDB引擎也是能够支持哈希索引的,而且单条记录的查询性能明显要高于B树索引。这说明哈希索引的建立不仅仅是语法上的支持,而是真正有代码实现的。

但是在最近的一些实践中发现,索引的最左原则居然不适用于MEMORY引擎的哈希索引! (more…)

MySQL Timeout解析

Saturday, February 6th, 2010

“And God said, Let there be network: and there was timeout”

在使用MySQL的过程中,你是否遇到了众多让人百思不得其解的Timeout?
那么这些Timeout之后,到底是代码问题,还是不为人知的匠心独具?
本期Out-man,讲述咱们MySQL DBA自己的Timeout。
(more…)

一主多备切换能否保证数据一致性?

Wednesday, November 25th, 2009

当主库彻底坏掉之后,DBA要把数据最接近主库的从库设置为新的主库,接着重定向剩下所有备库的复制方向。
这就产生了一个问题,如何计算备库到新主库的binlog position呢?
看一下官网上对show slave status的解释:

#binlog读到了哪里
Master_Log_File
The name of the master binary log file from which the I/O thread is currently reading.
Read_Master_Log_Pos
The position up to which the I/O thread has read in the current master binary log.
(more…)