MySQL TEXT内存分配 [英] MySQL TEXT memory allocation

查看:451
本文介绍了MySQL TEXT内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道MySQL如何为"TEXT"或"BLOB"之类的字段分配磁盘空间

Anybody knows how MySQL allocates disk space for fields like "TEXT" or "BLOB"

例如,当我在"TEXT"列中插入10kb字符串时会发生什么?是分配了整个65kb的数据还是只有10kb?

For example, what happens when I insert 10kb string into "TEXT" column? Is the entire 65kb data allocated or only 10kb?

推荐答案

文档中对此进行了解释:

This is explained in the documentation: 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

可变长度字符串类型使用长度前缀加 数据.长度前缀需要1到4个字节,具体取决于 数据类型,并且前缀的值为L( 字符串).例如,存储MEDIUMTEXT值需要L 字节来存储值,再加上三个字节来存储值的长度 值.

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不会浪费.

So in short, the whole 65kb is not wasted.

这篇关于MySQL TEXT内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆