Skip to content

Conversation

@phacops
Copy link
Contributor

@phacops phacops commented Jan 26, 2026

Add a new timestamp_ns column of type UInt16 to the eap_items_1 table for storing sub-second timestamp precision.

The migration:

  • Adds the timestamp_ns column after the existing timestamp column
  • Modifies the sort key to include timestamp_ns after timestamp: (organization_id, project_id, item_type, timestamp, timestamp_ns, trace_id, item_id)
  • Includes proper backwards migration to revert the sort key and drop the column

Add a new UInt16 column `timestamp_ns` to the eap_items_1 table for
storing sub-second timestamp precision. The column is added after the
existing `timestamp` column and included in the sort key.

Co-Authored-By: Claude <noreply@anthropic.com>
@phacops phacops requested review from a team as code owners January 26, 2026 23:27
@github-actions
Copy link

github-actions bot commented Jan 26, 2026

This PR has a migration; here is the generated SQL for ./snuba/migrations/groups.py ()

-- start migrations

-- forward migration events_analytics_platform : 0052_add_timestamp_ns_column
Local op: 
                    ALTER TABLE eap_items_1_local
                    ADD COLUMN IF NOT EXISTS timestamp_ns UInt16 AFTER timestamp,
                    MODIFY ORDER BY (organization_id, project_id, item_type, timestamp, timestamp_ns, trace_id, item_id)
                
Distributed op: ALTER TABLE eap_items_1_dist ON CLUSTER 'cluster_one_sh' ADD COLUMN IF NOT EXISTS timestamp_ns UInt16 AFTER timestamp;
-- end forward migration events_analytics_platform : 0052_add_timestamp_ns_column




-- backward migration events_analytics_platform : 0052_add_timestamp_ns_column
-- end backward migration events_analytics_platform : 0052_add_timestamp_ns_column

@phacops phacops requested a review from volokluev January 28, 2026 00:33
Comment on lines 44 to 57
operations.DropColumn(
storage_set=self.storage_set_key,
table_name=self.dist_table_name,
column_name="timestamp_ns",
target=OperationTarget.DISTRIBUTED,
),
operations.RunSql(
storage_set=self.storage_set_key,
statement=f"""
ALTER TABLE {self.local_table_name}
MODIFY ORDER BY (organization_id, project_id, item_type, timestamp, trace_id, item_id)
""",
target=OperationTarget.LOCAL,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this actually work? if you drop the column, the order by would break maybe?

Copy link
Contributor Author

@phacops phacops Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't modify the order by again since we'd modify it with columns that contain data and it might change the order of things on disk, the actual backwards operation here would be to stop inserting in timestamp_ns.

I removed the backwards operation.

@phacops phacops force-pushed the feat/add-timestamp-ns-column branch 2 times, most recently from 5735acb to 51b6b0c Compare January 28, 2026 18:18
Replace RunSql with AddColumn operation for adding the timestamp_ns
column to the distributed table. This uses the standard migration
operation instead of raw SQL.

Note: This migration is non-reversible due to ClickHouse limitations.
ClickHouse does not allow removing a column from the middle of a
sorting key via ALTER TABLE MODIFY ORDER BY.

Co-Authored-By: Claude <noreply@anthropic.com>
@phacops phacops force-pushed the feat/add-timestamp-ns-column branch from 51b6b0c to e0ac45e Compare January 28, 2026 18:27
@phacops phacops requested a review from volokluev January 28, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants