MySQL InnoDB Pluginã®ãã¼ã¿å§ç¸®æ©è½
InnoDB Pluginã®é¢ç½ãæ©è½ã®ä¸ã¤ã«ããã¼ã¿å§ç¸®æ©è½ãããã¾ããä»åã¯ãã®ä»çµã¿ã¨å¹æã«ã¤ãã¦è¦ã¦ããããã¨æãã¾ããã¾ãã¯ã°ã©ããã覧ãã ããã
ããã¯Wikipediaæ¥æ¬èªçã®ãã¼ã¿ãã¼ã¹ããã¦ã³ãã¼ãããè¨äºæ¬æã®æ ¼ç´ããã¦ããtextãã¼ãã«ãMySQL 5.1ï¼InnoDB Plugin 1.0ã®ç°å¢ã«ãã¼ããããã®ã§ãã
- å ããã¹ãï¼ä»åå©ç¨ãããã¼ã¿ã¯2009/06/21çã®ãã®ã§ã(jawiki-20090621-pages-articles.xml.bz2)ãå ããã¹ãã¯ããããXml2sqlãç¨ãã¦ã¿ãåºåãããã¹ããåãåºãããã®ãç¨ãã¦ãã¾ãããã®ãã¡ã¤ã«ã«ã¯1,167,411件ã®è¨äºãæ ¼ç´ããã¦ããã容éã¯3,436MBã¨ãªã£ã¦ãã¾ãã
- å ããã¹ã gzipï¼å ããã¹ããgzipã³ãã³ãã§å§ç¸®ãããã®ã§ãã
- MyISAMï¼è¨äºãMyISAMã®ãã¼ãã«ã«ãã¼ããããã®ã§ããMYDãã¡ã¤ã«ã¨MYIãã¡ã¤ã«ãåç®ãã¦ãã¾ããMyISAMã¯å ããã¹ãã«å¯¾ãã¦ãªã¼ãã¼ããããã»ã¨ãã©ãªããã¨ãåããã¾ãã
- MyISAM myisampackï¼MyISAMã®ãã¼ãã«ãmyisampackã¨ããMySQLä»å±ã®ã³ãã³ãã§å§ç¸®ãããã®ã§ããmyisampackããããã¨ãã¼ãã«ãèªã¿åãå°ç¨ã«ãªããæ´æ°ãã§ããªããªãã¾ãã
- InnoDBï¼è¨äºãé常ã®InnoDBãã¼ãã«ã«ãã¼ããããã®ã§ããå ããã¹ãã«æ¯ã¹ç´1.5åã®ãã¡ã¤ã«ãµã¤ãºã«ãªã£ã¦ãã¾ãã
- InnoDB Compressedï¼InnoDBã®ãã¼ã¿å§ç¸®æ©è½ãç¨ãããã®ã§ããé常ã®InnoDBã«æ¯ã¹ãããååã®ãµã¤ãºã«ãªã£ã¦ãã¾ãã
InnoDBã®ãã¼ã¿å§ç¸®æ©è½ãããå¹ãã¦ãããã¨ãåããã¨æãã¾ãã
åææ¡ä»¶
InnoDBã®ãã¼ã¿å§ç¸®æ©è½ã¯ã以ä¸ã®ç°å¢ã§å©ç¨ãããã¨ãã§ãã¾ãã
ç´ ã®MySQL 5.1ãããããåã®ãã¼ã¸ã§ã³ã§ã¯å©ç¨ãããã¨ãã§ãã¾ãããã¾ããMySQL 5.4ã§ã¯å©ç¨å¯è½ã«ãªããã¨ãã¢ãã¦ã³ã¹(PDF)ããã¦ãã¾ããã確èªããã¨ããMySQL 5.4.1ã«ã¯ã¾ã å®è£ ããã¦ãã¾ããã§ãããããã§ä»åãå æ¥ã®ã¨ã³ããªã¨åæ§ãCentOS 5.3ä¸ã®MySQL Community Server 5.1.35ï¼InnoDB Plugin 1.0.3ã§ä½æ¥ãè¡ã£ã¦ãã¾ãã
ãã©ã¡ã¼ã¿è¨å®
ä»åå©ç¨ããmy.cnfã®æç²ã§ãã
character_set_server = utf8 collation_server = utf8_bin default_storage_engine = InnoDB innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_autoextend_increment = 1
InnoDB Pluginã®ãã¼ã¿å§ç¸®æ©è½ãå©ç¨ããã«ã¯ãinnodb_file_formatã¨innodb_file_per_tableã¨ããäºã¤ã®ãã©ã¡ã¼ã¿ãè¨å®ããå¿
è¦ãããã¾ãã
innodb_file_formatã¯InnoDB Pluginã§æ°è¦ã«è¿½å ããããã©ã¡ã¼ã¿ã§ãInnoDBã®ãã¡ã¤ã«ãã©ã¼ããããæå®ãããã®ã§ããå¤ã¨ãã¦Antelope(ã¬ã¤ã¨ã¦)ã¾ãã¯Barracuda(ã«ãã¹)ãæå®ãããã¨ãã§ãã¾ããAntelopeãå¾æ¥ã®ãã©ã¼ããããBarracudaãå§ç¸®æ©è½ããµãã¼ãããæ°ãããã©ã¼ãããã§ããã©ãããã¢ã«ãã¡ãããé ã«Antelopeããã¼ã¸ã§ã³1ãBarracudaããã¼ã¸ã§ã³2ã¨ãããã¨ã®ããã§ãã½ã¼ã¹ãè¦ãã¨ãã¼ã¸ã§ã³26ã®Zebraã¾ã§ããã§ã«å®ç¾©ããã¦ãããã¨ã確èªã§ãã¾ãã
innodb_file_per_tableã¯å¾æ¥ãããããªãã·ã§ã³ã§ããã¼ãã«ãã¨ã«ãã¼ã¿ãã¡ã¤ã«ãåå²ããæ©è½ã§ããInnoDB Pluginã§ã¯ãã®åå²ããããã¼ã¿ãã¡ã¤ã«ãã¨ã«ãAntelopeã¨Barracudaã使ãåãããã¨ãã§ããããã«ãªã£ã¦ãã¾ãã
ãã®ã»ãcharacter_set_serverã¯ãWikipediaæ¥æ¬èªçã®ãã¼ã¿ãUTF-8ã§ãã®ã§ãããã¦utf8ã«ãã¦ãã¾ããã¾ããinnodb_autoextend_incrementã§InnoDBããã¼ã¿ãã¡ã¤ã«ã®æ¡å¼µãè¡ããµã¤ãºãæå®ãã¦ãã¾ããæ¬æ¥ã¯ãã£ã¨å¤§ããªå¤ãæå®ããã¹ããã®ã§ãããä»åã¯ãã¼ã¿ãµã¤ãºã極åæ£ç¢ºã«è¦ãããã«ããã¦1MBã¨ãã¦ãã¾ãã
ãã¼ã¿å§ç¸®ã®æé
ãã¼ã¿å§ç¸®ã¯ãã¼ãã«åä½ã«æå®ãã¾ããCREATE TABLEã¾ãã¯ALTER TABLEæã§ä»¥ä¸ã®ããã«å®ç¾©ãã¾ãã
CREATE TABLE `text` ( `old_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `old_text` mediumblob NOT NULL, `old_flags` tinyblob NOT NULL, PRIMARY KEY (`old_id`) ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8
ROW_FORMATã«COMPRESSEDãæå®ãããã¨ã§ãBarracudaãã©ã¼ãããã®å§ç¸®å½¢å¼ã«ãªãã¾ããInnoDB Pluginã«ããã¦ãROW_FORMATã¯ç¾å¨ä»¥ä¸ã®å種é¡ãæå®ã§ãã¾ãã
- REDUNDANTï¼MySQL 4.1ã¾ã§ã®ãã©ã¼ãããã§ãã
- COMPACTï¼MySQL 5.0以éã®ãã©ã¼ãããã§ããUTF-8æååã®æé©åãªã©ã«ãã£ã¦ãREDUNDANTããããã¼ã¿ãµã¤ãºãå°ãããªã£ã¦ãã¾ãã
- DYNAMICï¼InnoDB Pluginã®Barracudaãã©ã¼ããããç¨ãã¾ããããã¼ã¿å§ç¸®ã¯è¡ããªãå½¢å¼ã§ãã
- COMPRESSEDï¼InnoDB Pluginã®Barracudaãã©ã¼ããããç¨ãããã¼ã¿å§ç¸®ãè¡ãå½¢å¼ã§ãã
次ã®KEY_BLOCK_SIZEã¯ãå§ç¸®å¾ã«ãããInnoDBã®ãã¼ã¸ãµã¤ãºãæå®ãããã®ã§ããããã©ã«ãã¯8KBã§ã1ã2ã4ã8ã16KBããé¸ã¶ãã¨ãã§ãã¾ããInnoDBã¯ãã¨ãã¨ãã¼ã¸ãµã¤ãºã16KBåºå®ã«ãªã£ã¦ãã¦ãã®ãã¼ã¸åä½ã«ãã£ã¹ã¯I/Oãªã©ã®ãã¼ã¿ç®¡çãè¡ã£ã¦ããã®ã§ãããBarracudaãã©ã¼ãããã®å§ç¸®å½¢å¼ã§ã¯ãã¼ã¸ãµã¤ãºããã¼ãã«ãã¨ã«å¯å¤ã«ãªã£ã¦ãã¾ãã
ãã¼ã¿å§ç¸®ã®ä»çµã¿
ãã¼ã¿å§ç¸®ã®ä»çµã¿ã«ã¤ãã¦è¦ã¦ããã¾ããããInnoDB Pluginã®ãã¼ã¿å§ç¸®ã¯zlibã©ã¤ãã©ãªãç¨ãã¦å®è£ ããã¦ãã¾ããã¤ã¾ãZIPãgzipã¨åãDeflateã¢ã«ã´ãªãºã ã«ããå§ç¸®ãè¡ããã¦ããã®ã§ã(Deflateã¢ã«ã´ãªãºã ã«ã¤ãã¦ã¯ããããããã¨ã«è©³ç´°ãªè§£èª¬è¨äºãããã¾ã)ãããã¯é常ã«çããå®è£ ã§ããä½ãçããã®ãã¨ããã¨ããã®ãããªæ®éã®ãã¼ã¿å§ç¸®ããã¼ã¿ãã¼ã¹å´ã®æ©è½å¶éãªãã«å®ç¾ãã製åããç§ã¯ä»ã¾ã§è¦ããã¨ãããã¾ãããä»ã®è£½åã«ããããã¼ã¿å§ç¸®æ©è½ã¯ããã®ã»ã¨ãã©ã以ä¸ã®ããã«ä½ãããã®å¶éãæ±ãã¦ãã¾ãã
- Oracle Advanced Compressionï¼ä¸ã¤ã®ãã¼ã¿ã»ãããã¯å ã§éè¤ããåå¤ãçãã¨ããå®è£ ã«ãªã£ã¦ãã¾ãããã¼ã¿ã»ã¦ã§ã¢ãã¦ã¹ã«ç¨ãããããããªéæ£è¦åããããã¼ãã«ã«ããã¦ãåãåå¤ãé »åºããã¨ããåæã«ãã¨ã¥ããæ©è½ã§ãã(åèè³æ(PDF))
- MySQL myisampackï¼ãããã³ç¬¦å·åã«ããå§ç¸®ãè¡ã£ã¦ãã¾ããããã¼ãã«ãèªã¿åãå°ç¨ã«ãªãã¨ããå¶éãããã¾ãã
- MySQL ARCHIVEã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ï¼zlibã«ããå§ç¸®ãè¡ã£ã¦ãã¾ãããSELECTã¨INSERTããã§ããªãã¨ããå¶éãããã¾ãã
InnoDB Pluginã®ãã¼ã¿å§ç¸®æ©è½ã«ã¯ãã®ãããªå¶éã¯ãªããå§ç¸®ããããã¼ãã«ã«å¯¾ãã¦æ®éã«SELECT/INSERT/UPDATE/DELETEãè¡ããã¨ãå¯è½ã§ãã
ãã¼ã¿å§ç¸®ã¯InnoDBã®ãã¼ã¸åä½ã«è¡ããã¾ããInnoDBã¯åãã¼ã¸16KBã®å®¹éãããããããå§ç¸®ãã¦KEY_BLOCK_SIZEã®å¤§ããã®å§ç¸®ãã¼ã¸ã«æ ¼ç´ãã¾ããKEY_BLOCK_SIZEã¯ããã©ã«ãã§8KBã¨ãªã£ã¦ãããããã¯å
ã®ãã¼ã¸ãµã¤ãºã«å¯¾ãã¦ååã¨ãªãã¾ãã
ã±ã£ã¨è¦ã¦çåã沸ãã¦ããã¨æãã¾ãããååããå°ããå§ç¸®ã§ãã¦ãç¡é§ã£ã¦ãã¨ï¼ããåå以ä¸ã«å§ç¸®ã§ããªãã£ããã©ããªãã®ï¼ãã¨ãããã®ã§ãã
ä¸ã¤ç®ã®çåã«ã¤ãã¦ã¯ãçãã¯YESã§ãããã¼ã¿ãååããå°ããå§ç¸®ã§ãã¦ãå§ç¸®ãã¼ã¸ã«ééãã§ãã¦ãã¾ãã ãã§ããã¼ã¿ãã¡ã¤ã«ã®å®¹éã¨ãã¦ã¯ååããå°ããã¯ãªãã¾ãããã¤ã¾ããKEY_BLOCK_SIZEãæå®ããæç¹ã§æ大ã®å§ç¸®çã決ã¾ã£ã¦ãã¾ãã¨ãããã¨ã«ãªãã¾ãããã®ãã¨ãããä¾ãã°ãã¼ã¿ç¹æ§ä¸ãµã¤ãºã25%以ä¸ã«å§ç¸®ã§ããã¨æå¾
ã§ããå ´åã¯ãKEY_BLOCK_SIZEã«ã¯8KBã§ã¯ãªã4KBãæå®ããã¹ãã§ãã
ãã ããä¾å¤ãããã¾ããLOBãã¼ã¿ã«é¢ãã¦ã¯æ±ããç°ãªããããKEY_BLOCK_SIZEã8KBã§ãååããå°ããã§ããå ´åãããã¾ãã
InnoDB Pluginã®Barracudaãã©ã¼ãããã§ã¯ãLOBãã¼ã¿ã¯ãã¹ã¦ãªã¼ãã¼ããã¼ãã¼ã¸ã¨å¼ã°ããå
ã®ã¬ã³ã¼ãã¨ã¯å¥ã®ãã¼ã¸ã«æ ¼ç´ããã¾ããããã¦ãããã®ãã¼ã¿ã«å¯¾ããå§ç¸®ã¯ãInnoDBã®ãã¼ã¸åä½ã§ã¯ãªãLOBãã¼ã¿åä½ã§è¡ããã¾ããå
ã
16KBÃ2ãã¼ã¸ã使ç¨ãã¦ããLOBãã¼ã¿ã常ã«8KBÃ2ãã¼ã¸ã«ãªãã¨ããããã§ã¯ãªããå§ç¸®ãå¹ãããããã°8KBÃ1ãã¼ã¸ã«ãªããã¨ãããã®ã§ãã
Wikipediaã®textãã¼ãã«ã¯æ¬æãMEDIUMBLOBåã®ãããããããä»çµã¿ã«ãã£ã¦ååããããå°ãããµã¤ãºã¾ã§å§ç¸®ããã¦ãã¾ãã
äºã¤ç®ã®çåãå§ç¸®ãã¦ãååã¾ã§å°ããã§ããªãã£ãã¨ãã«ã©ããªããã§ããããã®å ´åInnoDBã¯å
ã®ãã¼ã¸ã2ã¤ã«åå²ãã¦å§ç¸®ãããç´ãã¾ãã
ãã®ãããã¼ãã«ã«ãã¾ãå§ç¸®ã®å¹ããªããã¼ã¿ãæ ¼ç´ãã¦ãã¾ãã¨ããã®åå²ï¼åå§ç¸®ãé »ç¹ã«èµ·ããã¾ãããã®ãããªãã¼ã¿ã¯å
ãã¼ã¿ã«æ¯ã¹ã¦ã»ã¨ãã©å°ãããªããªãã§ãããæ§è½ã大å¹
ã«è½ã¡ã¦ãã¾ããã¨ã«ãªãã¾ããå§ç¸®ããã¾ãKEY_BLOCK_SIZEã«åã¾ã£ãã®ãã©ããã¯ãinformation_schemaã®INNODB_CMPãã¼ãã«ã§ç¢ºèªã§ãã¾ãã
mysql> select * from information_schema.INNODB_CMP; +-----------+--------------+-----------------+---------------+----------------+-----------------+ | page_size | compress_ops | compress_ops_ok | compress_time | uncompress_ops | uncompress_time | +-----------+--------------+-----------------+---------------+----------------+-----------------+ | 1024 | 0 | 0 | 0 | 0 | 0 | | 2048 | 0 | 0 | 0 | 0 | 0 | | 4096 | 0 | 0 | 0 | 0 | 0 | | 8192 | 139654 | 77562 | 253 | 31046 | 21 | | 16384 | 0 | 0 | 0 | 0 | 0 | +-----------+--------------+-----------------+---------------+----------------+-----------------+ 5 rows in set (0.00 sec)
INNODB_CMPãã¼ãã«ã«ã¯ãpage_sizeãã¨ã«å§ç¸®ãè¡ã£ãåæ°(compress_ops)ãå§ç¸®ãç¡äºKEY_BLOCK_SIZEã«åã¾ã£ãåæ°(compress_ops_ok)ã示ããã¦ãã¾ãããã®ä¾ã§ã¯13ä¸åä¸6ä¸å以ä¸ãå§ç¸®ã«å¤±æãã¦ãããããªãæ績ãæªãã¨ãããã¨ãåããã¾ããå§ç¸®ã®å¤±æãå¤ããã¼ãã«ã«å¯¾ãã¦ã¯ãKEY_BLOCK_SIZEã大ããããã¨ããå§ç¸®ããããã¨ãã£ã対å¦ãå¿ è¦ã«ãªãã¾ãã
ããã¾ã§ã®ã¾ã¨ã
ããã¾ã§InnoDB Pluginã®ãã¼ã¿å§ç¸®æ©è½ã«ã¤ãã¦ããã®ä»çµã¿ã¨å§ç¸®å¹æãè¦ã¦ãã¾ãããzlibããã¼ã¿ãåå以ä¸ã®ãµã¤ãºã«å§ç¸®ãã¦ããããã¨ãæå¾
ãã¦KEY_BLOCK_SIZEãããã©ã«ã8KBã«ãªã£ã¦ãããå®éã«Wikipediaæ¥æ¬èªçã®ãã¼ã¿ããããååã«ã¾ã§å§ç¸®ããããã¨ã確èªãã¾ããã
ã¡ãã£ã¨é·æã«ãªã£ã¦ãã¾ã£ãã®ã§ä»åã¯ããã¾ã§ã«ãã¦ã次åã¯å§ç¸®ãã¼ãã«ã«å¯¾ããæ§è½ãè¦ã¦ããããã¨æãã¾ããZIPãgzipã使ã£ããã¨ãããã°ããã«åããã¾ããããã®æã®å§ç¸®ã»å±éã¢ã«ã´ãªãºã ã¯æ±ºãã¦å¦çãéãããã§ã¯ããã¾ããããã£ããã©ãã¾ã§æ§è½ãè½ã¡ãã®ããå®éã«è©¦ãã¦ã¿ããã¨æãã¾ãã
2009/07/05追è¨
æ§è½è©¦é¨ãè¡ãã¾ãããThe Art of Workï¼MySQL InnoDB Pluginã®ãã¼ã¿å§ç¸®æ©è½ æ§è½ç·¨ããã²ã覧ãã ããã