这是一个很好的使用方法吗?

时间:2022-09-06 18:47:13

Let us Imagine the Facebook homepage. There is a list of posts, I report a post, and that post is blocked.

让我们想象一下Facebook主页。有一个帖子列表,我报告一个帖子,这个帖子被屏蔽了。

So, in the PHP & Mysql backend, I would do something like.

在PHP和Mysql后端,我会做一些类似的事情。

  1. reported_posts = MySQL GROUP_CONCAT(reported_post_id) and fetch all my reported posts, store it in some cache like memcached or redis. This will give me a response with comma separated post_ids like 123, 234, 45
  2. reported_posts = MySQL GROUP_CONCAT(reported_post_id)并获取我报告的所有文章,并将其存储在一些缓存中,如memcached或redis。这会给我一个带有逗号分隔的post_id的响应,比如123、234、45
  3. Fetch all homepage_posts which are NOT IN (reported_posts). This will give us all the post_ids that needs to be in the homepage other than the posts, 123, 234 and 45, as I have used NOT IN.
  4. 获取不在(reported_posts)中的所有主页。这将为我们提供除了posts之外的所有主页需要的post_id, 123、234和45,正如我在NOT in中使用的那样。

The issue here is that, as time goes by, the reported_posts will keep on increasing(lets assume it increases 1000 ids). At that time, the NOT IN (reported_posts) clause will take a huge input. Will this effect the performance of the query? What is an alternative solution to this?

这里的问题是,随着时间的推移,reported_posts将继续增加(假设增加了1000个id)。那时,NOT IN (reported_posts)子句将接受大量输入。这会影响查询的性能吗?有什么替代方案吗?

I hope I could convey my doubt clearly, please let me know if it needs more clarification, I would edit as such. Thank you.

我希望我能清楚的表达我的疑问,如果需要更多的澄清请让我知道,我会这样编辑。谢谢你!

EDIT

编辑

The Reported post is not to be considered Globally, i.e. If I report the post, it should be Hidden only for me, and not for anyone else. So, it's also dependent on the account_id as well.

所报告的帖子不应在全球范围内被考虑,也就是说,如果我报告这个帖子,它应该只为我而不是其他人隐藏。它也依赖于account_id。

2 个解决方案

#1


3  

Assuming that reported_posts contains a list of user-specific blacklisted posts, it would be much better to do an exclusive left join and let the database handle everything:

假设reported_posts中包含特定于用户的黑名单文章列表,最好执行一个排他性的左连接,并让数据库处理所有内容:

SELECT *
FROM homepage_posts hp
LEFT JOIN
   reported_posts rp 
   ON hp.id = rp.post_id       
      AND rp.account_id = 123
WHERE 
   rp.id IS NULL

#2


0  

In mysql "IN" operator works fine if the column is indexed. If that column is not indexed then it impacts performance.

在mysql中,如果列被索引,“In”操作符可以正常工作。如果该列没有被索引,那么它将影响性能。

#1


3  

Assuming that reported_posts contains a list of user-specific blacklisted posts, it would be much better to do an exclusive left join and let the database handle everything:

假设reported_posts中包含特定于用户的黑名单文章列表,最好执行一个排他性的左连接,并让数据库处理所有内容:

SELECT *
FROM homepage_posts hp
LEFT JOIN
   reported_posts rp 
   ON hp.id = rp.post_id       
      AND rp.account_id = 123
WHERE 
   rp.id IS NULL

#2


0  

In mysql "IN" operator works fine if the column is indexed. If that column is not indexed then it impacts performance.

在mysql中,如果列被索引,“In”操作符可以正常工作。如果该列没有被索引,那么它将影响性能。