Skip to content

fix(spans): scope GetSpansByRunIDsAndName self-join to same run_id - #1

Draft
ndholaria-stripe wants to merge 1 commit into
mainfrom
fix/spans-cross-run-join
Draft

fix(spans): scope GetSpansByRunIDsAndName self-join to same run_id#1
ndholaria-stripe wants to merge 1 commit into
mainfrom
fix/spans-cross-run-join

Conversation

@ndholaria-stripe

Copy link
Copy Markdown

Summary

  • dynamic_span_id is deterministic (derived from function/step identity) and is reused across all runs of the same function
  • The self-join in GetSpansByRunIDsAndName was joining on dynamic_span_id alone, causing a single run-data load to scan spans from every unrelated run sharing that ID
  • Adds AND m.run_id = s.run_id to the JOIN condition to scope results to the requested runs only
  • Follow-up/update rows (the reason the self-join exists) share both dynamic_span and run_id with their originating span, so post-emit attribute merge semantics are preserved

Reported impact: 30+ second queries scanning 2.4M rows for a single run load (57,775 distinct runs sharing one dynamic_span_id).

Fixes inngest#4656

Test plan

  • Open a run detail page on a self-hosted deployment with a large spans table and confirm query time drops to milliseconds
  • Confirm step spans and their follow-up attribute-update rows still render correctly in the run trace view

Release note

Fixed a performance bug where loading run trace data performed a cross-run self-join on spans, causing queries to scan millions of rows from unrelated runs that happened to share the same deterministic dynamic_span_id.

Migration note

None

dynamic_span_id is derived from function/step identity and is reused
across all runs of the same function. Joining spans only on
dynamic_span_id caused a single run-data load to aggregate spans from
every unrelated run sharing that ID, scanning millions of rows and
taking 30+ seconds in production.

Adding AND m.run_id = s.run_id to the join constrains s to spans
belonging to the requested runs only. Follow-up/update rows (the reason
the self-join exists) share both dynamic_span_id and run_id with their
originating span, so the semantics of merging in post-emit attribute
updates are preserved.

Fixes inngest#4656

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
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.

Inngest Spans Cross-Run Query Issue

1 participant