perf(coderd/database): optimize GetAPIKeysLastUsedAfter (#19725)

This change adds a support-index for `GetAPIKeysLastUsedAfter`.

On dogfood (24h): called 4.4k times, 380ms average.

Change for tested time range: `170ms` -> `3.3ms`.
This commit is contained in:
Mathias Fredriksson
2025-09-08 13:13:12 +03:00
committed by GitHub
parent fb9753edf2
commit 21402c7aaa
3 changed files with 7 additions and 0 deletions
@@ -0,0 +1 @@
DROP INDEX api_keys_last_used_idx;
@@ -0,0 +1,2 @@
CREATE INDEX api_keys_last_used_idx ON api_keys (last_used DESC);
COMMENT ON INDEX api_keys_last_used_idx IS 'Index for optimizing api_keys queries filtering by last_used';