麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數據庫 > 文庫 > 正文

MyISAM Table Storage Formats

2024-09-07 22:12:43
字體:
來源:轉載
供稿:網友
         MyISAM Table Storage Formats
  
        本文主要了解 Static (Fixed-Length) TABLE 和 Dynamic Table 以及對空格的處理。
  
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:[email protected]
本文鏈接: http://blog.itpub.net/26442936/viewspace-2062237/
########################################################################################
 

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精品久久久久久国产三级 | xxxxhd73国产 | 免费一级在线观看 | 欧美福利视频一区二区三区 | 水多视频在线观看 | 一级黄色免费电影 | 九九热在线免费观看视频 | 国产精品99久久久久久久 | 一区www| 一区二区三区在线观看av | 日韩999| free性欧美hd另类 | 国产亚洲美女精品久久久2020 | 亚洲成人欧美在线 | 久久草在线视频免费 | qyl在线视频精品免费观看 | 久久久免费观看完整版 | 激情视频在线播放 | 亚洲一区二区三区视频免费 | 午夜国内精品a一区二区桃色 | 国产精品成人亚洲一区二区 | 在线成人精品视频 | 91系列在线观看 | chinesehd天美原创xxxx| 青草av.久久免费一区 | 成人在线免费观看小视频 | 国产午夜精品久久久久 | 日韩字幕在线观看 | 欧美日韩在线视频一区二区 | 极品大长腿啪啪高潮露脸 | 国产精品视频二区不卡 | 久草在线精品观看 | 久久毛片免费观看 | 羞羞电影网 | 免费一区二区三区 | 中文字幕国产日韩 | 看免费毛片| 久久激情小视频 | 日本在线视频免费观看 | 色屁屁xxxxⅹ在线视频 | 男女羞羞视频在线免费观看 |