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:
		
							parent
							
								
									dd4ddfc965
								
							
						
					
					
						commit
						e5c48f4644
					
				|  | @ -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 { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue