Skip to content

Commit

Permalink
feat(spans): Add indexes for tag columns (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored May 9, 2024
1 parent fe0e536 commit fd3b817
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions snuba/migrations/group_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def get_migrations(self) -> Sequence[str]:
"0010_spans_add_compression",
"0011_spans_add_index_on_trace_id",
"0012_spans_add_index_on_transaction_name",
"0013_spans_add_indexes_for_tag_columns",
]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import List, Sequence

from snuba.clusters.storage_sets import StorageSetKey
from snuba.migrations import migration, operations

table_name_prefix = "spans"
storage_set = StorageSetKey.SPANS
indexes = [
("bf_tags_key", "tags.key", "bloom_filter(0.0)", 1),
("bf_tags_hash_map", "_tags_hash_map", "bloom_filter(0.0)", 1),
("bf_sentry_tags_hash_map", "_sentry_tags_hash_map", "bloom_filter(0.0)", 1),
]


class Migration(migration.ClickhouseNodeMigration):
blocking = False

def forwards_ops(self) -> Sequence[operations.SqlOperation]:
ops: List[operations.SqlOperation] = []
for index in indexes:
index_name, index_expression, index_type, granularity = index
ops.append(
operations.AddIndex(
storage_set=storage_set,
table_name=f"{table_name_prefix}_local",
index_name=index_name,
index_expression=index_expression,
index_type=index_type,
granularity=granularity,
target=operations.OperationTarget.LOCAL,
)
)
return ops

def backwards_ops(self) -> Sequence[operations.SqlOperation]:
ops: List[operations.SqlOperation] = []
for index in indexes:
index_name, _, _, _ = index
ops.append(
operations.DropIndex(
storage_set=storage_set,
table_name=f"{table_name_prefix}_local",
index_name=index_name,
target=operations.OperationTarget.LOCAL,
)
)
return ops

0 comments on commit fd3b817

Please sign in to comment.