未加星标

Why we still need MyISAM (for read-only tables)

字体大小 | |
[数据库(mysql) 所属分类 数据库(mysql) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

TL;DR : we still need MyISAM and myisampack because it uses less space on disk (half of compressed InnoDB)!

In the previous post, I shared my experience with InnoDB table compression on a read-only dataset. In it, I claimed, without giving much detail, that using MyISAM and myisampack would result is a more compact storage on disk. In this post, I will share more details about this claim.

MyISAM is the original storage engine of mysql. It is a modified version of ISAM for MySQL (My- ISAM ). It was replaced by InnoDB as the default storage engine in MySQL 5.5 (first GA release in December 2010). MyISAM is sometimes qualified as "not under active development", unsupported, unmaintained, deprecated, end-of life, and/or other unflattering adjectives. There are even people writing about the end of MyISAM . However in some situations and even if it does not support good concurrency, neither transactions nor foreign keys, MyISAM (and myisampack) can still be very useful. The end of MyISAM would leave a gap in MySQL feature-set. Let's see why.

In the previous post , I described a replicated system storing thousands of read-only tables. Those tables are written as non-compressed InnoDB table on the master and they reach slaves via standard replication. After being written, those tables are converted locally (not writing to the binary logs) to compressed InnoDB tables . This post-compression significantly reduces the storage needed for this system.

MyISAM and myisampack could replace InnoDB table compression on this system. The tables would still be written on the master using the InnoDB storage engine (for replication crash safety), but MyISAM and myisampack would be used instead of InnoDB compression for reducing disk footprint. As compression is done on a copy of the table (atomically swapping/renaming tables when completed), the lack of transaction support in MyISAM is not a problem: if a crash happens during compression, the operation can be restarted from the beginning without losing any data. Also, as the tables are read-only, compressed MyISAM tables can be used (after packing a table using myisampack, the table becomes read-only).

We can use myisampack because our dataset is read-only !

In the previous post , I described a log table where I am keeping information about the size of each compression round. For testing MyISAM and myisampack, I used an extra slave where I added four fields to the compression log table: myisam_size , myisam_size2 , mypack_size and mypack_size2 . The structure of table becomes the following:

> show create table compression_logs\G *************************** 1. row *************************** Table: compression_logs Create Table: CREATE TABLE `compression_logs` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `schema_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL, `initial_size` bigint(20) unsigned NOT NULL, `state` enum([...]) NOT NULL DEFAULT 'copying', `copied_size` bigint(20) unsigned DEFAULT NULL, `kbs_8_size` bigint(20) unsigned DEFAULT NULL, `kbs_4_size` bigint(20) unsigned DEFAULT NULL, `kbs_2_size` bigint(20) unsigned DEFAULT NULL, `kbs_1_size` bigint(20) unsigned DEFAULT NULL, `final_size` bigint(20) unsigned DEFAULT NULL, `final_kbs` tinyint(4) DEFAULT NULL, `myisam_size` bigint(20) unsigned DEFAULT NULL, `myisam_size2` bigint(20) unsigned DEFAULT NULL, `mypack_size` bigint(20) unsigned DEFAULT NULL, `mypack_size2` bigint(20) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB 1 row in set (0.01 sec)

We need two fields for MyISAM and myisampack sizes because, contrarily to InnoDB that stores data in a single .ibd file, MyISAM and myisampack store data in two files: .MYD for the data and .MYI for indexes. I could have stored the sum of both values in a single field but this would have lost some information that could be useful in the future (feel free to ask me creative questions/queries on that data in the comments).

Before going further, let's look again at the InnoDB statistics for the MySQL instance analysed in the previous post:

> SELECT nb_tables, initial_gib, final_gib, -> ROUND(initial_gib / final_gib, 2) AS ratio -> FROM (SELECT COUNT(*) AS nb_tables, -> ROUND(SUM(initial_size) / POW(2,30), 2) AS initial_gib, -> ROUND(SUM(final_size) / POW(2,30), 2) AS final_gib -> FROM compression_logs) AS c; +-----------+-------------+-----------+-------+ | nb_tables | initial_gib | final_gib | ratio | +-----------+-------------+-----------+-------+ | 248670 | 20701.84 | 4566.50 | 4.53 | +-----------+-------------+-----------+-------+ 1 row in set (0.15 sec)

This MySQL instance:

contains 248,670 tables which would use 20.21 TiB of disk space with uncompressed but they are only using 4.45 TiB after compression so InnoDB table compression divides storage requirements by 4.53.

How would MyISAM and myisampack compare to above? To answer that question, I ran a script that, for each table:

takes a MyISAM copy of the table, saves the MyISAM table sizes in the log table ( .MYD and .MYI ), runs myisampack and myisamchk on the table, and saves the myisampack-ed sizes in the log table.

As shown by the query below and in average, InnoDB uncompressed is using 22% more disk space than MyISAM:

> SELECT nb_tables, initial_gib, myisam_gib, -> ROUND(initial_gib / myisam_gib, 2) AS ratio -> FROM (SELECT COUNT(*) AS nb_tables, -> ROUND(SUM(initial_size) / POW(2,30), 2) AS initial_gib, -> ROUND(SUM(myisam_size+myisam_size2) / POW(2,30), 2) AS myisam_gib -> FROM compression_logs) AS c; +-----------+-------------+------------+-------+ | nb_tables | initial_gib | myisam_gib | ratio | +-----------+-------------+------------+-------+ | 248670 | 20701.84 | 16906.99 | 1.22 | +-----------+-------------+------------+-------+ 1 row in set (0.14 sec)

As we have an average compression ratio of 4.53 on this dataset with InnoDB table compression, MyISAM alone is not very interesting. The query below shows more interesting results with myisampack:

> SELECT nb_tables, initial_gib, final_gib, mypack_gib, -> ROUND(initial_gib / mypack_gib, 2) AS r_mypack, -> ROUND(final_gib / mypack_gib, 2) AS r_i_vs_m -> FR

本文数据库(mysql)相关术语:navicat for mysql mysql workbench mysql数据库 mysql 存储过程 mysql安装图解 mysql教程 mysql 管理工具

主题: InnoDBSQLMySQLAUSUAUTUTRYRIM
分页:12
转载请注明
本文标题:Why we still need MyISAM (for read-only tables)
本站链接:http://www.codesec.net/view/561342.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mysql) | 评论(0) | 阅读(49)