Commit 68a4b6f
committed
fix: re-key event/gauge tables on (tenant, metric, time, id) for time-range scan efficiency
Previous ORDER BY of (tenant, id) had id (random UUID) as the primary
sort key, so ClickHouse stored rows in essentially random physical
order. Time-range predicates like WHERE time > X had to scan every
granule because the primary index had no time information to skip on.
Re-key to (tenant, metric, time, id) so the primary index matches
how the data is actually queried:
- tenant: multi-tenant isolation (cheap first-level filter)
- metric: per-metric series (most queries are scoped to one)
- time: range scans now hit a small contiguous span instead of
the whole table
- id: tiebreaker for stable physical ordering
Gauges get the same shape. Daily MV already had the right key.
Drop the now-redundant bloom_filter indexes on metric and time
(primary key already covers them).
Pre-prod schema change — no migration path needed, just DROP+CREATE
on next deploy.
Updates MetricTest counts to match the trimmed index lists.1 parent b2cbdbc commit 68a4b6f
4 files changed
Lines changed: 32 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1039 | 1044 | | |
1040 | 1045 | | |
1041 | 1046 | | |
| |||
1073 | 1078 | | |
1074 | 1079 | | |
1075 | 1080 | | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | 1081 | | |
1082 | | - | |
1083 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
1084 | 1085 | | |
1085 | 1086 | | |
1086 | 1087 | | |
1087 | 1088 | | |
1088 | | - | |
| 1089 | + | |
1089 | 1090 | | |
1090 | 1091 | | |
1091 | 1092 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
586 | 589 | | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | 590 | | |
598 | 591 | | |
599 | 592 | | |
| |||
639 | 632 | | |
640 | 633 | | |
641 | 634 | | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
654 | 639 | | |
655 | 640 | | |
656 | 641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
112 | 116 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
132 | 124 | | |
133 | 125 | | |
134 | 126 | | |
| |||
138 | 130 | | |
139 | 131 | | |
140 | 132 | | |
| 133 | + | |
| 134 | + | |
141 | 135 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 136 | + | |
146 | 137 | | |
147 | 138 | | |
148 | 139 | | |
| |||
0 commit comments