在MySQL数据库中具有LONGTEXT列的内存消耗 [英] Memory consumption of having a column LONGTEXT in MySQL database

查看:1079
本文介绍了在MySQL数据库中具有LONGTEXT列的内存消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MySQL数据库中创建一个日志表.其中一个字段将仅在大约5%的日志中使用,并将包含堆栈跟踪和其他供开发人员使用的冗长信息.我当时正在考虑使用LONGTEXT字段,但我想知道,即使此列在95%的行中为空,使用它也会使我的数据库增长非常快.

I'm creating a log table in my MySQL database. One of the field will be only used in approximately 5% of the logs and will contains stack traces and others lengthy informations for the developers. I was considering using the LONGTEXT field but I was wondering if using this would make my database grow very quickly, even if this column is empty in 95% of the rows.

所以我的问题很清楚,即使大多数行中的LONGTEXT列为空,是否也会消耗内存呢?例如,如果我改用TEXT并截断太长的字符串,我会在数据库上节省很多空间.

So my question in clear, is there a memory consumption of having a LONGTEXT column even when this column is empty in most of the rows? For example, if I use TEXT instead and truncate the strings that are too long, would I save a lot of space on the database.

重要的是要补充一点,随着时间的流逝会有很多日志.

It's important to add that there will be a LOT of logs over time.

谢谢!

推荐答案

尽管从一个MySQL差异到另一个差异,它略有不同,但总的来说,像LONGTEXT这样的BLOB类型的列本质上是可变长度的,并且在不存在时几乎不占用存储空间用过的.在NULL值的情况下,它们所需的空间甚至没有分配.

Although it varies slightly from one difference of MySQL to another, in general terms BLOB-type columns like LONGTEXT are inherently variable length and take up almost no storage when not used. The space needed by them isn't even allocated in the case of a NULL value.

对于您对扩展的担心,只有一种发现方法:生成大量的日志数据以测试您打算使用的任何模式.将其推得足够大以至于几乎要死了,然后获得一些关于它可以处理的指标.这将使您了解您的方法的可行性.

As for your concerns about scaling, there's only one way to find out: Generate a gigantic amount of log data to test any schema you're intending to use. Push it so full that it nearly dies, and then get some metrics on how much it can handle. That'll give you an idea of how viable your approach is.

这篇关于在MySQL数据库中具有LONGTEXT列的内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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