Skip to content

perf(db): index case-insensitive api key lookups#902

Open
raymondjacobson wants to merge 1 commit into
mainfrom
codex/db-audit-api-keys-lower-index
Open

perf(db): index case-insensitive api key lookups#902
raymondjacobson wants to merge 1 commit into
mainfrom
codex/db-audit-api-keys-lower-index

Conversation

@raymondjacobson
Copy link
Copy Markdown
Member

Summary

  • add a concurrent functional index on lower(api_key)
  • preserves existing case-insensitive rate-limit lookup semantics while making the predicate indexable

Production evidence

  • pg_stat_statements showed the rate-limit lookup at ~23.7M calls
  • pg_stat_user_tables showed api_keys had ~23.7M seq scans and ~35B tuples read
  • EXPLAIN for LOWER(api_key) = LOWER() used a seq scan, while exact api_key lookup uses the pkey
  • production has 335 mixed-case api_keys, so a code-only exact lookup would change behavior

Verification

  • migration follows existing CONCURRENTLY migration style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant