简体   繁体   English

加速只读MyISAM表

[英]Speed-up of readonly MyISAM table

We have a large MyISAM table that is used to archive old data. 我们有一个大的MyISAM表,用于存档旧数据。 This archiving is performed every month, and except from these occasions data is never written to the table. 此归档每月执行一次,除此之外,数据永远不会写入表中。 Is there anyway to "tell" MySQL that this table is read-only, so that MySQL might optimize the performance of reads from this table? 反正有“告诉”MySQL这个表是只读的,以便MySQL可以优化这个表的读取性能吗? I've looked at the MEMORY storage engine, but the problem is that this table is so large that it would take a large portion of the servers memory, which I don't want. 我看过MEMORY存储引擎,但问题是这个表太大了,它需要很大一部分服务器内存,这是我不想要的。

Hope my question is clear enough, I'm a novice when it comes to db administration so any input or suggestions are welcome. 希望我的问题很清楚,在数据库管理方面我是新手,所以欢迎任何意见或建议。

Instead of un-and re-compressing the history table: If you want to access a single table for the history, you can use a merge table to combine the compressed read-only history tables. 而不是取消压缩和重新压缩历史记录表:如果要访问历史记录的单个表,可以使用合并表来组合压缩的只读历史记录表。

Thus assuming you have an active table and the compressed history tables with the same table structure, you could use the following scheme: 因此,假设您有一个活动表和具有相同表结构的压缩历史表,您可以使用以下方案:

The tables: 表格:

compressed_month_1
compressed_month_2
active_month

Create a merge table: 创建合并表:

create table history_merge like active_month;
alter table history_merge 
    ENGINE=MRG_MyISAM 
    union (compressed_month_1,compressed_month_2);

After a month, compress the active_month table and rename it to compressed_month_3 . 一个月后,压缩active_month表并将其重命名为compressed_month_3 Now the tables are: 现在表格是:

compressed_month_1
compressed_month_2
compressed_month_3
active_month

and you can update the history table 你可以更新历史表

alter table history_merge 
    union (compressed_month_1, compressed_month_2, compressed_month_3);

You could use myisampack to generate fast, compressed, read-only tables . 您可以使用myisampack生成快速,压缩的只读表

(Not really sure if that hurts performance if you have to return most of the rows; testing is advisable; there could be a trade-off between compression and disk reads). (如果必须返回大部分行,不确定是否会损害性能;建议进行测试;压缩和磁盘读取之间可能存在折衷)。

I'd say: also certainly apply the usual: 我会说:也肯定适用平常:

  1. Provide appropriate indexes (based on the most used queries) 提供适当的索引(基于最常用的查询)
  2. Have a look at clustering the data (again if this is useful given the queries) 看一下聚类数据(如果在查询时这很有用)

Yes, you can compress the myisam tables. 是的,你可以压缩myisam表。

Here is the doc from 5.0 : http://dev.mysql.com/doc/refman/5.0/en/myisampack.html 这是来自5.0的文档: http//dev.mysql.com/doc/refman/5.0/en/myisampack.html

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

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