将大量相同的 MySQL 表转换为一个和大量指向它的视图?
我正在运行一个相当大的 WPMU(Wordpress 多用户、Wordpress 多站点)部署,它使用 4096 个数据库和 100k+ 表(显然,所涉及的模式有很多重叠)。
基本上,它是为每个博客一遍又一遍地复制相同的 20 个表,其中一些是空的,另一些包含几行到几百行。
我的计划(这省去了很多麻烦,但可能效率低下)是将所有相同模式的表合并到几个大的 InnoDB 表中,并用指向它们的 MySQL 视图替换旧的表,重写查询,以便相关行返回(将旧表名存储在新列中,然后使用视图将该列添加到查询 WHERE 子句中)。
问题是:这会在性能方面提供任何改进吗? (关键缓冲区效率、表缓存效率、索引)或者这只是蛇油,我应该采用更激烈的方法重写应用程序,这样我不需要视图,但查询直接进入大 InnoDB桌子?
I'm running a pretty big deployment of WPMU (Wordpress Multi-User, Wordpress Multisite) that uses 4096 databases and 100k+ tables (with a lot of overlap in what schema is concerned, obviously).
Basically it's the same 20-some tables replicated over and over again for each and every blog, some of them empty, others containing a few to a few hundred rows.
My plan (that saves lots of headaches but may prove inefficient) is to merge all same-schema tables into a few big-ish InnoDB tables and replace the old ones with MySQL VIEWs that point to them, rewriting the queries so that the relevant rows are returned (store the old table name in a new column and then using the view to add the column to the query WHERE clause).
The question is: would this provide ANY kind of improvement in what performance is concerned? (key buffer efficiency, table cache efficiency, indexing) or is this just snake oil and I should resort to a more drastic approach of rewriting the app in such a way that i don't need VIEWs but the queries go straight to the big InnoDB tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要进行您正在考虑的表合并。
考虑合并表的一些缺点:
使用或不使用视图不会对上述问题产生正面或负面影响。至少在 MySQL 中,视图基本上只是运行时的查询重写,它不会使用比直接查询基表更好或更差的索引。
我曾经与 Wordpress.com 的数据库架构师交谈过。他们在
数十数百台物理服务器上托管数百万个Wordpress 博客。早期,他们一开始将所有博客的数据合并到同一个表中,但随着规模的增长,他们发现操作难度变得太大。现在,他们将每个博客托管在一个单独的数据库中。I would recommend against doing the table merge you're thinking of.
Consider some of the downsides to merging the tables:
Using views or not using views doesn't affect the above issues positively or negatively. In MySQL at least, a view is basically just a query rewrite at runtime, it's not going to use indexes any better or worse than querying the base tables directly.
I once spoke with the database architect for Wordpress.com. They host millions of Wordpress blogs on
dozenshundreds of physical servers. In their early days, they started out with the data for all blogs merged into the same tables, but they found the operational difficulties became too great as they grew. Now they host each blog in a separate database.