简体   繁体   English

如何清除MySQL中MEMORY表中的开销(Data_free)?

[英]How do you clear overhead (Data_free) in a MEMORY table in MySQL?

I have a MEMORY table in MySQL for a live chat (maybe this isn't the best table type for this?), and deleting rows every night to keep the chat logs manageable cause overhead in the table. 我在MySQL中有一个MEMORY表用于实时聊天(也许这不是最好的表类型?),并且每晚删除行以保持聊天日志的可管理性导致表中的开销。 However, since you can't run OPTIMIZE on a MEMORY table, how do you get rid of the overhead ( Data_free in the show table status )? 但是,由于无法在MEMORY表上运行OPTIMIZE,如何摆脱开销( show table status中的Data_free )?

how do you get rid of the overhead? 你怎么摆脱开销?

You can force a table using the MEMORY/HEAP storage engine to recover residual space lost from deleted rows by ALTERing it, but not changing anything. 您可以使用MEMORY / HEAP存储引擎强制执行表,以通过更改它来恢复从已删除行中丢失的剩余空间,但不能更改任何内容。 eg 例如

ALTER TABLE my_table ENGINE=MEMORY;

It will re-write the table. 它会重写表格。 Backing that up with a quote from the documentation : 文档中的引用来支持它:

To free up the memory used by rows that have been deleted, use ALTER TABLE ENGINE=MEMORY to force a table rebuild. 要释放已删除的行所使用的内存,请使用ALTER TABLE ENGINE = MEMORY强制执行表重建。

EDIT 编辑

maybe this isn't the best table type for this? 也许这不是最好的表类型?

It doesn't sound like the ideal application of a MEMORY table in my opinion -- by and large, I consider it a legacy engine. 在我看来,它听起来并不像MEMORY表的理想应用 - 总的来说,我认为它是一个传统引擎。 Some food-for-thought 一些值得思考的食物

Firstly, MEMORY tables can't/don't use b-tree indexes (hash indexes only), so queries which could otherwise use an index for ORDERing or ranging (ie <, > operations) resort to sorting/filtering manually/exhaustively. 首先,MEMORY表不能/不使用b树索引(仅限哈希索引),因此否则可能使用索引进行ORDERing或测距(即<,>操作)的查询需要手动/详尽地进行排序/过滤。

Secondly, Innodb tables will reside in RAM if your innodb_buffer_pool is large enough, and works better with concurrent threads, so it often performs as good if not better than a MEMORY table for most applications. 其次,如果你的innodb_buffer_pool足够大,Innodb表将驻留在RAM中,并且对并发线程效果更好,因此对于大多数应用程序来说,如果不比MEMORY表更好,它通常表现得更好。

Thirdly, perhaps most importantly, if your MySQL is ever turned off, you'll lose all data in your table. 第三,也许最重要的是,如果您的MySQL被关闭,您将丢失表中的所有数据。 There are table truncation implications also if you're using replication. 如果您正在使用复制,还会有表截断的含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM