-
[OPIK-4879] [BE] perf: add span_id_prefilter to narrow feedback_scores and comments scans (#5625)
发布于
2026-03-12 11:11:35 +00:00 - [OPIK-NA] [BE] Add span_id_prefilter to narrow feedback_scores and comments scans
When spans are filtered by name, input, or other criteria but feedback
score filters are not active, the feedback_scores and comments CTEs still
scan ALL data for the entire project. For large projects (85M+ spans),
this reads 500+ GiB unnecessarily.This adds a span_id_prefilter CTE that pre-computes matching span IDs
using the same filters as the main query. The feedback_scores and comments
CTEs then use entity_id IN (SELECT id FROM span_id_prefilter) to only
process scores/comments for spans that actually match.The pre-filter is only activated when:
- There are narrowing filters (trace_id, type, search_text, or span filters)
- Feedback scores are not needed for filtering or sorting
- fix(span-dao): use prefilter OR time-range, not both, on feedback_scores CTEs
Matches the if/else pattern from TraceDAO review feedback: when
span_id_prefilter is active (already includes time-range internally),
skip redundant time-range filters on feedback_scores/comments CTEs.- refactor(span-dao): reuse template attributes and hoist toOrderBySql
- shouldUseSpanIdPrefilter now reads filter presence from template
attributes already set by newFindTemplate, avoiding redundant
toAnalyticsDbFilters calls - Hoist toOrderBySql result into local variable to avoid duplicate call
下载附件