Writing Storage Engines for MySQL
by Brian Aker
MySQLのDirector of Architectureによるストレージエンジンの作り方解説:
- Starting points for coding:
-sql/ is for the kernel -mysys/ is the portable runtime -mysql-test is for you test cases
- Terms:Storage Engine, Handler (This is the code that controls the storage engine)
- What does it take?: All code is written in simplified C++, An example storage engine, your ideas
- People who implemented storage engine: Friendster, Google, Yahoo (contributed ideas, thanks Jeremy!!)
- server's kernel:
DDL > Query cache > rewrite engine > parser > optimizer > hander > strage engine DML > rewrite engine > parser > optimizer > hander > strage engine
- What is a storage engine?: Data formats on disk
- What do I need to do to add field:
- Subclass Field in field.h - implements a few method Storage:store(string), store(long long), store(double) Retrieve:val_real(), val_int(), val_str() Other:field_cast_type(), result_type(), cmp(), sort_string(), max_length()
- Field Store Example:
int Field_ipaddrv4::store(const char *from, uint length, CHARSET_INFO *cs) { int count; count = sscan(from,"%u.%u.%u.%u" ptr, (ptr+1),(ptr+2),(ptr+3)); if(count!=4) { bzero(ptr,4); return -1; } return 0; }
- Storage Engine Methods types:
Table Control: create(), open(), close(), delete_table() Optimizer: info(), records_in_range() SQL Modifiers: insert_row(), delete_row(), write_row(), update_row() SQL Readers: [Scan Reads] rnd_init(), md_init(), md_next(), position(), rnd_pos(), mod_pos() [Index Reads] index_read(), index_next()
- Transaction methods ←more complex!!
- Bulk load methods
- Defrag methods
- Lot more (read handler.h)
- Autoconf: Create a new rule in config/ac-macros(look at ha_example file), add your ruleto be checked in configure.in
- Additional Files: basic server files modified under sql/
sql/Makefile.am ..add your include and source file sql/handler.h ..register your handler sql/mysql_priv.h ..set up your variable for show variabes sql/handler.cc ..add yourself to the handler create list sql/mysqld.cc ..set up your variable for show sql/set_var.cc ..add your variable for SHOW display
- Test Cases
mysql-test/include/have_mmap.inc mysql-test/mmap.test mysql-test/???
- other thoughts: what is your goal? (read only? durable? network?)
- more information: sql/ha_example.[h|cc] , mysql.com , list , support
感想.昨日のアレよりもテクニカル,実践的.とりあえず"sql/ha_example"見れ.Brianさんお疲れ様です.今回のUCのセッションはこれにて終了.あとはTim O'Reilly氏のスピーチのみ.