如何在不加锁的情况下对 MySQL / MyISAM 表应用索引?
拥有一个生产表,其中一个非常关键的列(日期)缺少索引,是否有任何方法可以在不影响用户的情况下应用所述索引?
该表目前每秒大约进行 5-10 次插入,因此全表锁定已不再适用; 将这些插入重定向到替代表/数据库,即使是暂时的,也会被拒绝(出于公司政治原因)。 还有其他办法吗?
Having a production table, with a very critical column (date) missing an index, are there any ways to apply said index without user impact?
The table currently gets around 5-10 inserts every second, so full table locking is out; redirecting those inserts to alternative table / database, even temporarily, is also denied (for corporate politics reasons). Any other ways?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,MyISAM 不可能做到这一点。 无论如何,每秒 5-10 个 INSERT 的情况下,您应该考虑使用 InnoDB,除非您阅读的内容不多。
您是否使用复制(最好在主-主设置中使用)? (您应该!)如果是这种情况,您可以在备用服务器上
CREATE INDEX
,切换角色并执行相同的操作,然后切换回来。 请务必暂时禁用复制(使用主-主时)以避免将CREATE INDEX
复制到活动节点。根据您是否主要使用该表来归档日志或类似内容,您也可以研究一下归档存储引擎。
As far as I know this is not possible with MyISAM. With 5-10 INSERTs per second you should consider InnoDB anyways, unless you're not reading that much.
Are you using replication, preferable in a Master-Master Setup? (You should!) If that is the case, you could
CREATE INDEX
on the standby server, switch roles and do the same, then switch back. Be sure to disable replication temporarily (when using master-master) to avoid replicating theCREATE INDEX
to the active node.Depending on whether you use that table primarily to archive Logs or similar, you might aswell look into the Archive Storage engine.