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

pgsql/migrations: add index on Vulnerability_Notification.deleted_at #280

Merged
merged 1 commit into from
Dec 6, 2016

Conversation

Quentin-M
Copy link
Contributor

searchNotificationAvailable never effectively use any indexes because:

  • notified_at < $1, where $1 is a recent timestamp, returns the
    majority of the table and therefore it is cheaper for PostgreSQL
    to use a sequential scan on the table.
  • there is no index for deleted_at IS NULL.
    However, when Clair has been running for long enough, the grand majority
    of rows (99%+) are expected to have a non-NULL deleted_at field. This
    commit adds a new index on this very field in order to fetch the
    remaining 1% in the blink of an eye.

In other words, instead of realizing a full table scan for each
searchNotificationAvailable query, we'll use the small branch of a new
index, reducing the total cost from over 30k to a mere 150 on a Clair
database that has already managed more than 1 000 000 notifications.

@Quentin-M Quentin-M added area/performance related to improving application performance component/database labels Dec 6, 2016
`searchNotificationAvailable` never effectively use any indexes because:
- `notified_at < $1`, where $1 is a recent timestamp, returns the
  majority of the table and therefore it is cheaper for PostgreSQL
  to use a sequential scan on the table.
- there is no index for `deleted_at IS NULL`.
However, when Clair has been running for long enough, the grand majority
of rows (99%+) are expected to have a non-NULL `deleted_at` field. This
commit adds a new index on this very field in order to fetch the
remaining 1% in the blink of an eye.

In other words, instead of realizing a full table scan for each
`searchNotificationAvailable` query, we'll use the small branch of a new
index, reducing the total cost from over 30k to a mere 150 on a Clair
database that has already managed more than 1 000 000 notifications.
@Quentin-M Quentin-M merged commit 1fcae6a into master Dec 6, 2016
@Quentin-M Quentin-M deleted the add_idx_deleted_at branch December 6, 2016 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/performance related to improving application performance
Development

Successfully merging this pull request may close these issues.

None yet

2 participants