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

Fix my Indexes #178

Open
ChaelCodes opened this issue Jan 25, 2024 · 0 comments
Open

Fix my Indexes #178

ChaelCodes opened this issue Jan 25, 2024 · 0 comments
Labels
needs work this ticket is not fully groomed

Comments

@ChaelCodes
Copy link
Owner

I think there's some missing indexes that could really improve performance on our queries. There's one missing from friendships, but there are probably others.

How to test indexes, even without enough data.

In the database.yml, add the following to the appropriate environment (development/test).

  variables: {
    enable_seqscan: 'off'
  }

Then restart the rails server, and all future requests will attempt to use any index available before doing a seq scan.

Indexes Needed

  • Add index for [buddy_id, friend_id] on friendship

Query attempted in profile.friends

Makes a nested loop - check if it's cleaner after indexes?

    test_query = Profile.where(Profile.arel_table[:id].in(Arel.sql(<<-SQL.squish, profile_id: id)))
      SELECT CASE
        WHEN friendships.friend_id = :profile_id THEN friendships.buddy_id
        WHEN friendships.buddy_id = :profile_id THEN friendships.friend_id
      END AS profile_id
      FROM friendships
      WHERE (friend_id = :profile_id
      OR buddy_id = :profile_id)
      AND status = 0
    SQL
@ChaelCodes ChaelCodes added the needs work this ticket is not fully groomed label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs work this ticket is not fully groomed
Projects
None yet
Development

No branches or pull requests

1 participant