-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary_clickhouse.sql
244 lines (236 loc) · 4.98 KB
/
dictionary_clickhouse.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
-- Dictionary over Remote ClickHouse : cached
CREATE DICTIONARY ch_products_dict_cached(
`id` string,
`name` string,
`d1` string,
`d2` string,
`d3` string,
`d4` string,
`d5` string,
`d6` string,
`d7` string,
`d8` string,
`d9` string,
`d10` string,
`d11` string,
`d12` string,
`d13` string,
`d14` string,
`d15` string,
`d16` string,
`d17` string,
`d18` string,
`d19` string,
`d20` string,
`d21` string,
`d22` string,
`d23` string,
`d24` string,
`d25` string,
`d26` string,
`d27` string,
`d28` string,
`d29` string,
`d30` string,
`d31` string,
`d32` string,
`d33` string,
`d34` string,
`d35` string,
`d36` string,
`d37` string,
`d39` string,
`d40` string,
`d41` string,
`d42` string,
`d43` string,
`d44` string,
`d45` string,
`d46` string,
`d47` string,
`d48` string,
`d49` string,
`d50` string,
`dt` datetime
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(DB 'default' TABLE 'products' HOST 'localhost' PORT 9000 USER 'default' PASSWORD ''))
LIFETIME(MIN 1800 MAX 3600) -- in seconds
LAYOUT(complex_key_cache(size_in_cells 1000000000 allow_read_expired_keys 1 max_update_queue_size 100000 update_queue_push_timeout_milliseconds 100 query_wait_timeout_milliseconds 60000 max_threads_for_updates 4));
-- SSD cached
CREATE DICTIONARY ch_products_dict_ssd_cached(
`id` string,
`name` string,
`d1` string,
`d2` string,
`d3` string,
`d4` string,
`d5` string,
`d6` string,
`d7` string,
`d8` string,
`d9` string,
`d10` string,
`d11` string,
`d12` string,
`d13` string,
`d14` string,
`d15` string,
`d16` string,
`d17` string,
`d18` string,
`d19` string,
`d20` string,
`d21` string,
`d22` string,
`d23` string,
`d24` string,
`d25` string,
`d26` string,
`d27` string,
`d28` string,
`d29` string,
`d30` string,
`d31` string,
`d32` string,
`d33` string,
`d34` string,
`d35` string,
`d36` string,
`d37` string,
`d39` string,
`d40` string,
`d41` string,
`d42` string,
`d43` string,
`d44` string,
`d45` string,
`d46` string,
`d47` string,
`d48` string,
`d49` string,
`d50` string,
`dt` datetime
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(DB 'default' TABLE 'products' HOST 'localhost' PORT 9000 USER 'default' PASSWORD ''))
LIFETIME(MIN 1800 MAX 3600) -- in seconds
LAYOUT(complex_key_ssd_cache(block_size 4096 file_size 1073741824 read_buffer_size 131072 write_buffer_size 1048576 path '/var/lib/timeplusd/user_files/products_dict'));
-- Direct
CREATE DICTIONARY ch_products_dict_direct(
`id` string,
`name` string,
`d1` string,
`d2` string,
`d3` string,
`d4` string,
`d5` string,
`d6` string,
`d7` string,
`d8` string,
`d9` string,
`d10` string,
`d11` string,
`d12` string,
`d13` string,
`d14` string,
`d15` string,
`d16` string,
`d17` string,
`d18` string,
`d19` string,
`d20` string,
`d21` string,
`d22` string,
`d23` string,
`d24` string,
`d25` string,
`d26` string,
`d27` string,
`d28` string,
`d29` string,
`d30` string,
`d31` string,
`d32` string,
`d33` string,
`d34` string,
`d35` string,
`d36` string,
`d37` string,
`d39` string,
`d40` string,
`d41` string,
`d42` string,
`d43` string,
`d44` string,
`d45` string,
`d46` string,
`d47` string,
`d48` string,
`d49` string,
`d50` string,
`dt` datetime
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(DB 'default' TABLE 'products' HOST 'localhost' PORT 9000 USER 'default' PASSWORD ''))
LAYOUT(complex_key_direct());
-- Timeplus stream do remote ClickHouse lookup join via dictionary
create random stream r_orders
(
`product_id` string default 'key_' || to_string(rand64() % 200000),
`name` string,
`d1` string,
`d2` string,
`d3` string,
`d4` string,
`d5` string,
`d6` string,
`d7` string,
`d8` string,
`d9` string,
`d10` string,
`d11` string,
`d12` string,
`d13` string,
`d14` string,
`d15` string,
`d16` string,
`d17` string,
`d18` string,
`d19` string,
`d20` string,
`d21` string,
`d22` string,
`d23` string,
`d24` string,
`d25` string,
`d26` string,
`d27` string,
`d28` string,
`d29` string,
`d30` string,
`d31` string,
`d32` string,
`d33` string,
`d34` string,
`d35` string,
`d36` string,
`d37` string,
`d39` string,
`d40` string,
`d41` string,
`d42` string,
`d43` string,
`d44` string,
`d45` string,
`d46` string,
`d47` string,
`d48` string,
`d49` string,
`d50` string,
`dt` datetime64(3)
);
-- Direct join
SELECT * FROM r_orders JOIN ch_products_dict_cached AS products
ON r_orders.product_id = products.id
SETTINGS join_algorithm = 'direct';