Comment

Comment by apavlo

From the documentation:

> Yet SQL does not provide a way of indexing queries that involve a JOIN. Social apps that want to query "what are all the posts of all the people I follow ordered in time" must design their own systems because SQL cannot index that query (SQL will need to load all of the posts of all the people you follow over all time, and sort them in memory!)

rough query but you get the idea

  CREATE MATERIALIZED VIEW follower_posts
    SELECT f.follower_id, p.post_id, p.author_id, p.created
      FROM followers AS f JOIN posts AS p
        ON f.followee_id = p.author_id;
  CREATE INDEX ON follower_posts (follower_id, created DESC);
Please read a textbook about databases before building your own.
parent apavlo 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton