因為我正在做一個基於相對比較大的數據庫(70.000.000 records)的項目,所以我想知道MyISAM與Innodb那個存儲引擎的效率更高些。現在,我們用myISAM存儲驅動作幾個測試:首先,我們建2個只含有很少字段的表(包含1個首鍵,一個int型索引字段,一個char索引字段),分別為MyISM和Innodb存儲引擎: CREATE TABLE `jointable` ( `pk_id` int(11) NOT NULL auto_increment, `indexed_int` int(11) default NULL, `indexed_char` varchar(255) default NULL, `randchar` varchar(255) default NULL, PRIMARY KEY (`pk_id`), KEY `idx_indexed_int` (`indexed_int`), KEY `idx_indexed_char` (`indexed_char`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
然後,我們向裡注入250,000條數據。執行如下操作(每個操作前都重啟數據庫,均在置空數據緩存的前提下): -- Using the Primary key to join the tables SELECT COUNT(t1.randchar), COUNT(t2.randchar)FROM jointable t1 INNER JOIN jointable t2 ON t1.pk_id = t2.pk_id
-- Using the indexed integer column to join the tables SELECT COUNT(t1.randchar), COUNT(t2.randchar) FROM jointable t1 INNER JOIN jointable t2 ON t1.indexed_int = t2.indexed_int
-- Using the indexed char column to join the tables SELECT COUNT(t1.randchar), COUNT(t2.randchar) FROM jointable t1 INNER JOIN jointable t2 ON t1.indexed_char = t2.indexed_char
結果:
-- Results based on a 250.000 row recordset
__________________________________________________
| | Primary Key | Int Index | Char index |
| MyISAM | 3.09 sec | 21.45 sec | 7.95 sec |
| InnoDB | 1.01 sec | 18.48 sec | 19.09 sec |
__________________________________________________
分析:結果顯示,InnoDB在處理Int型數據的時候,執行效率明顯要比MyISAM高。處理字符索引的時候效率要差些。所以,建議大型數據庫使用InnoDb.