Skip to content

Commit 76d8deb

Browse files
committed
Add distributed tables for fields and schema
1 parent b9c7a13 commit 76d8deb

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

oximeter/db/schema/replicated/db-init-test.sql

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,50 +102,62 @@ ENGINE = Distributed('oximeter_cluster', 'oximeter', 'measurements_cumulativef64
102102
* already has the key. Realistically though, these tables are quite small and
103103
* so performance benefits will be low in absolute terms.
104104
*/
105-
CREATE TABLE IF NOT EXISTS oximeter.fields_i64 ON CLUSTER oximeter_cluster
105+
CREATE TABLE IF NOT EXISTS oximeter.fields_i64_local ON CLUSTER oximeter_cluster
106106
(
107107
timeseries_name String,
108108
timeseries_key UInt64,
109109
field_name String,
110110
field_value Int64
111111
)
112-
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_i64', '{replica}')
112+
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_i64_local', '{replica}')
113113
ORDER BY (timeseries_name, field_name, field_value, timeseries_key);
114114

115-
CREATE TABLE IF NOT EXISTS oximeter.fields_ipaddr ON CLUSTER oximeter_cluster
115+
CREATE TABLE IF NOT EXISTS oximeter.fields_i64 ON CLUSTER oximeter_cluster AS oximeter.fields_i64_local
116+
ENGINE = Distributed('oximeter_cluster', 'oximeter', 'fields_i64_local', xxHash64(splitByChar(':', timeseries_name)[1]));
117+
118+
CREATE TABLE IF NOT EXISTS oximeter.fields_ipaddr_local ON CLUSTER oximeter_cluster
116119
(
117120
timeseries_name String,
118121
timeseries_key UInt64,
119122
field_name String,
120123
field_value IPv6
121124
)
122-
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_ipaddr', '{replica}')
125+
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_ipaddr_local', '{replica}')
123126
ORDER BY (timeseries_name, field_name, field_value, timeseries_key);
124127

125-
CREATE TABLE IF NOT EXISTS oximeter.fields_string ON CLUSTER oximeter_cluster
128+
CREATE TABLE IF NOT EXISTS oximeter.fields_ipaddr ON CLUSTER oximeter_cluster AS oximeter.fields_ipaddr_local
129+
ENGINE = Distributed('oximeter_cluster', 'oximeter', 'fields_ipaddr_local', xxHash64(splitByChar(':', timeseries_name)[1]));
130+
131+
CREATE TABLE IF NOT EXISTS oximeter.fields_string_local ON CLUSTER oximeter_cluster
126132
(
127133
timeseries_name String,
128134
timeseries_key UInt64,
129135
field_name String,
130136
field_value String
131137
)
132-
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_string', '{replica}')
138+
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_string_local', '{replica}')
133139
ORDER BY (timeseries_name, field_name, field_value, timeseries_key);
134140

135-
CREATE TABLE IF NOT EXISTS oximeter.fields_uuid ON CLUSTER oximeter_cluster
141+
CREATE TABLE IF NOT EXISTS oximeter.fields_string ON CLUSTER oximeter_cluster AS oximeter.fields_string_local
142+
ENGINE = Distributed('oximeter_cluster', 'oximeter', 'fields_string_local', xxHash64(splitByChar(':', timeseries_name)[1]));
143+
144+
CREATE TABLE IF NOT EXISTS oximeter.fields_uuid_local ON CLUSTER oximeter_cluster
136145
(
137146
timeseries_name String,
138147
timeseries_key UInt64,
139148
field_name String,
140149
field_value UUID
141150
)
142-
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_uuid', '{replica}')
151+
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/fields_uuid_local', '{replica}')
143152
ORDER BY (timeseries_name, field_name, field_value, timeseries_key);
144153

154+
CREATE TABLE IF NOT EXISTS oximeter.fields_uuid ON CLUSTER oximeter_cluster AS oximeter.fields_uuid_local
155+
ENGINE = Distributed('oximeter_cluster', 'oximeter', 'fields_uuid_local', xxHash64(splitByChar(':', timeseries_name)[1]));
156+
145157
/* The timeseries schema table stores the extracted schema for the samples
146158
* oximeter collects.
147159
*/
148-
CREATE TABLE IF NOT EXISTS oximeter.timeseries_schema ON CLUSTER oximeter_cluster
160+
CREATE TABLE IF NOT EXISTS oximeter.timeseries_schema_local ON CLUSTER oximeter_cluster
149161
(
150162
timeseries_name String,
151163
fields Nested(
@@ -200,5 +212,8 @@ CREATE TABLE IF NOT EXISTS oximeter.timeseries_schema ON CLUSTER oximeter_cluste
200212
),
201213
created DateTime64(9, 'UTC')
202214
)
203-
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/timeseries_schema', '{replica}')
215+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/timeseries_schema_local', '{replica}')
204216
ORDER BY (timeseries_name, fields.name);
217+
218+
CREATE TABLE IF NOT EXISTS oximeter.timeseries_schema ON CLUSTER oximeter_cluster AS oximeter.timeseries_schema_local
219+
ENGINE = Distributed('oximeter_cluster', 'oximeter', 'timeseries_schema_local', xxHash64(splitByChar(':', timeseries_name)[1]));

0 commit comments

Comments
 (0)