简体   繁体   English

关联数据库或表的最佳方法?

[英]Best approach to relating databases or tables?

What I have: 我有的:

  • A MySQL database running on Ubuntu that maintains a large table of articles (similar to wordpress). 在Ubuntu上运行的MySQL数据库,维护着大量的文章表(类似于wordpress)。
  • Need to relate a given article to another set of data. 需要将给定的文章与另一组数据相关联。 This set of data will be fairly large. 这组数据将相当大。
  • There maybe various sets of data that will be related. 可能会有各种相关数据集。

The query: 查询:

  • Is it better to contain these various large sets of data within the same database of articles, which will have a large set of traffic on it? 最好将这些各种各样的大型数据集包含在同一个商品数据库中,这将对其产生大量访问量吗?

or 要么

  • Is it better to create different databases (on the same server) that relate by a primary key to the main database with the articles? 最好在主服务器上创建与文章相关的,通过主键关联的不同数据库(在同一服务器上)?

Put them all in the same DB initially, until you find that there is a performance issue. 首先将它们全部放在同一数据库中,直到发现性能问题。 Much easier than prematurely optimising. 比过早优化容易得多。

Modern RDBMS are very good at optimising data access. 现代的RDBMS非常擅长优化数据访问。

If you need to connect frequently and read both of the records, you should put in a the same database. 如果需要经常连接并读取两条记录,则应将其放在同一数据库中。 The server then won't have to run permission checks twice for each of your databases. 这样,服务器就不必为每个数据库运行两次权限检查。

If you have serious traffic, you should consider using persistent connection for that query. 如果流量很大,则应考虑对该查询使用持久连接。

If you don't need to read them together frequently, consider to put on different machine. 如果您不需要经常一起阅读它们,请考虑使用其他机器。 As the high traffic for the bigger database won't cause slow downs on the other. 由于较大数据库的高流量不会导致其他数据库的速度降低。

Different databases on the same server gives you all the problems of a distributed architecture without any of the benefits of scaling out. 同一台服务器上的不同数据库为您带来了分布式体系结构的所有问题,而没有任何横向扩展的好处。 One database per server is the way to go. 每台服务器一个数据库是一种方法。

When you say 'same database' and 'different databases related' don't you mean 'same table' vs 'different tables'? 当您说“相同的数据库”和“不同的数据库相关”时,您的意思不是“相同的表”还是“不同的表”?

if that's the question, i'd say: 如果那是问题,我会说:

  • one table for articles 一张桌子的文章
  • if these 'other sets of data' are all of the same structure, put them all in the same table. 如果这些“其他数据集”都具有相同的结构,则将它们全部放在同一张表中。 if not, one table per kind of data. 如果不是,则每种数据一张表。
  • everything on the same database 一切都在同一数据库上

if you grow big enough to make database size a performance issue (after many million records and lots of queries a second), consider table partitioning or maybe replacing the biggest table with a key/value store ( couchDB , mongoDB , redis , tokyo cabinet , [etc][6]), which can be a little faster than MySQL but a lot easier to distribute for performance. 如果你长大足够大,使数据库大小性能问题(后万条记录和大量的查询秒),考虑表分区或可能与一个键/值存储(代替最大表的CouchDBMongoDB的Redis的东京柜 , [etc] [6]),它的速度可能比MySQL快一点,但更容易分发以提高性能。

[6]:key-value store [6]:键值存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM