今天研究了一下Archive引擎,发现其唯一的优点:在于节省磁盘空间,与Myisam引擎相比,节省近13倍多的磁盘空间,占用的磁盘空间少了,I/O占用也随之变小,不过,个人认为,在磁盘这么廉价的今天,Archive引擎也没有什么优势。
 
查看表的当前引擎为Myisam:
mysql> show table status like 'Sword_log'\G;
*************************** 1. row ***************************
           Name: Sword_log
         Engine: MyISAM
        Version: 10
     Row_format: Dynamic
           Rows: 7215544
 Avg_row_length: 166
    Data_length: 1203502908
Max_data_length: 281474976710655
   Index_length: 73538560
      Data_free: 0
 Auto_increment: 188213135
    Create_time: 2010-08-05 00:43:19
    Update_time: 2010-08-05 00:48:35
     Check_time: 2010-08-05 00:48:37
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.00 sec)
ERROR:
No query specified
 
 

mysql> desc Sword_log;
+------------+---------------+------+-----+-------------------+-----------------------------+
| Field      | Type          | Null | Key | Default           | Extra                       |
+------------+---------------+------+-----+-------------------+-----------------------------+
| id         | int(16)       | NO   | PRI | NULL              | auto_increment              |
| operate    | varchar(40)   | NO   |     | NULL              |                             |
| param      | varchar(2048) | NO   |     | NULL              |                             |
| createDttm | timestamp     | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| userId     | int(16)       | NO   |     | NULL              |                             |
| accId      | int(16)       | NO   |     | NULL              |                             |
| accName    | varchar(40)   | NO   |     | NULL              |                             |
| userName   | varchar(40)   | NO   |     | NULL              |                             |
+------------+---------------+------+-----+-------------------+-----------------------------+
8 rows in set (0.00 sec)
 
 
测试查询时间,Myisam引擎耗时2.31秒:
mysql> select count(*),id from Sword_log group by id having count(*)>1;
Empty set (2.31 sec)
 
 
把引擎改为Innodb格式,并再次查询,耗时2.62秒:
mysql> alter table Sword_log engine=innodb;
Query OK, 7215544 rows affected (1 min 56.15 sec)
Records: 7215544  Duplicates: 0  Warnings: 0
mysql> select count(*),id from Sword_log group by id having count(*)>1;
Empty set (2.62 sec)
 
 
 
把引擎改为Archive格式的的时候报错,个人感觉可能是mysql bug,删除自增及主键后可以改,不过这样应该没有什么实际意义了,靠应用来维护基本上是不可能的事情,更改为Archive之后,查询时间为1分38秒:

mysql> alter table Sword_log engine=archive;
ERROR 1022 (23000): Can't write; duplicate key in table '#sql-6d20_55'

mysql> alter table Sword_log change id id int(16);
Query OK, 7215544 rows affected (1 min 35.59 sec)
Records: 7215544  Duplicates: 0  Warnings: 0
mysql> alter table Sword_log drop primary key;
Query OK, 7215544 rows affected (2 min 25.19 sec)
Records: 7215544  Duplicates: 0  Warnings: 0
mysql> alter table Sword_log engine=archive;
Query OK, 7215544 rows affected (1 min 5.83 sec)
Records: 7215544  Duplicates: 0  Warnings: 0
mysql> select count(*) from Sword_log;
+----------+
| count(*) |
+----------+
|  7215544 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*),id from Sword_log group by id having count(*)>1;
Empty set (1 min 37.86 sec)
 
 
 
采用Myisam引擎Sword_log表所占用的磁盘空间:
[root@youyou yy]# du -sh Sword_log*
20K     Sword_log.frm
1.2G    Sword_log.MYD
94M     Sword_log.MYI
 
 
 
采用Archive引擎Sword_lg表所占用的磁盘空间:
[root@youyou xx]# du -sh Sword_log*
97M     Sword_log.ARZ
20K     Sword_log.frm