Rebuild AI Usage Events
What does this MR do and why?
MR 2 of 4 for #608216. Rebuilds ai_usage_events so that the org-scoped
traversal_path replaces the legacy namespace_path as the leading sort key,
which lets org-scoped startsWith lookups use the primary index.
Overlap between the copy and the view is safe: both write the same canonical
traversal_path, and the ReplacingMergeTree sort key collapses the duplicates.
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
-
Run the ClickHouse migrations:
bundle exec rake gitlab:clickhouse:migrate -
Confirm the sort key moved:
SELECT sorting_key FROM system.tables WHERE name = 'ai_usage_events'; -- traversal_path, event, timestamp, user_id -
Confirm no row still needs resolving. Residual rows are namespaces the dictionary could not resolve; record the number:
SELECT countIf(traversal_path = '0/') FROM ai_usage_events; -
Reconcile engine query totals per-org and globally against the values from before the rebuild.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #608216