gpt4 book ai didi

mysql - longtext 列如何存储在磁盘上?

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

我正在开发电子邮件支持系统。每个存储的电子邮件包含 from_emailsubjectdate、一些标志和邮件的内容。显然,邮件数量可能很大,我们的系统主要关注最近的邮件(例如,最近 14 天),而较旧的邮件被视为已存档。我们还想搜索、过滤某些标签等等。

对于电子邮件的 ListView ,我们不需要考虑 content 字段。我正在考虑两个选项,一个表中的所有数据,以及存储 LONGTEXT 电子邮件正文的单独表。

假设 SQL SELECT 字段不包含 content 字段,将它放在单独的表中是否更有效?显然,LONGTEXT 字段没有存储固定长度的行数据,但我想它可能是交错的,因此 ListView 必须获取的页面数更大。

我正在使用 MariaDB 5.5.25 和 InnoDB 引擎。

最佳答案

我在 MySQL 5.5 手册中找到了此信息,section 14.3.12.2. File Space Management

If [an InnoDB] row is less than half a page long, all of it is stored locally within the page. If it exceeds half a page, variable-length columns are chosen for external off-page storage until the row fits within half a page. For a column chosen for off-page storage, InnoDB stores the first 768 bytes locally in the row, and the rest externally into overflow pages. Each such column has its own list of overflow pages. The 768-byte prefix is accompanied by a 20-byte value that stores the true length of the column and points into the overflow list where the rest of the value is stored.

用更通俗的话说,如果你创建一个只有主键和长文本的表,如果长文本大于 8000 字节(半页),InnoDB 将拆分行。

我的建议是将长文本放在存储的电子邮件表行的末尾,因为 InnoDB 可能无论如何都会为长电子邮件拆分该行。

将所有固定长度的列放在行的开头,将可变长度的列放在行的末尾是一种很好的数据库做法。

关于mysql - longtext 列如何存储在磁盘上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17572059/

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