在线重建InnoDB索引以防止超时?

时间:2010-01-18 15:34:39

标签: mysql oracle timeout indexing innodb

当我更新特别大的表时,更新超时,因为在索引重建时表被锁定。有没有办法重建索引ONLINE(即Oracle),以便更新不会超时?

3 个答案:

答案 0 :(得分:0)

简单回答:不,没有办法。

更复杂的答案:您可以通过使用基于语句的复制并首先将索引添加到从属服务器,然后将其作为主服务器来模拟在线索引添加。这就是人们使用http://mysql-mmm.org/等软件包的原因。

答案 1 :(得分:0)

{ "caption": "File", "mnemonic": "F", "id": "file", "children": [ { "command": "new_file", "caption": "New File", "mnemonic": "N" }, { "command": "prompt_open_file", "caption": "Open File…", "mnemonic": "O", "platform": "!OSX" }, { "command": "prompt_open_folder", "caption": "Open Folder…", "platform": "!OSX" }, { "command": "prompt_open", "caption": "Open…", "platform": "OSX" }, { "caption": "Open Recent", "mnemonic": "R", "children": [ { "command": "reopen_last_file", "caption": "Reopen Closed File" }, { "caption": "-" }, { "command": "open_recent_file", "args": {"index": 0 } }, { "command": "open_recent_file", "args": {"index": 1 } }, { "command": "open_recent_file", "args": {"index": 2 } }, { "command": "open_recent_file", "args": {"index": 3 } }, { "command": "open_recent_file", "args": {"index": 4 } }, { "command": "open_recent_file", "args": {"index": 5 } }, { "command": "open_recent_file", "args": {"index": 6 } }, { "command": "open_recent_file", "args": {"index": 7 } }, { "caption": "-" }, { "caption": "More Recent Files", "mnemonic": "F", "children": [ { "command": "open_recent_file", "args": {"index": 8 } }, { "command": "open_recent_file", "args": {"index": 9 } }, { "command": "open_recent_file", "args": {"index": 10 } }, { "command": "open_recent_file", "args": {"index": 11 } }, { "command": "open_recent_file", "args": {"index": 12 } }, { "command": "open_recent_file", "args": {"index": 13 } }, { "command": "open_recent_file", "args": {"index": 14 } }, { "command": "open_recent_file", "args": {"index": 15 } }, { "command": "open_recent_file", "args": {"index": 16 } }, { "command": "open_recent_file", "args": {"index": 17 } }, { "command": "open_recent_file", "args": {"index": 18 } }, { "command": "open_recent_file", "args": {"index": 19 } }, { "command": "open_recent_file", "args": {"index": 20 } }, ] }, { "caption": "-" }, { "command": "open_recent_folder", "args": {"index": 0 } }, { "command": "open_recent_folder", "args": {"index": 1 } }, { "command": "open_recent_folder", "args": {"index": 2 } }, { "command": "open_recent_folder", "args": {"index": 3 } }, { "command": "open_recent_folder", "args": {"index": 4 } }, { "command": "open_recent_folder", "args": {"index": 5 } }, { "command": "open_recent_folder", "args": {"index": 6 } }, { "command": "open_recent_folder", "args": {"index": 7 } }, { "caption": "-" }, { "caption": "More Recent Directories", "mnemonic": "D", "children": [ { "command": "open_recent_folder", "args": {"index": 8 } }, { "command": "open_recent_folder", "args": {"index": 9 } }, { "command": "open_recent_folder", "args": {"index": 10 } }, { "command": "open_recent_folder", "args": {"index": 11 } }, { "command": "open_recent_folder", "args": {"index": 12 } }, { "command": "open_recent_folder", "args": {"index": 13 } }, { "command": "open_recent_folder", "args": {"index": 14 } }, { "command": "open_recent_folder", "args": {"index": 15 } }, { "command": "open_recent_folder", "args": {"index": 16 } }, { "command": "open_recent_folder", "args": {"index": 17 } }, { "command": "open_recent_folder", "args": {"index": 18 } }, { "command": "open_recent_folder", "args": {"index": 19 } }, { "command": "open_recent_folder", "args": {"index": 20 } }, ] }, { "caption": "-" }, { "command": "clear_recent_files", "caption": "Clear Items" } ] }, ... (continued) 在线重建索引

  

OPTIMIZE TABLE对常规和分区的InnoDB表使用在线DDL,从而减少了并发DML操作的停机时间。由OPTIMIZE TABLE触发并由ALTER TABLE ... FORCE在后台执行的表重建已就位。排他表锁定仅在操作的准备阶段和提交阶段短暂进行。在准备阶段,将更新元数据并创建一个中间表。在提交阶段,将提交表元数据更改。

来源:https://dev.mysql.com/doc/refman/8.0/en/optimize-table.html

但是!我听说过很多事情,您不应该在InnoDB中重建索引,因为它们始终是最新的。 Google对此有所了解。

答案 2 :(得分:0)

pt-online-schema-change可用于优化表。 OPTIMIZE TABLE实际上是noop ALTER TABLE

pt-online-schema-change --alter "ENGINE=InnoDB" D=sakila,t=actor