mysql - SQL 或 NoSQL 搜索?

标签 mysql sql database database-design nosql

假设我有一个拥有一定数量用户的网站,该网站具有以下三个显着特征:

1) 用户是网络的一部分。 (该站点包含多个网络。)

2) 用户是一定数量的其他站点成员的“联系人”。

3) 用户上传的个人文档可能会与某些联系人共享(不包括其他联系人)。

这样一来,用户的文档搜索对于每个用户都是唯一的,基于他或她的网络、联系人以及与该用户共享的其他文档。有什么可能的方法来解决这个问题——我是否需要为每个用户的每个搜索附加一个长的唯一 SQL 查询?我目前正在使用 MySQL 作为数据库——使用它是否足够,或者我是否需要在此处转向 NoSQL 选项以保持类似的非过滤搜索的性能?

最佳答案

我想到了几个问题来帮助回答这个问题:

  1. 您认为普通用户可以访问多少文档?网络中的许多文档是否会被共享以供所有人查看?
  2. 用户将如何找到文档,这些文档是什么样子的?他们只能通过共享它的联系人进行搜索吗?通过简单的标题匹配?他们能否对文档内容进行全文搜索?

根据这两个问题的答案,关系系统可以正常工作,我猜这是更可取的,因为您已经在使用 MySql。我认为您可以通过一些非常合理的查询在关系系统中找到单个用户的文档。

这是一个潜在的骨架模式

User
--all users in the system
UserId int
NetworkId int (Not sure if this is a 1 to many relationship)

Document
--all documents in the system
DocumentId int
UserId int -- the author
Name varchar 
StatusId -- perhaps a flag to indicate whether it is public or not, e.g. shared with everyone in the same network or shared with all contacts

UserDocumentLink
--Linking between a document and the contacts a user has shared the document with
DocumentId
ContactId

UserContact
--A link between a user and all of their contacts
ContactId -- PK identity to represent a link between two users
UserId -- User who owns the contact
ContactUserId --The contact user

这是一个潜在的“搜索”查询:

--documents owned by me
SELECT DocumentId
from Document where UserId = @userId

UNION

--documents shared with me explicitly
SELECT DocumentId
From UserContact uc
InnerJoin UserDocumentLink ucl on uc.ContactId = ucl.ContactId
Where 
uc.ContactUserId = @userId

UNION

--documents shared with me via some public status, using a keyword filter
Select DocumentId
From Document d 
inner join User u on d.UserId = u.UserId
where 
u.NetworkId = @userNetworkId
and d.status in ()
and d.Name like '%' + @keyword + '%'

我认为对架构设计更有影响力的要求可能是您的问题中没有提到的要求 - 用户将如何能够搜索文档?我们在这里谈论什么样的文件? MySql 不是全文搜索的好选择。

关于mysql - SQL 或 NoSQL 搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8409524/

相关文章:

mysql - 同时执行查询并在所有查询准备就绪后返回

Mysql - 将详细日期格式更改为 Y-m-d

mysql - 如何在 SQL 中添加/减去上一行?

mysql - 触发 SQL 插入和更新

c - 哪个能够容纳 1 亿条记录的嵌入式数据库具有高效的 C 或 C++ API

ios - SQL 错误 : Not an Error

php - 插入触发器错误后的MySQL PHP游戏

mysql - GROUP BY 具有时移的日期时间

mysql - 用于检索选票的 SQL 语法奇怪地遗漏了一些结果

php - Wordpress数据库查询多少次才算正常?