pgsql: Reduce cost of GetNotification by 2.5
By delaying the Layer join to the very end, we can cut the query costs from 540,836 to 219,477. See Pull Request for details.
This commit is contained in:
parent
026f64aa82
commit
dc8f71024f
@ -211,22 +211,20 @@ const (
|
|||||||
WHERE name = $1`
|
WHERE name = $1`
|
||||||
|
|
||||||
searchNotificationLayerIntroducingVulnerability = `
|
searchNotificationLayerIntroducingVulnerability = `
|
||||||
WITH subquery AS (
|
WITH LDFV AS (
|
||||||
SELECT l.ID, l.name
|
SELECT ldfv.layer_id
|
||||||
FROM Vulnerability_Affects_FeatureVersion vafv, FeatureVersion fv, Layer_diff_FeatureVersion ldfv, Layer l
|
FROM Vulnerability_Affects_FeatureVersion vafv, FeatureVersion fv, Layer_diff_FeatureVersion ldfv
|
||||||
WHERE l.id >= $2
|
WHERE ldfv.layer_id >= $2
|
||||||
AND vafv.vulnerability_id = $1
|
AND vafv.vulnerability_id = $1
|
||||||
AND vafv.featureversion_id = fv.id
|
AND vafv.featureversion_id = fv.id
|
||||||
AND ldfv.featureversion_id = fv.id
|
AND ldfv.featureversion_id = fv.id
|
||||||
AND ldfv.modification = 'add'
|
AND ldfv.modification = 'add'
|
||||||
AND ldfv.layer_id = l.id
|
ORDER BY ldfv.ID
|
||||||
ORDER BY l.ID
|
)
|
||||||
)
|
SELECT l.id, l.name
|
||||||
|
FROM LDFV, Layer l
|
||||||
SELECT *
|
WHERE LDFV.layer_id = l.id
|
||||||
FROM subquery
|
LIMIT $3`
|
||||||
LIMIT $3;
|
|
||||||
`
|
|
||||||
|
|
||||||
// complex_test.go
|
// complex_test.go
|
||||||
searchComplexTestFeatureVersionAffects = `
|
searchComplexTestFeatureVersionAffects = `
|
||||||
|
Loading…
Reference in New Issue
Block a user