Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,12 @@ condition is FilterCondition.Contains or FilterCondition.NotContains

var attributePredicate = BuildStringPredicate("a.attribute_value", condition, parameterName);
parameters.Add($"TraceField{filterIndex}", filter.Field);
return $"EXISTS (SELECT 1 FROM telemetry_span_attributes a WHERE a.trace_id = s.trace_id AND a.span_id = s.span_id AND a.attribute_key = @TraceField{filterIndex} COLLATE NOCASE AND {attributePredicate})";
// Unary + prevents SQLite from using attribute_key to choose an index, so this
// correlated subquery looks up attributes by (trace_id, span_id) instead.
// Otherwise, LIKE '%...%' can scan all attributes with the same key for every
// span, making filtering quadratic in the span count.
// See https://www.sqlite.org/optoverview.html#disqualifying_where_clause_terms_using_unary_
return $"EXISTS (SELECT 1 FROM telemetry_span_attributes a WHERE a.trace_id = s.trace_id AND a.span_id = s.span_id AND +a.attribute_key = @TraceField{filterIndex} COLLATE NOCASE AND {attributePredicate})";
}

private GetSpansResponse GetSpansFromDatabase(GetSpansRequest context, CancellationToken cancellationToken)
Expand Down
Loading