From 6af7471d0ea870eb6f2c252a4489a5a1fccb00a4 Mon Sep 17 00:00:00 2001 From: William Mak Date: Wed, 27 Nov 2024 16:38:10 -0500 Subject: [PATCH] fix(rpc): Only groupby when needed - this should fix the timeout bug we're experiencing with samples queries --- src/sentry/snuba/spans_rpc.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/sentry/snuba/spans_rpc.py b/src/sentry/snuba/spans_rpc.py index 855accbad5ace8..bd87a9a9311f3e 100644 --- a/src/sentry/snuba/spans_rpc.py +++ b/src/sentry/snuba/spans_rpc.py @@ -66,6 +66,9 @@ def run_table_query( descending=orderby_column.startswith("-"), ) ) + has_aggregations = any( + col for col in columns if isinstance(col.proto_definition, AttributeAggregation) + ) labeled_columns = [categorize_column(col) for col in columns] @@ -74,11 +77,15 @@ def run_table_query( meta=meta, filter=query, columns=labeled_columns, - group_by=[ - col.proto_definition - for col in columns - if isinstance(col.proto_definition, AttributeKey) - ], + group_by=( + [ + col.proto_definition + for col in columns + if isinstance(col.proto_definition, AttributeKey) + ] + if has_aggregations + else [] + ), order_by=resolved_orderby, limit=limit, virtual_column_contexts=[context for context in contexts if context is not None],