Skip to content

Create index on issue_comments(user) and other foreign keys #35

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

Closed
simonw opened this issue May 1, 2020 · 3 comments
Closed

Create index on issue_comments(user) and other foreign keys #35

simonw opened this issue May 1, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented May 1, 2020

create index issue_comments_user on issue_comments(user)

I'm sure there are other user columns that could benefit from an index.

@simonw simonw added the enhancement New feature or request label May 1, 2020
@simonw
Copy link
Collaborator Author

simonw commented May 1, 2020

It sped up this query a lot - 2.5s down to 300ms:

select
  repos.full_name,
  json_object(
    'href', 'https://github.com/' || repos.full_name || '/issues/' || issues.number,
    'label', '#' || issues.number
  ) as issue,
  issues.title,
  users.login,
  users.id,
  issues.state,
  issues.locked,
  issues.assignee,
  issues.milestone,
  issues.comments,
  issues.created_at,
  issues.updated_at,
  issues.closed_at,
  issues.author_association,
  issues.pull_request,
  issues.repo,
  issues.type
from
  issues
  join repos on repos.id = issues.repo
  join users on issues.user = users.id
where
  issues.state = 'open'
  and issues.user not in (9599, 27856297)
  and not exists (
    select
      id
    from
      issue_comments
    where
      issue_comments.user = 9599
      and issues.id = issue_comments.issue
  )
order by
  issues.updated_at desc;

@simonw
Copy link
Collaborator Author

simonw commented May 1, 2020

This sped that query up even more - down to 4ms.

create index issue_comments_issue on issue_comments(issue);

@simonw
Copy link
Collaborator Author

simonw commented May 2, 2020

@simonw simonw changed the title Ccreate index on issue_comments(user) Create index on issue_comments(user) and other foreign keys May 2, 2020
@simonw simonw closed this as completed in 4a0c4ef May 2, 2020
simonw added a commit that referenced this issue May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant