Skip to content

Commit

Permalink
pgsql: use subquery to plan GetNotification query (#182)
Browse files Browse the repository at this point in the history
This change enables the query planner to wait and sort the result set of
our query rather than attempting to re-use the layer table's index for
the ORDER BY clause. Because the result set is always small, this makes
queries that were previous tens of seconds, now tens of milliseconds.
  • Loading branch information
jzelinskie committed May 20, 2016
1 parent 51f9c5d commit 5d8336a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions database/pgsql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,22 @@ const (
WHERE name = $1`

searchNotificationLayerIntroducingVulnerability = `
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
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
LIMIT $3`
)
SELECT *
FROM subquery
LIMIT $3;
`

// complex_test.go
searchComplexTestFeatureVersionAffects = `
Expand Down

0 comments on commit 5d8336a

Please sign in to comment.