【发布时间】:2020-03-05 16:12:20
【问题描述】:
我有一个简单的聊天模块,允许帐户创建多用户房间。
鉴于以下架构 - 是否可以创建一个查询来检查给定用户的房间是否已经存在?
如果此检查可能导致性能问题 - 您能否提出其他设计或方法?
示例数据:
- chat_id: 1, users: [1, 2, 3]
- chat_id: 2, users: [2, 3]
- chat_id: 3, users: [1]
- chat_id: 4, users: [5, 6]
所需查询:
Check if chat room for users [2, 3] exists => true, id: 2
Check if chat room for users [1, 2, 3] exists => true, id: 1
Check if chat room for users [2, 6] exists => false
Check if chat room for users [1, 2, 6] exists => false
我正在使用 postgres 11.2
编辑: 如果存在给定的组合,我也应该能够获取聊天 ID。
【问题讨论】:
标签: sql postgresql database-design chat junction-table