简体   繁体   English

多个客户表或大型总体表

[英]Multiple client tables or large overall table

I've recently taken over a project linking to a large MySQL DB that was originally designed many years ago and need some help. 我最近完成了一个链接到大型MySQL数据库的项目,该数据库最初是在多年前设计的,需要一些帮助。

Currently the DB has 5 tables per client that store their users information, transaction history, logs etc. However we currently have ~900 clients that have applied to use our services, with an average of 5 new clients applying weekly. 当前,数据库每个客户有5个表,用于存储他们的用户信息,交易历史记录,日志等。但是,我们目前已有约900个客户申请使用我们的服务,平均每周有5个新客户申请。 So the DB has grown to nearly 5000 tables and ever increasing. 因此,数据库已增长到近5000个表,并且还在不断增加。 Many of our clients do not end up using our services so their tables are all empty but still in the DB. 我们的许多客户最终都没有使用我们的服务,因此他们的表都是空的,但仍在数据库中。

The original DB designer says it was created this way so if a table was ever compromised it would not reveal information on any other client. 最初的数据库设计人员说,它是通过这种方式创建的,因此,如果一个表被破坏,它将不会在任何其他客户端上泄露信息。

As I'm redesigning the project in PHP I'm thinking of redesigning the DB to have an overall user, transaction history, log etc tables using the clients unique id to reference them. 在重新设计PHP项目时,我正在考虑重新设计数据库,以使用客户端的唯一ID来引用总体表,事务历史记录,日志等表。

Would this approach be correct or should the DB stay as is? 这种方法是正确的还是数据库应该保持原样?

Could you see any possible security / performance concerns 您能看到任何可能的安全/性能问题吗?

Thanks for all your help 感谢你的帮助

You should redesign the system to have just five tables, with a separate column identifying which client the row pertains to. 您应该重新设计系统,使其只有五个表,并在单独的列中标识该行与哪个客户端有关。 SQL handles large tables well, so you shouldn't have to worry about performance. SQL可以很好地处理大表,因此您不必担心性能。 In fact, having many, many tables can be a hinderance to performance in many cases. 实际上,在许多情况下,拥有许多表可能会妨碍性能。

This has many advantages. 这有很多优点。 You will be able to optimize the table structures for all clients at once. 您将能够一次为所有客户端优化表结构。 No more trying to add an index to 300 tables to meet some performance objective. 无需再尝试为300个表添加索引来满足某些性能目标。 Managing the database, managing the tables, backing things up -- all of these should be easier with a single table. 管理数据库,管理表,备份内容-使用单个表应该简化所有这些工作。

You may find that the database even gets smaller in size. 您可能会发现数据库甚至变得更小 This is because, on average, each of those thousands of tables has a half-paged filled at the end. 这是因为,平均而言,这数千个表中的每个表最后都有半页填充。 This will go from thousands of half-pages to just one. 这将从数千个半页变为仅一页。

The one downside is security. 一个缺点是安全性。 It is easier to put security on tables than one rows in tables. 与表中的一行相比,在表上放置安全性要容易得多。 If this is a concern, you may need to think about these requirements. 如果这是一个问题,您可能需要考虑这些要求。

This may just be a matter of taste, but I would find it far more natural - and thus maintainable - to store this information in as few tables as possible. 这可能只是一个口味问题,但是我发现将这种信息存储在尽可能少的表中更加自然,因此可以维护。 Also most if not all database ORMs will be expecting a structure like this, and there is no reason to reinvent that wheel. 而且,即使不是全部,大多数数据库ORM也会期望这样的结构,并且没有理由重新发明轮子。

From the perspective of security, it sounds like this project could be described as a web app. 从安全性的角度来看,听起来该项目可以描述为一个Web应用程序。 Obviously I don't know the realities of the business logic you're dealing with, but it seems like regardless of the table permissions all access to the database would be via the code base, in which case the app itself needs full permissions for all tables - nullifying any advantage of keeping the tables separated. 显然,我不知道您正在处理的业务逻辑的现实情况,但是似乎无论表权限如何,所有对数据库的访问都将通过代码库进行,在这种情况下,应用程序本身需要所有权限表格-消除了将表格分开的任何优势。

If there is a compelling reason for the security measures - say, different services that feed data into the DB independently of the web app, I would still explore ways to handle that authentication at the application layer instead of at the database layer. 如果有必要采取安全措施,例如,独立于Web应用程序将数据馈入DB的不同服务,我仍将探索在应用程序层而不是数据库层处理身份验证的方法。 It will be much easier to handle your security rules in that way. 以这种方式处理您的安全规则将容易得多。 Instead of having rules set in 5000+ different places, a single security rule of 'only let a user view a row of data if their user id equals the user_id column" is far simpler, easier to understand, and therefore far more maintainable (and possibly more secure). 而不是将规则设置在5000多个不同的位置,而是一个简单的安全规则“只允许用户查看其用户ID等于user_id列的数据行”,它更简单,更容易理解,因此更易于维护(并且可能安全)。

Different people approach databases in different ways. 不同的人以不同的方式处理数据库。 I am a web developer, so I view databases as the place to store my data and nothing more, as it's always a dedicated and generally single-purpose DB installation, and I handle all other logic at the application level. 我是一名Web开发人员,因此我将数据库视为存储数据的地方,仅此而已,因为它始终是专用的且通常是单一用途的DB安装,并且我在应用程序级别处理所有其他逻辑。 There are people who view databases as the application itself, who make far more extensive use of built-in security features for their massive, distributed, multi-user systems - but I honestly don't know enough about those scenarios to comment on exactly where that line should be drawn. 有些人将数据库视为应用程序本身,他们在其庞大的分布式多用户系统中更加广泛地使用内置安全功能-但老实说,我对这些方案的了解不足,无法确切地评论在哪里那条线应该画出来。

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

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