MySQL在6.0中新增加了一個存儲引擎falcon,中文翻譯爲獵鷹,這個存儲引擎的開發顯然和innodb被oracle收購相關,也許在不久的將來,falcon將會完全會替代innodb。
在
mysql5.0和5.1中,支持事務的存儲引擎有兩種,是innodb和NDB(mysql
cluster)中使用,其中,ndb可以很容易得達到99.999%的可用性和超過10000
tps的高性能;而innodb主要應用在單服務器上或者是master/slave模式下。falcon和innodb在很多特性上類似,但是他們的架
構不同,特性上也有很多不同的地方,如下所示:
falcon和innodb的主要區別如下:
- falcon不使用cluster索引
- falcon不支持read uncommited 隔離級別
- falcon不支持語句級複製,這樣是爲了保證日誌和數據文件的一致性。
- falcon支持表空間的概念,innodb只有數據文件概念,但是數據和索引表空間不能分開。
- falcon支持在線備份,不過備份工具要到6.1的時候纔會發佈。
mysql> show engines;
+------------+---------+----------------------------------------------------------------+--------------+-----+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+-----+------------+
| FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| Falcon | YES | Falcon storage engine | YES | NO | YES |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+------------+---------+----------------------------------------------------------------+--------------+-----+------------+
9 rows in set (0.01 sec)
創建falcon的表很簡單,和創建其他表一樣:
mysql> CREATE TABLE tbl1 (id INTEGER AUTO_INCREMENT PRIMARY KEY, value VARCHAR(30)) ENGINE=Falcon;
Query OK, 0 rows affected (0.19 sec)
mysql> show create table tbl1;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tbl1 | CREATE TABLE `tbl1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`value` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=Falcon DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
當然,如果希望創建的表默認就是falcon存儲引擎,可以在my.cnf中加入“default-storage-engine=Falcon”。
我們測試一下事務:
mysql> insert into tbl1 (value) values(1);
Query OK, 1 row affected (0.01 sec)
mysql> rollback;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from tbl1;
Empty set (0.00 sec)
falcon的表空間管理:
對於一個falcon表的存儲,涉及到了3個表空間的,分別是:
- 一個未命名的表空間用來存儲系統表。
- falcon_user 用來存儲表數據的默認位置
- falcon_temporary 用來存儲臨時表
mysql> select * from FALCON_TABLES;
+-------------+------------+-----------+-------------+---------------+
| SCHEMA_NAME | TABLE_NAME | PARTITION | TABLESPACE | INTERNAL_NAME |
+-------------+------------+-----------+-------------+---------------+
| TEST | TBL1 | | FALCON_USER | TBL1 |
+-------------+------------+-----------+-------------+---------------+
我們也可以創建自己的表空間,命令如下:
mysql> create tablespace tbs2 add datafile 'data02' engine=falcon;
Query OK, 0 rows affected (0.13 sec)
從系統表中可以查到所有的表空間:
mysql> select * from FALCON_TABLESPACES;
+------------------+------------------+---------+
| TABLESPACE_NAME | TYPE | COMMENT |
+------------------+------------------+---------+
| FALCON_USER | FALCON_USER | |
| FALCON_TEMPORARY | FALCON_TEMPORARY | |
| tb1 | USER_DEFINED | |
| tbs2 | USER_DEFINED | |
+------------------+------------------+---------+
4 rows in set (0.02 sec)
從操作系統上看,數據目錄下多了一個data02的數據文件,size爲16k。我們也可以在新的表空間上創建表,命令如下:
mysql> create table tbl2 (id int) tablespace tbs2 engine=falcon;
Query OK, 0 rows affected (0.06 sec)
系統表中定義如下:
mysql> select * from FALCON_TABLES;
+-------------+------------+-----------+-------------+---------------+
| SCHEMA_NAME | TABLE_NAME | PARTITION | TABLESPACE | INTERNAL_NAME |
+-------------+------------+-----------+-------------+---------------+
| TEST | TBL1 | | FALCON_USER | TBL1 |
| TEST | TBL2 | | tbs2 | TBL2 |
+-------------+------------+-----------+-------------+---------------+
2 rows in set (0.00 sec)
用alter table命令可以將表移到另外的表空間中,例如:
mysql> alter table tbl2 tablespace tb1;
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> use information_schema
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from FALCON_TABLES;
+-------------+------------+-----------+-------------+---------------+
| SCHEMA_NAME | TABLE_NAME | PARTITION | TABLESPACE | INTERNAL_NAME |
+-------------+------------+-----------+-------------+---------------+espace
| TEST | TBL1 | | FALCON_USER | TBL1 |
| TEST | TBL2 | | tb1 | TBL2 |
+-------------+------------+-----------+-------------+---------------+
2 rows in set (0.00 sec)
如果要增加數據文件,目前看似乎還沒有實現,測試如下:
mysql> alter tablespace tb1 add datafile 'data01_1' engine=falcon;
ERROR 1178 (42000): The storage engine for the table doesn't support
上述語句目前只有NDB存儲引擎可以使用。
對於沒有任何對象的表空間,可以用drop tablespace命令進行刪除:
mysql> drop tablespace tbs2 engine=falcon;
Query OK, 0 rows affected (0.01 sec)
注意:這裏一定要加上engine=falcon關鍵字,否則會報語法錯誤。
刪除後,表空間相應的數據字典信息和數據文件都會被刪除。
如果表空間不爲空,刪除的時候會進行非空提示:
mysql> drop tablespace tb1 engine=falcon;
ERROR 1671 (HY000): Tablespace 'tb1' not empty
待續
參考文檔:
[url]http://dev.mysql.com/tech-resources/articles/falcon-in-depth.html[/url]
[url]http://dev.mysql.com/doc/refman/6.0/en/se-falcon.html[/url]