From b34c9795e1d09b684c4ade588820b0a8f24b16c8 Mon Sep 17 00:00:00 2001 From: Pierre Massat Date: Thu, 21 Mar 2024 14:23:30 -0600 Subject: [PATCH] feat(spans): Add an index on segment_name (#5671) --- snuba/migrations/group_loader.py | 1 + ...012_spans_add_index_on_transaction_name.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 snuba/snuba_migrations/spans/0012_spans_add_index_on_transaction_name.py diff --git a/snuba/migrations/group_loader.py b/snuba/migrations/group_loader.py index ef464378eb..65733802d6 100644 --- a/snuba/migrations/group_loader.py +++ b/snuba/migrations/group_loader.py @@ -356,6 +356,7 @@ def get_migrations(self) -> Sequence[str]: "0009_spans_add_measure_hashmap", "0010_spans_add_compression", "0011_spans_add_index_on_trace_id", + "0012_spans_add_index_on_transaction_name", ] diff --git a/snuba/snuba_migrations/spans/0012_spans_add_index_on_transaction_name.py b/snuba/snuba_migrations/spans/0012_spans_add_index_on_transaction_name.py new file mode 100644 index 0000000000..1ceb2911e7 --- /dev/null +++ b/snuba/snuba_migrations/spans/0012_spans_add_index_on_transaction_name.py @@ -0,0 +1,34 @@ +from typing import Sequence + +from snuba.clusters.storage_sets import StorageSetKey +from snuba.migrations import migration, operations + +table_name_prefix = "spans" +column_name = "segment_name" + + +class Migration(migration.ClickhouseNodeMigration): + blocking = False + + def forwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.AddIndex( + storage_set=StorageSetKey.SPANS, + table_name=f"{table_name_prefix}_local", + index_name=f"bf_{column_name}", + index_expression=column_name, + index_type="bloom_filter(0.0)", + granularity=1, + target=operations.OperationTarget.LOCAL, + ), + ] + + def backwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.DropIndex( + StorageSetKey.SPANS, + table_name=f"{table_name_prefix}_local", + index_name=f"bf_{column_name}", + target=operations.OperationTarget.LOCAL, + ), + ]