MyISAM Table Storage Formats
发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,MyISAM Table Storage Formats本文主要了解 Static (Fixed-Length) TABLE 和 Dynamic Table 以及对空格的处理。http://dev.m
千家信息网最后更新 2025年01月22日MyISAM Table Storage FormatsMyISAM Table Storage Formats
本文主要了解 Static (Fixed-Length) TABLE 和 Dynamic Table 以及对空格的处理。
http://dev.mysql.com/doc/refman/5.7/en/myisam-table-formats.html
1.创建和更改 MyISAM Table Storage Formats 语法
## table has no BLOB or TEXT ##
Create Table Engine
Create Table table_name ROW_FORMAT=FIXED;
Change Table Engine
Alter Table table_name ROW_FORMAT=DYNAMIC;
2.案例
2.1 创建 FIXED TABLE OF MyISAM Engine 并插入带有空格的字符,观察 FIXED TABLE OF MyISAM Engine 是如何处理空格的。
mysql> create table myisam_char(name char(10)) engine=myisam ROW_FORMAT=FIXED;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into myisam_char values('abcde'),('abcde '),(' abcde'),(' abcde ');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select name,length(name) from myisam_char;
+---------+--------------+
| name | length(name) |
+---------+--------------+
| abcde | 5 |
| abcde | 5 |
| abcde | 7 |
| abcde | 7 |
+---------+--------------+
4 rows in set (0.00 sec)
## FIXED TABLE OF MyISAM Engine 中字段都是非变长字段,数据会按照列的宽度定义补足空格,但是应用访问的时候并不会得到这些空格,这些空格在返回给应用之前已经去掉。
## 所以,开发需求本来就要保存字符后的空格,那就需要注意了。
mysql> show table status from test1 like 'myisam_char';
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
| myisam_char | MyISAM | 10 | Fixed | 4 | 11 | 44 | 3096224743817215 | 1024 | 0 | NULL | 2016-03-22 16:09:26 | 2016-03-22 16:09:35 | NULL | latin1_swedish_ci | NULL | row_format=FIXED | |
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
1 row in set (0.00 sec)
## SHOW TABLE STATUS 语法直接查看 MyISAM Table Storage Formats
2.2 更改 MyISAM Table Storage Formats
mysql> alter table myisam_char engine=myisam ROW_FORMAT=DYNAMIC;
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> show table status from test1 like 'myisam_char';
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
| myisam_char | MyISAM | 10 | Dynamic | 4 | 20 | 80 | 281474976710655 | 1024 | 0 | NULL | 2016-03-22 16:21:44 | 2016-03-22 16:21:44 | NULL | latin1_swedish_ci | NULL | row_format=DYNAMIC | |
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
1 row in set (0.00 sec)
mysql> insert into myisam_char values('ABCDE'),('ABCDE '),(' ABCDE'),(' ABCDE ');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select name,length(name) from myisam_char;
+---------+--------------+
| name | length(name) |
+---------+--------------+
| abcde | 5 |
| abcde | 5 |
| abcde | 7 |
| abcde | 7 |
| ABCDE | 5 |
| ABCDE | 5 |
| ABCDE | 7 |
| ABCDE | 7 |
+---------+--------------+
8 rows in set (0.00 sec)
3.Static (Fixed-Length) 和 Dynamic Table 特点
3.1 Static (Fixed-Length) 特点
Static-format tables have these characteristics:
CHAR and VARCHAR columns are space-padded to the specified column width, although the column type is not altered. BINARY and VARBINARY columns are padded with 0x00 bytes to the column width.
Very quick.
Easy to cache.
Easy to reconstruct after a crash, because rows are located in fixed positions.
Reorganization is unnecessary unless you delete a huge number of rows and want to return free disk space to the operating system. To do this, use OPTIMIZE TABLE or myisamchk -r.
Usually require more disk space than dynamic-format tables.
## 这种存储方式的优点存储非常迅速,容易缓存,出现故障容易恢复因为行位于固定的位置;缺点是占用的空间比动态表多。
3.2 Dynamic Table 特点
Dynamic-format tables have these characteristics:
All string columns are dynamic except those with a length less than four.
Each row is preceded by a bitmap that indicates which columns contain the empty string (for string columns) or zero (for numeric columns). This does not include columns that contain NULL values. If a string column has a length of zero after trailing space removal, or a numeric column has a value of zero, it is marked in the bitmap and not saved to disk. Nonempty strings are saved as a length byte plus the string contents.
Much less disk space usually is required than for fixed-length tables.
Each row uses only as much space as is required. However, if a row becomes larger, it is split into as many pieces as are required, resulting in row fragmentation. For example, if you update a row with information that extends the row length, the row becomes fragmented. In this case, you may have to run OPTIMIZE TABLE or myisamchk -r from time to time to improve performance. Use myisamchk -ei to obtain table statistics.
More difficult than static-format tables to reconstruct after a crash, because rows may be fragmented into many pieces and links (fragments) may be missing.
The expected row length for dynamic-sized rows is calculated using the following expression:
3
+ (number of columns + 7) / 8
+ (number of char columns)
+ (packed size of numeric columns)
+ (length of strings)
+ (number of NULL columns + 7) / 8
There is a penalty of 6 bytes for each link. A dynamic row is linked whenever an update causes an enlargement of the row. Each new link is at least 20 bytes, so the next enlargement probably goes in the same link. If not, another link is created. You can find the number of links using myisamchk -ed. All links may be removed with OPTIMIZE TABLE or myisamchk -r.
## 这种存储方式比静态表占用空间少;但是,频繁的更新和删除记录会生产锁片。所以,需要定期执行 OPTIMIZE TABLE or myisamchk -r 命令来改善性能;出现故障时恢复比较困难。
########################################################################################
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!【QQ交流群:53993419】
QQ:14040928 E-mail:dbadoudou@163.com
本文链接: http://blog.itpub.net/26442936/viewspace-2062237/
########################################################################################
本文主要了解 Static (Fixed-Length) TABLE 和 Dynamic Table 以及对空格的处理。
http://dev.mysql.com/doc/refman/5.7/en/myisam-table-formats.html
1.创建和更改 MyISAM Table Storage Formats 语法
## table has no BLOB or TEXT ##
Create Table Engine
Create Table table_name ROW_FORMAT=FIXED;
Change Table Engine
Alter Table table_name ROW_FORMAT=DYNAMIC;
2.案例
2.1 创建 FIXED TABLE OF MyISAM Engine 并插入带有空格的字符,观察 FIXED TABLE OF MyISAM Engine 是如何处理空格的。
mysql> create table myisam_char(name char(10)) engine=myisam ROW_FORMAT=FIXED;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into myisam_char values('abcde'),('abcde '),(' abcde'),(' abcde ');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select name,length(name) from myisam_char;
+---------+--------------+
| name | length(name) |
+---------+--------------+
| abcde | 5 |
| abcde | 5 |
| abcde | 7 |
| abcde | 7 |
+---------+--------------+
4 rows in set (0.00 sec)
## FIXED TABLE OF MyISAM Engine 中字段都是非变长字段,数据会按照列的宽度定义补足空格,但是应用访问的时候并不会得到这些空格,这些空格在返回给应用之前已经去掉。
## 所以,开发需求本来就要保存字符后的空格,那就需要注意了。
mysql> show table status from test1 like 'myisam_char';
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
| myisam_char | MyISAM | 10 | Fixed | 4 | 11 | 44 | 3096224743817215 | 1024 | 0 | NULL | 2016-03-22 16:09:26 | 2016-03-22 16:09:35 | NULL | latin1_swedish_ci | NULL | row_format=FIXED | |
+-------------+--------+---------+------------+------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+------------------+---------+
1 row in set (0.00 sec)
## SHOW TABLE STATUS 语法直接查看 MyISAM Table Storage Formats
2.2 更改 MyISAM Table Storage Formats
mysql> alter table myisam_char engine=myisam ROW_FORMAT=DYNAMIC;
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> show table status from test1 like 'myisam_char';
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
| myisam_char | MyISAM | 10 | Dynamic | 4 | 20 | 80 | 281474976710655 | 1024 | 0 | NULL | 2016-03-22 16:21:44 | 2016-03-22 16:21:44 | NULL | latin1_swedish_ci | NULL | row_format=DYNAMIC | |
+-------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+--------------------+---------+
1 row in set (0.00 sec)
mysql> insert into myisam_char values('ABCDE'),('ABCDE '),(' ABCDE'),(' ABCDE ');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select name,length(name) from myisam_char;
+---------+--------------+
| name | length(name) |
+---------+--------------+
| abcde | 5 |
| abcde | 5 |
| abcde | 7 |
| abcde | 7 |
| ABCDE | 5 |
| ABCDE | 5 |
| ABCDE | 7 |
| ABCDE | 7 |
+---------+--------------+
8 rows in set (0.00 sec)
3.Static (Fixed-Length) 和 Dynamic Table 特点
3.1 Static (Fixed-Length) 特点
Static-format tables have these characteristics:
CHAR and VARCHAR columns are space-padded to the specified column width, although the column type is not altered. BINARY and VARBINARY columns are padded with 0x00 bytes to the column width.
Very quick.
Easy to cache.
Easy to reconstruct after a crash, because rows are located in fixed positions.
Reorganization is unnecessary unless you delete a huge number of rows and want to return free disk space to the operating system. To do this, use OPTIMIZE TABLE or myisamchk -r.
Usually require more disk space than dynamic-format tables.
## 这种存储方式的优点存储非常迅速,容易缓存,出现故障容易恢复因为行位于固定的位置;缺点是占用的空间比动态表多。
3.2 Dynamic Table 特点
Dynamic-format tables have these characteristics:
All string columns are dynamic except those with a length less than four.
Each row is preceded by a bitmap that indicates which columns contain the empty string (for string columns) or zero (for numeric columns). This does not include columns that contain NULL values. If a string column has a length of zero after trailing space removal, or a numeric column has a value of zero, it is marked in the bitmap and not saved to disk. Nonempty strings are saved as a length byte plus the string contents.
Much less disk space usually is required than for fixed-length tables.
Each row uses only as much space as is required. However, if a row becomes larger, it is split into as many pieces as are required, resulting in row fragmentation. For example, if you update a row with information that extends the row length, the row becomes fragmented. In this case, you may have to run OPTIMIZE TABLE or myisamchk -r from time to time to improve performance. Use myisamchk -ei to obtain table statistics.
More difficult than static-format tables to reconstruct after a crash, because rows may be fragmented into many pieces and links (fragments) may be missing.
The expected row length for dynamic-sized rows is calculated using the following expression:
3
+ (number of columns + 7) / 8
+ (number of char columns)
+ (packed size of numeric columns)
+ (length of strings)
+ (number of NULL columns + 7) / 8
There is a penalty of 6 bytes for each link. A dynamic row is linked whenever an update causes an enlargement of the row. Each new link is at least 20 bytes, so the next enlargement probably goes in the same link. If not, another link is created. You can find the number of links using myisamchk -ed. All links may be removed with OPTIMIZE TABLE or myisamchk -r.
## 这种存储方式比静态表占用空间少;但是,频繁的更新和删除记录会生产锁片。所以,需要定期执行 OPTIMIZE TABLE or myisamchk -r 命令来改善性能;出现故障时恢复比较困难。
########################################################################################
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!【QQ交流群:53993419】
QQ:14040928 E-mail:dbadoudou@163.com
本文链接: http://blog.itpub.net/26442936/viewspace-2062237/
########################################################################################
空格
方式
特点
存储
字段
字符
故障
空间
语法
链接
应用
频繁
困难
优点
位置
动态
命令
地址
宽度
性能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
java数据库选择查询
冷箭计划软件开发
数据库复制引擎
网络技术社团活动方案
北京大型软件开发特点
网络安全法规专门立法
1999年工程软件开发
网络安全等级保护顶级指南
原神有没有分服务器
编程数据库怎么读
杭州市网络安全展
石家庄技术软件开发服务供应
刘冬国科大网络安全
进出口银行软件开发招聘
微信数据库开发商
设计工作者租用服务器
爱拼团软件开发
太原学软件开发在哪
软件开发新工具
网络安全领域存在哪些问题
公路bim软件开发
黑龙江数据库空投箱销售厂家
核糖体数据库使用
互联网科技贷款牌照
盈和软件开发
跨专业软件开发面试
北京智能广播系统服务器
python跨平台桌面软件开发
wn链接服务器失败
网络安全法自那天起施行