static-format.md 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#### 16.2.3.1 Static (Fixed-Length) Table Characteristics

Static format is the default for`MyISAM`tables. It is used when the table contains no variable-length columns ([`VARCHAR`](char.html),[`VARBINARY`](binary-varbinary.html),[`BLOB`](blob.html), or[`TEXT`](blob.html)). Each row is stored using a fixed number of bytes.

Of the three`MyISAM`storage formats, static format is the simplest and most secure (least subject to corruption). It is also the fastest of the on-disk formats due to the ease with which rows in the data file can be found on disk: To look up a row based on a row number in the index, multiply the row number by the row length to calculate the row position. Also, when scanning a table, it is very easy to read a constant number of rows with each disk read operation.

The security is evidenced if your computer crashes while the MySQL server is writing to a fixed-format`MyISAM`file. In this case,[**myisamchk**](myisamchk.html)can easily determine where each row starts and ends, so it can usually reclaim all rows except the partially written one.`MyISAM`表索引总是可以根据数据行重建。

笔记

固定长度行格式仅适用于没有[`斑点`](blob.html)要么[`文本`](blob.html)列。创建具有此类列的表,其中包含显式`ROW_FORMAT`子句不会引发错误或警告;格式规范被忽略。

静态格式表具有以下特征:

-   [`字符`](char.html)[`VARCHAR`](char.html)列被空格填充到指定的列宽,尽管列类型没有改变。[`二进制`](binary-varbinary.html)[`变量`](binary-varbinary.html)列填充`0x00`字节到列宽。

-   `空值`列在行中需要额外的空间来记录它们的值是否`空值`.每个`空值`column 需要额外的一位,四舍五入到最接近的字节。

-   很快。

-   易于缓存。

-   崩溃后易于重建,因为行位于固定位置。

-   除非您删除大量行并希望将可用磁盘空间返还给操作系统,否则无需重新组织。为此,请使用[`优化表`](optimize-table.html)要么[**myisamchk -r**](myisamchk.html).

-   通常比动态格式表需要更多的磁盘空间。

-   使用以下表达式计算静态大小行的预期行长度(以字节为单位):

    ```
    row length = 1
                 + (sum of column lengths)
                 + (number of NULL columns + delete_flag + 7)/8
                 + (number of variable-length columns)
    ```

    *`删除标志`*对于具有静态行格式的表,为 1。静态表在行记录中使用一个位作为标志,指示该行是否已被删除。*`删除标志`*动态表为 0,因为标志存储在动态行标题中。