Add reposts user created-at index#969
Merged
Merged
Conversation
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.
Summary
/v1/users/:id/repostspagination(user_id, created_at DESC)and includerepost_type/repost_item_idDB evidence
Live read-only analysis showed the existing plan could scan global
reposts_new_created_at_idxand discard millions of unrelated rows for users whose reposts were not globally recent.For heavy user
279392before the index:LIMIT 10 OFFSET 0: ~7.7s cold, skipped ~2.65M unrelated rowsLIMIT 100 OFFSET 0: ~1.35s warm, skipped ~4.51M unrelated rowsLIMIT 100 OFFSET 1000: ~1.30s warm, skipped ~4.52M unrelated rowsAfter applying
reposts_user_created_at_active_idx, the planner usedIndex Only Scan using reposts_user_created_at_active_idx:LIMIT 10 OFFSET 0: ~6.5msLIMIT 100 OFFSET 0: ~6.4msLIMIT 100 OFFSET 1000: ~35ms714646433 LIMIT 10 OFFSET 0: ~4.9msThe live index was valid/ready/live and ~226 MB.
Test
go test ./api -run Test200UnAuthed -count=1