Archive引擎初探
生活随笔
收集整理的這篇文章主要介紹了
Archive引擎初探
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天研究了一下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
*************************** 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
轉載于:https://blog.51cto.com/chlotte/362209
總結
以上是生活随笔為你收集整理的Archive引擎初探的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 崩坏3模拟器用什么(崩坏3模拟器)
- 下一篇: 在拉萨卖家具赚钱吗