MYSQL TINYBLOB 与 LONGBLOB

发布于 2024-12-28 06:34:52 字数 281 浏览 3 评论 0原文

这是我上一个问题的后续问题:Blob 和存储要求

我使用 SHOW TABLE STATUS< 进行了一些测试/code>,发现实际使用的总磁盘空间仅取决于上传到数据库的实际文件的大小,而不取决于列的类型(例如 TINYBLOB 或 LONGBLOG)。

那么,如果情况并非如此,那么当我们选择一种 BLOB 类型而不是另一种 BLOB 类型时,会有什么区别呢?

This is a follow up for my previous question: Blob and Storage Requirement

I did some testing using SHOW TABLE STATUS, and found out that the total disk space used actually only depends on the size of actual files uploaded to the database and not on the type (e.g. TINYBLOB or LONGBLOG) of the column.

So, if that's not the case then what difference does make when we choose one over the other of the BLOB types?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咋地 2025-01-04 06:34:52

每个大小的 blob 字段都会保留额外的字节来保存大小信息。 Longblob 使用 4+n 字节的存储空间,其中 n 是您要存储的 blob 的实际大小。如果您只存储(比如说)10 字节的 blob 数据,那么您将使用 14 字节的空间。

相比之下,tinyblob 使用 1+n 个字节,因此 10 个字节将占用 11 个字节的空间,节省了 3 个字节。

当仅处理少量记录时,3 个字节并不算多,但随着数据库记录数量的增加,节省的每个字节都是一件好事。

Each size of blob field reserves extra bytes to hold size information. A longblob uses 4+n bytes of storage, where n is the actual size of the blob you're storing. If you're only ever storing (say) 10 bytes of blob data, you'd be using up 14 bytes of space.

By comparison, a tinyblob uses 1+n bytes, so your 10 bytes would occupy 11 bytes of space, a 3 byte savings.

3 bytes isn't much when dealing with only a few records, but as DB record counts grow, every byte saved is a good thing.

你丑哭了我 2025-01-04 06:34:52

使用 BLOB 使您的大小与文件大小成正比,而不是像普通数据库字段那样与文件数量成正比(BLOB 不会在记录空间中分配 - 除了大小和文件数据的内部链接)
BLOB 类型之间的巨大差异来自允许的图像大小(请参阅链接)。
由于 BLOB(long) 在处理大图像时仅增加 3 个字节,我注意到大多数程序都使用 BLOB(long) - 当您将 3 个字节与 1M+ 字节的图像进行比较时,这是一个无关紧要的成本,程序员选择 BLOB(long)以避免随着创建的增长而重组数据库。

https://tableplus.com/blog/2019/10/ tinyblob-blob-mediumblob-longblob.html

Using BLOB make your size being proportional with the size of the files not with the number of the files as in normal database fields (BLOB is not allocated in the records space - except for size and an internal link to file data)
The big difference between BLOB types comes from the allowed size of the images (see link).
As BLOB(long) adds only 3 bytes more when working with large images, I noticed that most programs use BLOB(long) - it is an immaterial cost when you compare 3 bytes with 1M+ bytes for images, and programmers choose BLOB(long) to avoid restructuring the database as their creation grows.

https://tableplus.com/blog/2019/10/tinyblob-blob-mediumblob-longblob.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文