feat: Add Postgres Schema, Indexes, and Feed Queries - #4
Merged
Conversation
Users, follows, and posts sit in 3NF with a composite author timeline index and keyset SQL. PostgresStore implements ActivityStore and runs the shared contract suite against PGlite.
Seed enough posts, ANALYZE, and EXPLAIN the author timeline as an index scan with no sort. Walk each followee through the same index with LATERAL. First page and keyed page are separate statements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Postgres now implements ActivityStore. Users, follows, and posts are 3NF tables with a unique handle index, a no-self-follow CHECK, and a composite (author_id, created_at DESC, id DESC) index. Author timelines and the home feed use two statements (first page vs keyed page) so a null cursor cannot force a generic plan. The home feed is CROSS JOIN LATERAL: each followee walks that index newest-first, then the outer query merges.
Same contract suite as the in-memory store. After ANALYZE, EXPLAIN on the author timeline is an Index Scan using posts_author_timeline_idx with no Sort. Tests run the SQL on PGlite. Any { query(sql, params) } client works, including node-postgres.
Closes #3