registry/internal/database
Repository files (latest commit first)
Filename Latest commit message Latest commit date
nate nowack 72f9f80d68
perf(db): use pk id for lookups and ordering (#390)
summary
- use the indexed primary key (`id`) for `getbyid`, `updateserver`, and
list ordering/cursor, instead of extracting `_meta...id` from jsonb
- in `updateserver`, error if the body tries to change the id; set
`meta.official.id` when missing

changes
- database: `getbyid` → `where id = $1`
- database: `updateserver` → `where id = $2`; fail on id mismatch; set
id if missing
- database: `list` orders by `id` and paginates via `id > $cursor`
- no schema or api changes

<details>
<summary>performance</summary>

- env: repo docker compose postgres, 5k–10k rows, warm cache
- getbyid: `id` ≈ 0.02 ms vs jsonb path ≈ 0.80 ms
- update: `id` ≈ 0.15 ms vs jsonb path ≈ 0.78 ms
- list (limit 100): order by `id` ≈ 0.13 ms vs jsonb path id ≈ 2.24 ms
(~17x slower)

</details>

<details>
<summary>explain analyze snippets</summary>

getbyid by `id`
```
Index Scan using idx_benchmark_servers_id on benchmark_servers (actual time≈0.01–0.02 ms)
Buffers: shared hit≈3
```

getbyid by jsonb path
```
Seq Scan on benchmark_servers (actual time≈0.43–0.83 ms)
Filter: ((value->'_meta'->'io.modelcontextprotocol.registry/official'->>'id') = $1)
Rows Removed by Filter: ≈4999
Buffers: shared hit≈455
```

update by `id`
```
Update on benchmark_servers …
-> Index Scan using idx_benchmark_servers_id … (actual time≈0.007 ms)
Execution Time: ≈0.15 ms
```

update by jsonb path
```
Update on benchmark_servers …
-> Seq Scan on benchmark_servers … Rows Removed by Filter: ≈4999
Execution Time: ≈0.78 ms
```
</details>

<details>
<summary>reproduce quickly</summary>

- start postgres: `docker compose up -d postgres`
- create a simple table (id varchar pk, value jsonb) with several
thousand rows
- compare plans: `explain (analyze, buffers) select value from … where
id = $1` vs the jsonb path predicate
</details>

---------

Co-authored-by: Adam Jones <adamj@anthropic.com>
2025-09-09 08:10:55 -07:00
..
migrations Fix _meta field format for MCP spec compliance (#367) 2025-09-08 11:40:04 -07:00
database.go Add filtering functionality to server list endpoint (#374) 2025-09-08 13:55:33 -07:00
memory.go Clean up schema by simplifying version structure (#379) 2025-09-08 14:32:59 -07:00
migrate.go fix: use path.Join instead of filepath.Join for embedded migrations (#338) 2025-09-02 14:51:23 +01:00
postgres.go perf(db): use pk id for lookups and ordering (#390) 2025-09-09 08:10:55 -07:00