SIGN IN SIGN UP

fix(traces): scope span self-join by run_id (#4718)

## Description

`GetSpansByRunIDsAndName` self-joined `spans` on `dynamic_span_id`
alone. That column has no usable index, so the join forced a full table
scan on every runs-list page — and since `dynamic_span_id` is
deterministic per step position, colliding IDs could bleed results
across runs.

The join now also matches `run_id`, which uses the existing
`idx_spans_run_id` index and scopes the merge to the requested runs.
Same invariant `loadTraceRunSpanDetails` already relies on; a new CQRS
test pins the no-bleed behavior.

Fixes #4690

## Release note

Fixed the runs list hanging on large Postgres deployments when
`deferredFrom`/`isDeferred` was selected. No migration or manual index
needed.

## Migration note

None.

*[Check our Pull Request
Guidelines](https://github.com/inngest/inngest/blob/main/docs/PULL_REQUEST_GUIDELINES.md)*
L
Linell Bonnette committed
9388b85872b54eb2f545cf699aa0fa317ad5ddc7
Parent: 5af7f78
Committed by GitHub <noreply@github.com> on 8/7/2026, 4:41:06 PM