MySQL 的 RENAME TABLE 语句如何工作/执行?

发布于 2024-07-19 18:46:49 字数 306 浏览 3 评论 0原文

MySQL 有一个 RENAME TABLE 语句,它允许您更改表的名称。

说明书上提到

重命名操作是原子完成的,这意味着没有其他会话可以 在重命名运行时访问任何表

该手册没有(据我所知)说明此重命名是如何完成的。 是否创建了表的完整副本,并指定了新名称,然后删除了旧表? 或者 MySQL 是否在幕后做了一些魔法来快速重命名表?

换句话说,表的大小是否会影响 RENAME 表语句的运行时间。 是否有其他因素可能导致块的重命名显着阻塞?

MySQL has a RENAME TABLE statemnt that will allow you to change the name of a table.

The manual mentions

The rename operation is done atomically, which means that no other session can
access any of the tables while the rename is running

The manual does not (to my knowedge) state how this renaming is accomplished. Is an entire copy of the table created, given a new name, and then the old table deleted? Or does MySQL do some magic behind the scenes to quickly rename the table?

In other words, does the size of the table have an effect on how long the RENAME table statement will take to run. Are there other things that might cause the renaming of a block to significantly block?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中性美 2024-07-26 18:46:50

我相信MySQL只需要在存储过程中更改元数据和对表旧名称的引用——表中的记录数应该是无关紧要的。

I believe MySQL only needs to alter metadata and references to the table's old name in stored procedures -- the number of records in the table should be irrelevant.

苏璃陌 2024-07-26 18:46:50

除了更改元数据之外,它还会重命名关联的 .FRM 文件。 虽然他们可以声称这是一个“原子”操作,但这是 mysql_rename_tables 函数代码中的实际注释...

/* Lets hope this doesn't fail as the result will be messy */

=)

In addition to altering the metadata, it also renames the associated .FRM file. While they can claim it being an "atomic" operation, this is an actual comment in the code for the mysql_rename_tables function...

/* Lets hope this doesn't fail as the result will be messy */

=)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文