3.Static (Fixed-Length) 和 Dynamic Table 特點(diǎn) 3.1 Static (Fixed-Length) 特點(diǎn) 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. ## 這種存儲(chǔ)方式的優(yōu)點(diǎn)存儲(chǔ)非常迅速,容易緩存,出現(xiàn)故障容易恢復(fù)因?yàn)樾形挥诠潭ǖ奈恢茫蝗秉c(diǎn)是占用的空間比動(dòng)態(tài)表多。
3.2 Dynamic Table 特點(diǎn)
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. ## 這種存儲(chǔ)方式比靜態(tài)表占用空間少;但是,頻繁的更新和刪除記錄會(huì)生產(chǎn)鎖片。所以,需要定期執(zhí)行 OPTIMIZE TABLE or myisamchk -r 命令來改善性能;出現(xiàn)故障時(shí)恢復(fù)比較困難。