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 ldfv compound index #278

Merged
merged 1 commit into from
Dec 4, 2016
Merged

pgsql/migrations: add ldfv compound index #278

merged 1 commit into from
Dec 4, 2016

Conversation

jzelinskie
Copy link
Contributor

@jzelinskie jzelinskie commented Dec 4, 2016

This speeds up the SearchNotificationLayerIntroducingVulnerability query
by an order magnitude.

After adding this index and vacuuming the table, the following query changes from 570578.327 ms to 1239.984 ms execution time:

EXPLAIN ANALYZE WITH subquery AS (
  SELECT l.ID, l.name
  FROM Vulnerability_Affects_FeatureVersion vafv, FeatureVersion fv, Layer_diff_FeatureVersion ldfv, Layer l
  WHERE l.id >= $2
    AND vafv.vulnerability_id = $1
    AND vafv.featureversion_id = fv.id
    AND ldfv.featureversion_id = fv.id
    AND ldfv.modification = 'add'
    AND ldfv.layer_id = l.id
  ORDER BY l.ID
)
SELECT *
FROM subquery
LIMIT $3;

This speeds up the SearchNotificationLayerIntroducingVulnerability query
by an order magnitude.
@Quentin-M
Copy link
Contributor

LGTM.

Actually, I noticed yesterday that the query planner was taking bad decisions such as doing seq scans rather than index scans at few places where the index was present. It must have been due to the table not being properly analyzed, with PostgreSQL considering that the query will return > 5-10% of the total table.

Verified performance gain with the index and analyzed table.

@jzelinskie jzelinskie merged commit 2fe4a46 into quay:master Dec 4, 2016
@jzelinskie jzelinskie deleted the layerdiffindex branch December 4, 2016 17:06
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