Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous query optimizations on appview #1766

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

devinivy
Copy link
Collaborator

@devinivy devinivy commented Oct 24, 2023

Three miscellaneous query optimizations here:

  • On the author feed posts_with_media filter, we simplify the condition that ensures only the user's own posts are displayed (i.e. not media in their reposts). By not referencing the post table here the query loosens, allowing it to do more filtering early in the query plan and make better use of the cursor index. Hoping to see lower IO on this query.
  • The query for notification skeleton was a bit bloated with joins and returned columns that went unused. By fetching notification record contents separate from the skeleton, the intent is to make simpler queries that postgres is able to cache more efficiently. Hoping to see lower IO on this query.
  • Fetching a single actor by handle occurs on many routes, and was hitting a degenerate case. Postgres would choose the gist trigram index originally used for typeahead search rather than the unique btree index on handle. The btree index is much quicker, so we've employed a little trick to ensure it's chosen instead of the trigram index.

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💎 these looks great!

@devinivy devinivy merged commit 825b2a0 into main Oct 24, 2023
@devinivy devinivy deleted the appview-misc-query-optimize branch October 24, 2023 17:07
mloar pushed a commit to mloar/atproto that referenced this pull request Nov 15, 2023
* split-up record fetching for notifs

* simplify query for author posts with media

* avoid hitting actor_handle_tgrm_idx when fetching actor by handle
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.

2 participants