克服 MyISAM 表中 2^32 行的 MySQL 限制
我想在 MySQL 中创建一个 MyISAM 表(尝试了 5.0.x 和 5.1.x 的各种版本),它允许超过 2^32 行。实现这一点的方法是让 MySQL 使用 8 字节而不是 4 字节行指针。
这里引用MySQL手册:
如果使用 --with-big-tables 选项构建 MySQL,行限制将增加到 1.844E+19 行。请参见第 2.3.2 节“典型配置选项”。 Unix 和 Linux 的二进制发行版是使用此选项构建的。
听起来很简单,对吧?但我尝试过 Linux x86_64 的各种二进制发行版,并且还使用“--with-big-tables”选项从源代码构建 MySQL。在每种情况下我仍然无法超出 2^32 的限制。我创建一个像这样的表:
CREATE TABLE big (col int) MAX_ROWS=1099511627776
当我检查表状态时,它说:
Create_options: max_rows=4294967295
我该如何做逃离32位炼狱?使用 InnoDB 可能会解决问题,但对于我正在运行的查询类型来说,它的执行速度要慢得多。
仅供参考,这是一个没有解决问题的重要参考:
I want to create a MyISAM table in MySQL (tried various versions of 5.0.x and 5.1.x) which allows more than 2^32 rows. The way to achieve this is to get MySQL to use 8-byte instead of 4-byte row pointers.
Here's a quote from the MySQL manual:
If you build MySQL with the --with-big-tables option, the row limitation is increased to 1.844E+19 rows. See Section 2.3.2, “Typical configure Options”. Binary distributions for Unix and Linux are built with this option.
Sounds simple, right? But I've tried various binary distributions for Linux x86_64, and also building MySQL from the source code with the "--with-big-tables" option. In every case I still can't get beyond the 2^32 limit. I create a table like thus:
CREATE TABLE big (col int) MAX_ROWS=1099511627776
And when I check the table status, it says:
Create_options: max_rows=4294967295
How do I escape 32-bit purgatory? Using InnoDB might solve the problem, but it performs a lot more slowly for the type of queries I'm running.
FYI, here's an important reference that didn't solve the problem:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己解决了这个问题,答案既简单又荒谬。
如果您在创建 MyISAM 表时忽略 MAX_ROWS 设置,则该表不会受到 2^32 行的限制。相反,最大行数由指针大小确定,指针大小本身由全局变量 myisam_data_pointer_size 确定。
默认情况下,在 Linux/Unix 上运行的现代 MySQL 版本中,myisam_data_pointer_size 为 6,导致固定行宽度表上的 2^48 行限制(或具有动态行的表上的 2^48 字节)。但您也可以使用以下方法更改它:
并使用以下方法检查它:
在具有固定宽度行的 MyISAM 表中,最大行数等于 (2^(8* myisam_data_pointer_size))-1,在指定时给出 myisam_data_pointer_size表创建。
I worked this out for myself, and the answer is both simple and absurd.
If you leave out the MAX_ROWS setting when creating a MyISAM table, then the table doesn't suffer from the 2^32 limit on rows. Instead the maximum number of rows is determined by the pointer size, which is itself determined by the global variable myisam_data_pointer_size.
By default, the myisam_data_pointer_size is 6 on modern builds of MySQL running on Linux/Unix, leading to a limit of 2^48 rows on tables with fixed row width (or 2^48 bytes on tables with dynamic rows). But you can also change it using something like:
And check it using:
In a MyISAM table with fixed width rows, the maximum number of rows is equal to (2^(8* myisam_data_pointer_size))-1, given myisam_data_pointer_size at the time of table creation.
如果您使用 --with-big-tables 选项编译 mysql,行限制将增加到 (2^32)^2。不幸的是,这是最高限制:)
If you are compiling mysql using --with-big-tables option, the row limitation is increased to (2^32)^2. Unfortunately this is the highest limit :)