Skip to content

Add reposts user created-at index#969

Merged
raymondjacobson merged 1 commit into
mainfrom
codex/reposts-user-created-at-index
Jun 22, 2026
Merged

Add reposts user created-at index#969
raymondjacobson merged 1 commit into
mainfrom
codex/reposts-user-created-at-index

Conversation

@raymondjacobson

Copy link
Copy Markdown
Member

Summary

  • add a concurrent partial covering index for /v1/users/:id/reposts pagination
  • index active reposts by (user_id, created_at DESC) and include repost_type / repost_item_id
  • keep endpoint SQL unchanged; this codifies the index that was manually applied and validated on prod

DB evidence

Live read-only analysis showed the existing plan could scan global reposts_new_created_at_idx and discard millions of unrelated rows for users whose reposts were not globally recent.

For heavy user 279392 before the index:

  • LIMIT 10 OFFSET 0: ~7.7s cold, skipped ~2.65M unrelated rows
  • LIMIT 100 OFFSET 0: ~1.35s warm, skipped ~4.51M unrelated rows
  • LIMIT 100 OFFSET 1000: ~1.30s warm, skipped ~4.52M unrelated rows

After applying reposts_user_created_at_active_idx, the planner used Index Only Scan using reposts_user_created_at_active_idx:

  • LIMIT 10 OFFSET 0: ~6.5ms
  • LIMIT 100 OFFSET 0: ~6.4ms
  • LIMIT 100 OFFSET 1000: ~35ms
  • fresh-heavy user 714646433 LIMIT 10 OFFSET 0: ~4.9ms

The live index was valid/ready/live and ~226 MB.

Test

  • go test ./api -run Test200UnAuthed -count=1

@raymondjacobson raymondjacobson merged commit 47c4673 into main Jun 22, 2026
5 checks passed
@raymondjacobson raymondjacobson deleted the codex/reposts-user-created-at-index branch June 22, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant