mysql - 您会在父表中添加 owner_id 还是在子表中添加 is_owner?
问题描述
假设你有一张桌子
collection
id
name
和一张桌子
collection_collaborator
id
user_id
您会在父表中添加 owner_id 吗?
collection
id
name
owner_id
你会在子表上添加一个 is_owner 吗?
collection_collaborator
id
name
is_owner
解决方案
这个问题没有非黑即白的答案——实际上取决于您的业务需求和您自己的偏好。
这两种方法有一个明显的区别:owner_id
字段表示集合只能有一个所有者,而is_owner
标志允许单个集合有多个所有者。
The other deciding factor could be the reports on the data. If you have owner_id
field, then you can display the owner information for a collection without needing to join on the collaborator table. If you have lots of reports where you need the owner information, but do not need any other information around the collaborators, then owner_id
field can increase the performance of your queries.
推荐阅读
- logback - wildfly10 和 slf4j 和 logback 不起作用
- python - 在 pandas 或 numpy 中处理负无穷数
- significant-digits - 在 BlueSky Statistics 中设置小数位
- azure - 从 Azure Apim 的上下文中读取命名值
- ios - Swift:FCM 更改通知的声音
- jquery - 如何使用ajax将键值对发送到url
- javascript - 将 3 变为 1000,将 2 变为 100 - getFixedDecimalValue 函数
- matlab - 如何从 MATLAB 中的侦听器将数据写入文件?
- java - 我们如何在java8中的DoubleSummaryStatistics对象中自定义count、avg、sum、min和max的顺序
- stream - 基于 Dart/Flutter 中的过滤器更新流