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的时候才会发布。
falcon在6。0以后被支持,要想查看当前版本是否支持falcon,可以用如下命令:
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 用来存储临时表
显然,我们刚刚创建的测试表tbl1应该位于falcon_user表空间,可以用相关的视图进行查看:
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]