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

Extremely frequent query #50

Open
erikgrinaker opened this issue Sep 7, 2013 · 1 comment
Open

Extremely frequent query #50

erikgrinaker opened this issue Sep 7, 2013 · 1 comment

Comments

@erikgrinaker
Copy link
Contributor

Variations of this query are run over 500.000 times per day, making up 92% of all database queries combined from all our apps. The average query duration is 0.134 seconds, which means our Grove workers are spending about 1250 minutes every day just waiting for this to return. If we could somehow cache it, or better yet, cache the data structured returned by the calling app, it should translate to huge savings.

SELECT
    "posts".*
FROM
    "posts"
WHERE
    "posts"."external_id" IN ('response_topic_bygdeposten_conversation_5340116' )
    AND "posts"."external_id" = 'response_topic_bygdeposten_conversation_5340116'
    AND (NOT deleted )
    AND (published OR published IS NULL )
LIMIT 1;
@atombender
Copy link
Contributor

You can improve that type of query slightly creating a partial index (reduces cost by 25%).

create index index_posts_on_realm_and_external_id_where_etc on posts (realm, external_id)
  where not deleted and (published or published is null);

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

No branches or pull requests

2 participants