pgsql: use subquery to plan GetNotification query (#182)

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.
This commit is contained in:
Jimmy Zelinskie 2016-05-20 13:10:00 -04:00
parent be3d697dc4
commit da446b65d6

View File

@ -205,6 +205,7 @@ const (
WHERE name = $1` WHERE name = $1`
searchNotificationLayerIntroducingVulnerability = ` searchNotificationLayerIntroducingVulnerability = `
WITH subquery AS (
SELECT l.ID, l.name SELECT l.ID, l.name
FROM Vulnerability_Affects_FeatureVersion vafv, FeatureVersion fv, Layer_diff_FeatureVersion ldfv, Layer l FROM Vulnerability_Affects_FeatureVersion vafv, FeatureVersion fv, Layer_diff_FeatureVersion ldfv, Layer l
WHERE l.id >= $2 WHERE l.id >= $2
@ -214,7 +215,12 @@ const (
AND ldfv.modification = 'add' AND ldfv.modification = 'add'
AND ldfv.layer_id = l.id AND ldfv.layer_id = l.id
ORDER BY l.ID ORDER BY l.ID
LIMIT $3` )
SELECT *
FROM subquery
LIMIT $3;
`
// complex_test.go // complex_test.go
searchComplexTestFeatureVersionAffects = ` searchComplexTestFeatureVersionAffects = `