Skip to content

fix(database): index server name substring searches - #1730

Merged
rdimitrov merged 1 commit into
mainfrom
codex/server-name-trigram-index
Oct 23, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
codex/server-name-trigram-index

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Substring searches use server_name ILIKE '%term%', which was scanning the production servers table and contending with ordinary listings. Add a GIN trigram index using the existing pg_trgm extension, plus instructions for concurrent construction on populated databases.

The index was built concurrently in production on 2026-10-23 and verified valid/ready. Migration 015 skips the existing index, creates it on fresh databases, and rejects an invalid index left by an interrupted build. The transactional migration runner is unchanged. Production benefits immediately; a release is not required to activate this index.

Validation

  • CI build, lint, validation, full unit/integration tests and CodeQL all passed for commit 5d358d3.
  • Applied the migration twice against a fresh isolated staging schema, then rolled the test back.
  • Production EXPLAIN ANALYZE uses the new index for a filesystem search: 96 ms execution.
  • Extended production verification: 38 sequential read-only API checks across v0 and v0.1, all HTTP 200 and all response assertions passed; 30 cache misses. Covers three-page listings, search pagination, case-insensitive matching, short/common/missing terms, literal %, _ and backslash matching, latest-version filters, limit=100, exact/latest details and version lists. Median response 0.77 seconds; maximum 6.8 seconds on a one-character search.
  • A fresh 65-second sample measured 232 ordinary searches averaging 214 ms and 28 latest-version searches averaging 59 ms. Pagination averaged 12–16 ms across 8,952 calls. Earlier pre-change search averages were approximately 26 seconds. Traffic/query mixes differ; these are operational observations rather than a controlled benchmark.
  • Latest five-minute monitoring window: approximately 39,700 listing requests with zero 5xx responses. At an earlier check in the same validation session, application-observed mean/p95 were 29/100 ms; these exclude client network time and are distinct from the direct API timings.
  • Index remains valid/ready; PostgreSQL has not restarted. git diff --check passed.

Remaining limitations

Brief database readiness failures and connection errors occurred during the build, and another readiness failure occurred at approximately 17:20 UTC after completion (18 listing 5xx responses recorded in subsequent metrics). The database recovered readiness at 17:20:54 UTC. These later failures mean the index must not be described as resolving every availability issue.

One- and two-character searches still took 4–7 seconds in some direct checks. Keep this PR focused on the index; short-search cost and readiness resilience warrant separate investigation. An optional read-only comparison against forced sequential scans hit its five-second statement timeout and was stopped; result equivalence for that additional check was not established. No production records were modified or restored by these checks.

@rdimitrov
rdimitrov marked this pull request as ready for review October 23, 2026 17:39
@rdimitrov
rdimitrov merged commit 1a319b0 into main Oct 23, 2026
9 checks passed
@rdimitrov
rdimitrov deleted the codex/server-name-trigram-index branch October 23, 2026 17:39
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