0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLのvarchar

0
Posted at

5.3.3 non-NULL Variable-Length Array
non-NULL Variable-Length Array是记录体中非空变长字段的实际长度数组,并标识该字段是否行外存储。由于NULL字段在Compact格式中长度必为0,并且可以在Nullable Bitmap中判断,因此不用存储。变长字段包括varchar、varbinary、text和blob等,如表t1的变长字段包括c2、c4、c5、c7和c8,若这些字段在记录上不是null,那么会使用1~2字节来保存其实际长度。

另外,当记录的总长度超过页面大小的一半(一般为8000字节左右),记录就需要挑选几个最大的变长字段实施行外存储,直到行内记录总长度小于8000字节。值得注意的是,不仅仅是blob或text字段会导致行外存储,varchar和varbinary字段同样会发生。

因此,非null变长字段长度的意义为:

  1. 若行外存储

最高位(第15位)总是1,表示使用两字节表示长度
次高位(第14位)为1,表示行外存储
剩余14位(0~13)表示行内存储使用的长度,Compact行格式是768字节前缀+20字节行外指针。而Dynamic行格式仅包含20字节行外指针。行外字段真实长度记录在行外页中。
2. 若行内存储

若字段定义的最大长度小于等于255,用1个字节表示其长度。
若字段定义的最大长度大于255,但实际使用长度小于128,用1个字节表示其实际长度。
若字段定义的最大长度大于255,并且实际使用长度大于等于128或者若字段是大字段(blob、text等),用2字节表示其长度。
最高位(第15位)总是1
次高位(第14位)为0表示行内存储
剩余14位(0~13)表示真实长度。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?