[英]What is the best approach for database design on large data per user?
I got a job to make a restaurant "survey" web app that will just track users status regarding to the restaurant (will be explained later) and if that restaurant is your favorite.我得到了一份餐厅“调查”web 应用程序的工作,该应用程序将仅跟踪有关餐厅的用户状态(将在稍后解释)以及该餐厅是否是您最喜欢的。 Pretty much that's all the data I have and need.这几乎就是我拥有和需要的所有数据。 I also have categories and subcategories but they aren't that much used.我也有类别和子类别,但它们用得不多。
So we are talking about 386 restaurants in total (with an option to add more).所以我们谈论的是总共 386 家餐厅(可以选择添加更多)。 After a sign-up every user can fill out the data and then save it for later use on the application.注册后,每个用户都可以填写数据,然后保存以供以后在应用程序中使用。 User can set one of the three status options (0 - never been there,1 - planning to go soon, 2 - went there) and they can also add to their favorites.用户可以设置三个状态选项之一(0 - 从未去过那里,1 - 计划很快到 go,2 - 去过那里),他们也可以添加到他们的收藏夹。
My current solution is this:我目前的解决方案是这样的:
So finally my question would be is this the right/optimal way of doing it.所以最后我的问题是这是正确/最佳的做法吗? At first I had an idea to initialize all of the 368 restaurants for every user that registers and then access them by index, because that way I would know that ID 0-367 is user 1, ID 367 - 735 is user two etc. But as you can see for only 10 users there are 3k+ records that will probably stay empty/null.起初我有一个想法,为每个注册的用户初始化所有 368 家餐厅,然后通过索引访问它们,因为这样我就知道 ID 0-367 是用户 1,ID 367 - 735 是用户二等。但是如您所见,只有 10 个用户有 3k+ 条记录可能会保持为空/空。
On the other hand my goal with this current implementation was to divide the work on frontend and backend because the restaurant data is static but I'm concerned when/if the records count reaches lets say million/10 million.另一方面,我当前实现的目标是划分前端和后端的工作,因为餐厅数据是 static,但我担心记录数何时/是否达到让我们说百万/1000 万。 In that case all of the records would be scattered around and someone could have a record on ID 4 and then on ID 904,302.在那种情况下,所有记录都将分散在各处,并且某人可能在 ID 4 上有记录,然后在 ID 904,302 上有记录。
Here is the current table that I use:这是我使用的当前表:
I should note that I made index on every page and tried to optimize it as much as possible.我应该注意,我在每个页面上都做了索引,并尽可能地优化它。
This doesn't sound like a lot of data.这听起来不像是很多数据。
Just keep each status record for each user and each restaurant.只需保留每个用户和每个餐厅的每个状态记录。 The timing of the status change is probably much more important than you realize.状态更改的时间可能比您意识到的重要得多。 There might be other information that you want as well.您可能还需要其他信息。 Perhaps someone who has never been to a restaurant has heard something about it and you want to include that.也许从未去过餐厅的人听说过这家餐厅,而您想将其包括在内。
Then, summarize the data as you need from the transactions.然后,根据需要从交易中汇总数据。
This is flexible for adding restaurants and adding users.这对于添加餐厅和添加用户是灵活的。 If you end up with zillions of restaurants and zillions of users, you can think about how to optimize any reporting that you want done.如果您最终拥有无数家餐厅和无数用户,您可以考虑如何优化您想要完成的任何报告。 In the meantime, indexes on a per-restaurant and per-user basis are probably sufficient.与此同时,基于每个餐厅和每个用户的索引可能就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.