Use the MIN aggregation function for cert-checker's start-of-window (#5406)

Switch from using `ORDER BY` and `LIMIT` to obtain a minimum ID from the
certificates table, to using the `MIN()` aggregation function.

Relational databases are most optimized for set aggregation functions,
and anywhere that aggregations can be used for `SELECT` queries tends to
bring performance improvements. Experimentally this is an
order-of-magnitude improvement in query time. Theoretically the query
optimizer should have constructed the same underlying query from each,
but it didn't.

Partially reverts #5400
Fixes of #5393
This commit is contained in:
J.C. Jones 2021-05-04 11:49:49 -07:00 committed by GitHub
parent dd4ddfc965
commit e5c48f4644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -128,7 +128,7 @@ func (c *certChecker) getCerts(unexpiredOnly bool) error {
}
initialID, err := c.dbMap.SelectInt(
"SELECT id FROM certificates WHERE issued >= :issued AND expires >= :now ORDER BY id ASC LIMIT 1",
"SELECT MIN(id) FROM certificates WHERE issued >= :issued AND expires >= :now",
args,
)
if err != nil {