了解MyISAM数据记录结构 [英] Understanding MyISAM record structure

查看:179
本文介绍了了解MyISAM数据记录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解的MyISAM存储物理的记录和记录后,插入和删除记录它是如何保持其结构。我已阅读以下链接:

I am trying to understand how MyISAM physically store its records and how it maintains its structure after record insertion and record deletion. I have read the following link:

  • MyISAM Dynamic Data File Layout
  • MyISAM Record Structure

我要确保,如果我理解正确,请纠正我,如果这是不对的。

I want to make sure if I understand it correctly, please correct me if it is not right.


  • 删除标记决定是否记录被删除或没有被删除。

  • 记录头持有该行的列包含NULL值

  • 数据的长度是固定的。


  • 删除标记被替换BLOCK_DELETED块类型

  • 记录头保存数据的长度和长度未使用的数据的


  • 单个记录可以被分隔成溢流指针连接的多个区块。


  • 对于可变大小的记录,更改块类型BLOCK_DELETED

  • 将具有新删除的记录点previous指针到最后删除的记录维护所有已删除的记录中的双链表。然后,最后删除的记录的下一个指针指向刚删除的记录。

  • 对于固定大小的记录,只需更改删除标记为删除。 (不确定,如果他们使用双链表与固定大小的记录连接所有已删除的记录)


  • 如果不存在未使用的空间(被删除的记录),在该文件的末尾
  • 追加数据
  • 如果有适合新插入的记录未使用的空间,书写新的记录在那里。

  • 如果有未使用的空间,这远远比新插入的记录更大,分成两个纪录:新记录和删除的记录

  • 如果有未使用的空间比新插入的记录更小,写数据在那里,有溢出指针指向其他块不适于数据。


  • 如果用户更新存在较长的数据资料?请问MyISAM数据标志着纪录删除,并找到地方,适合新数据或简单地使用溢出指针指向不适于数据?

再重新盖上问题

我要确保,如果我理解正确,请纠正我,如果
  这是不对的。

I want to make sure if I understand it correctly, please correct me if it is not right.

其他问题


  • 难道是非常低效的,如果表以来已经记录结构删除和插入多次可能完全溢出指针和未使用的空间呢?

推荐答案

您在MyISAM数据有关的问题掌握的信息是正确的目标。不过,我想解决你的两个其他问题:

The information you have in the question concerning MyISAM is right on target. However, I would like to address your two additional questions:

如果用户更新存在较长的数据资料?请问MyISAM数据标志着纪录删除,并找到地方,适合新数据或简单地使用溢出指针指向不适于数据?

What if users update existed data with longer data? Will MyISAM marked the record as deleted and find place that fits the new data or simply use overflow pointer to point to unfitted data?

根据 图书

第10章存储引擎196页第7段说:

Chapter 10 : "Storage Engines" Page 196 Paragraph 7 says

有关具有可变长度的记录,该格式是更复杂的。第一个字节包含一个特殊的code描述记录的亚型。后续字节的含义与每个亚型而异,但共同的主题是,有一个包含记录的长度,未使用的字节的块中的数,空值指示标志,以及可能的指针字节序列记录的延续,如果记录不适合入previously创造空间,不得不被拆分。当一个记录被删除这可能发生,并进入其位置超过原来的大小为要插入一个新的。您可以通过研究switch语句in_mi_get_block_info得到不同的codeS的含义的细节()存储/ MyISAM数据/ mi_dynrec.c。

For records with variable length, the format is more complicated. The first byte contains a special code describing the subtype of the record. The meaning of the subsequent bytes varies with each subtype, but the common theme is that there is a sequence of bytes that contains the length of the record, the number of unused bytes in the block, NULL value indicator flags, and possibly a pointer to the continuation of the record if the record did not fit into the previously created space and had to be split up. This can happen when one record gets deleted, and a new one to be inserted into its place exceeds the original one is size. You can get the details of the meanings of different codes by studying the switch statement in_mi_get_block_info() in storage/myisam/mi_dynrec.c.

根据这一段,老纪获取与联动数据覆盖只有当新的数据插入无法适应pviously分配块的$ P $。这会导致许多臃肿行

Based on that paragraph, the old record gets overwritten with linkage data only if the new data to insert cannot fit in the previously allocated block. This can result in many bloated rows.

难道是非常低效的,如果该表已被删除,插入多次,因为记录结构可能完全溢出指针和未使用的空间呢?

Would it be very inefficient if the table has been deleted and inserted for many times since the record structure could potentially full of overflow pointers and unused space?

从我的previous答案,会有很多块有

From my previous answer, there would be lots of blocks that have


  • 的空间块

  • 记录长度

  • 未使用的字节的块数

  • NULL值指示标志

  • 可能是一个指向记录的延续,如果记录不适合入previously创造空间,不得不被拆分

这种记录链接将开始在每一个已被插入超大数据行的前面。这会增加一个MyISAM表 .MYD 文件速度非常快。

Such record links would start in the front of every row that have oversized data being inserted. This can bloat a MyISAM tables .MYD file very quickly.

一个MyISAM的默认行格式是动态的。当一个表是动态的,经历许多插入,更新和删除,这样的表需要用

The default row format of a MyISAM is Dynamic. When a table is Dynamic and experiences lots of INSERTs, UPDATEs, and DELETEs, such a table would need to optimized with

OPTIMIZE TABLE mytable;

有一个替代方法:开关表的行的格式固定。这样一来,所有的行具有相同的尺寸。这是你如何让固定行格式:

There is an alternative: switch the table's row format to Fixed. That way, all rows are the same size. This is how you make the row format Fixed:

ALTER TABLE mytable ROW_FORMAT=Fixed;

即使有一个固定的行格式,时间必须采取查找可用的记录,但时间是O(1)搜索时间(通俗地说,也需要相同的时间量,以找到一个可用的记录,不管有多少行的表或有多少删除的行有)。你可以绕过一步实现 concurrent_insert 如下:

将此到my.cnf

[mysqld]
concurrent_insert = 2

MySQL的重启不是必需的。只要运行

MySQL restart not required. Just run

mysql> SET GLOBAL concurrent_insert = 2;

这会导致所有的INSERT语句中去表背面头也不回的自由空间。

This would cause all INSERTs to go to the back of the table without looking for free space.


  • 插入,更新和DELETE会有所加快

  • 选择20-25%的速度

下面是我的一些帖子对被选择的行格式是固定的速度更快

Here are some of my posts on SELECT being faster for Row Formats being Fixed

  • May 03, 2012 : Which is faster, InnoDB or MyISAM?
  • Sep 20, 2011 : Best of MyISAM and InnoDB
  • May 10, 2011 : What is the performance impact of using CHAR vs VARCHAR on a fixed-size field?

在大多数情况下,当你运行 ALTER TABLE MYTABLE ROW_FORMAT =固定; ,该表可能增长80-100%。在 .MYI 文件(索引页的MyISAM表)也将增加以同样的速度。

In most cases, when you run ALTER TABLE mytable ROW_FORMAT=Fixed;, the table may grow 80-100%. The .MYI file (index pages for the MyISAM table) would also grow at the same rate.

如果你想速度MyISAM表,可以用更大的表活,就需要我的备选建议。如果你想节省为每个MyISAM表空间,离开该行格式为(动态)。你将不得不COM preSS与 OPTIMIZE TABLE MyTable的表。更频繁地使用动态表

If you want speed for MyISAM tables and can live with bigger tables, my alternate suggestions would be needed. If you want to conserve space for each MyISAM table, leave the row format as is (Dynamic). You will have to compress the table with OPTIMIZE TABLE mytable; more frequent with Dynamic tables.

这篇关于了解MyISAM数据记录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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