You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Number of seconds captured in the query stat. 60 = 1 minute source data, 3600 = 1 hour aggregation
48
+
pubgranularity:i32,
47
49
pubcollected_at:SystemTime,
48
50
pubfingerprint:i64,
49
51
pubcalls:i64,
50
-
pubtotal_time:f64,
51
52
}
52
53
```
53
54
@@ -56,25 +57,24 @@ And a matching Postgres table:
56
57
```sql
57
58
CREATETABLEquery_stats (
58
59
database_id bigintNOT NULL,
60
+
granularity intNOT NULL,
59
61
start_at timestamptzNOT NULL,
60
62
end_at timestamptzNOT NULL,
61
63
collected_at bytea STORAGE EXTERNAL NOT NULL,
62
64
fingerprint bytea STORAGE EXTERNAL NOT NULL,
63
-
calls bytea STORAGE EXTERNAL NOT NULL,
64
-
total_time bytea STORAGE EXTERNAL NOT NULL
65
-
);
66
-
CREATEINDEXON query_stats USING btree (database_id);
67
-
CREATEINDEXON query_stats USING btree (end_at, start_at);
68
-
```
65
+
calls bytea STORAGE EXTERNAL NOT NULL
66
+
) PARTITION BY LIST (granularity);
69
67
70
-
`STORAGE EXTERNAL` is set so that Postgres doesn't try to compress the already-compressed fields
68
+
CREATETABLEquery_stats_1min PARTITION OF query_stats FOR VALUESIN (60);
69
+
CREATETABLEquery_stats_1hour PARTITION OF query_stats FOR VALUESIN (3600);
71
70
72
-
This uses a `(end_at, start_at)` index because it's more selective than `(start_at, end_at)` for common use cases. For example when loading the last week of stats, the `end_at` filter is what's doing the work to filter out rows.
0 commit comments