# Prompt traffic reads: with and without their indexes

**Last updated:** 2026-11-25T20:26:36-03:00 (UTC-3)

What the reads of [prompt revision on traffic](/docs/features/prompt-registry/#prompt-revision-on-traffic) cost on a large request log, and what their indexes change: the prompt page's figures of one prompt, and the 7-day counts of the prompt list.

## What the figures say

- **On PostgreSQL the indexes are what make the prompt page fast.** At 2 million requests, one prompt's figures over 7 days take about 120 ms without them and about 2 ms with them; over 30 days, about 300 ms and 8 ms. The list's counts of every prompt over 7 days go from about 135 ms to about 57 ms.
- **The gateway builds them itself.** Once `prompt_tracking` is on, it builds two partial indexes on the request log, `CONCURRENTLY` (writes go on during the build), one replica at a time: `(prompt_id, occurred_at)` and `(occurred_at)`, both only over the requests that recorded a prompt. At 2 million requests with one in ten tracked, the build took under a second. A failed build is logged as `prompt_index_failed` and tried again a minute later.
- **The analytics store needs none.** Its reads of one prompt take 3 to 6 ms at the same volume. A bloom-filter skip index on the prompt was measured and changes nothing: tracked requests of every prompt are spread through every granule, so no granule can be skipped. The gateway does not create it.

## Method

A probe in the gateway's own test suite (`internal/gateway/prompt_traffic_probe_test.go`, run only on request with `GATEWAY_PROMPT_PROBE=<rows>`) writes requests over 30 days for 20 teams, one in ten recording one of 40 prompts in one of three revisions, then times each read 20 times after one warm-up, without the indexes and again after building them.

- PostgreSQL 16 in a local container, `VACUUM (ANALYZE)` after the load; the reads run through `store.UsageQuery`, as the API runs them, for the prompt's own team.
- ClickHouse 25.12 in a local container; the reads are the predicates the query compiler writes for `prompt.id` on the request log copy and on the span table.
- One Apple M4 Pro machine. The figures compare the forms of one read; they are not a capacity promise.

The recorded runs are in [prompt-traffic.json](https://github.com/m7gtw/gateway/blob/main/docs/performance/prompt-traffic.json).

<!-- generated by scripts/render-trace-explorer.py from prompt-traffic.json: do not edit below -->

### PostgreSQL, 2,000,000 requests

| Read | Rows matched | Without index p50 (ms) | Without index p95 (ms) | With index p50 (ms) | With index p95 (ms) |
| --- | ---: | ---: | ---: | ---: | ---: |
| Prompt page: one prompt, 7 days | 2,332 | 123 | 127 | 2.3 | 2.5 |
| Prompt page: one prompt, 30 days | 10,000 | 299 | 370 | 8.0 | 9.2 |
| Prompt list: requests of every prompt, 7 days | 46,831 | 136 | 145 | 56.8 | 58.0 |

Writing the data took 39 s and building the indexes 0.9 s; each read ran 20 times after one warm-up.

### The analytics store, 2,000,000 requests

| Read | Rows matched | Without index p50 (ms) | Without index p95 (ms) | With index p50 (ms) | With index p95 (ms) |
| --- | ---: | ---: | ---: | ---: | ---: |
| Request log copy: one prompt, 7 days | 4,684 | 3.3 | 5.1 | 3.6 | 5.6 |
| Spans: request spans of one prompt, 7 days | 4,653 | 5.8 | 8.2 | 5.8 | 7.3 |

Writing the data took 7 s and building the indexes 1.7 s; each read ran 20 times after one warm-up.

<!-- end of generated tables -->
