0

I have a scaling issue we are running into. I have a social media app - the user feed has posts from them, posts from the groups they are part of and posts where their groups are tagged in the comments (even if the group is private to the user).

Now my current model is posts (post id, group id , user id) and groupusermap (groupid, userid) and tags(postid, groupid). Now for the user feed, i get the posts from posts where userid = user or groupid in (groupusermap where userid = user) union tags where groupid in (groupusermap where userid = user). This is not scaling well and it takes a lot of time.

I thought of doing userpostmapping(postid, userid) - but this can hit a billion rows or more easily due to the config we face. How can we scale this efficiently? We are using PGSQL.

1
  • Could you please share the DDL for all tables and indexes involved, the query itself and the query plan for this query, using explain(analyze, verbose, buffers, settings. All in plain text, as an update of your question. And what PostgreSQL version do you use? Commented Jul 8 at 14:52

0

Browse other questions tagged or ask your own question.