简体   繁体   English

数据库设计:每位用户每天的价值

[英]Database design: Value(s) per user per day

I'm setting up a system where for every user (1000+), I want to add a set of values every single day. 我正在建立一个系统,在该系统中,我想为每一位用户(超过1000名)每天添加一组值。

Hypotetically: A system where I can log when Alice and Bob woke up and what they had for dinner on the August 1st 2019 or 2024. 假设地:我可以在该系统上记录爱丽丝和鲍勃醒来的时间以及他们在2019年8月1日或2024年吃晚饭的时间。

Any suggestions on how to best structure the database tables? 关于如何最好地构造数据库表的任何建议?

A person table with a primary person ID? 具有主要人物ID的人物表? rows: n 行:n

A date table with a primary date ID? 具有主要日期ID的日期表? rows: m 行:m

And a personDate table the person ID and date ID as foreign keys? 一个personDate表中的人员ID和日期ID是外键吗? rows nxm 行nxm

I don't think u need a date table unless u want to use it to make specific queries easier. 我认为您不需要日期表,除非您想使用它来简化特定查询。 Such as left join against the date to see what days you are missing events. 如按日期左联接,以查看您缺少活动的日期。 Nevertheless, I would stick to the DATE or DATETIME as the field and avoid making a separate surrogate foreign key. 不过,我会坚持使用DATE或DATETIME作为该字段,并避免制作单独的代理外键。 It won't save any space and will potentially perform worse and will be more difficult to use for the developer. 它不会节省任何空间,并且性能可能会变差,并且对于开发人员而言将更加难以使用。

This seems simple and fine to me. 这对我来说似乎很简单。 I wouldn't worry too much about the performance based upon the number of elements alone. 我不会太担心仅基于元素数量的性能。 You can insert a billion records with no problem and that implies a very large site. 您可以毫无问题地插入十亿条记录,这意味着站点很大。

Just don't insert records if the event didn't happen. 如果事件未发生,请不要插入记录。 In other words you want your database to grow in relation to the real usage. 换句话说,您希望数据库相对于实际使用量有所增长。 Avoid growth based upon phantom events and you should be okay. 避免因幻影事件而成长,你应该没事。

person
    person_id


action
    action_id

personAction
    person_id
    action_id
    action_datetime

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

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