将大量相同的 MySQL 表转换为一个和大量指向它的视图?

发布于 2024-12-03 08:56:46 字数 383 浏览 2 评论 0原文

我正在运行一个相当大的 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 技术交流群。

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

发布评论

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

评论(1

才能让你更想念 2024-12-10 08:56:46

我建议不要进行您正在考虑的表合并。

考虑合并表的一些缺点:

  • 合并表的索引数据结构将更大、更深,因此效率较低。
  • 积累大量数据但随后闲置的博客仍然会增加表和索引的总体大小,从而使查询花费更长的时间。
  • 备份和恢复个人博客更加困难。
  • 如果您想横向扩展,将单个博客移动到另一个数据库服务器会更困难。
  • 更难使用 SQL 权限来限制对给定博客的访问(尽管您可以将 SQL 权限应用于视图)。
  • 添加自定义功能(包括给定博客的架构更改)变得更加困难。

使用或不使用视图不会对上述问题产生正面或负面影响。至少在 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:

  • Index data structures for the merged tables will be larger and deeper, and therefore less efficient.
  • Blogs that accumulate a lot of data but then go idle still contribute to the overall size of the tables and indexes, and therefore make queries take longer.
  • Harder to back up and restore an individual blog.
  • Harder to move an individual blog to another database server if you want to scale out.
  • Harder to use SQL privileges to restrict access for a given blog (though you could apply SQL privileges to the views).
  • Harder to add custom features that include schema changes for a given blog.

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 dozens hundreds 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.

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