The LEFT JOINs used to build the monitor list in pkg/service/sqlstore/monitor.go aren't entirely ideal, but while most of them don't impact performance at all yet (nor are real likely to soon), the LEFT JOIN of monitor_collector to monitor is hurting performance.
This PR breaks that query into two: one that queries the list of collector ids and their monitor_ids, grouped by monitor id, and the rest as it was before. The collector ids are then added to the monitor information struct.
The LEFT JOINs used to build the monitor list in
pkg/service/sqlstore/monitor.go
aren't entirely ideal, but while most of them don't impact performance at all yet (nor are real likely to soon), the LEFT JOIN of monitor_collector to monitor is hurting performance.This PR breaks that query into two: one that queries the list of collector ids and their monitor_ids, grouped by monitor id, and the rest as it was before. The collector ids are then added to the monitor information struct.