gpt4 book ai didi

MySQL TEXT内存分配

转载 作者:可可西里 更新时间:2023-11-01 07:02:30 25 4
gpt4 key购买 nike

任何人都知道 MySQL 如何为“TEXT”或“BLOB”等字段分配磁盘空间

例如,当我将 10kb 的字符串插入“TEXT”列时会发生什么?是分配了整个 65kb 数据还是仅分配了 10kb?

最佳答案

这在文档中有解释:http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html

BLOB, TEXT              L + 2 bytes, where L < 2^16
MEDIUMBLOB, MEDIUMTEXT L + 3 bytes, where L < 2^24
LONGBLOB, LONGTEXT L + 4 bytes, where L < 2^32

Variable-length string types are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type, and the value of the prefix is L (the byte length of the string). For example, storage for a MEDIUMTEXT value requires L bytes to store the value plus three bytes to store the length of the value.

所以简而言之,整个 65kb 都没有浪费。

关于MySQL TEXT内存分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38968710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com