|
| 1 | +/*********** Partitioning Data ****************/ |
| 2 | + |
| 3 | + |
| 4 | +-------- Create new table with associated Partion Column (event hour: 0 - 24 hours) -------- |
| 5 | + |
| 6 | +/* Create a table of location and temperature measurements */ |
| 7 | +CREATE TABLE time_series.location_temp_p( |
| 8 | + event_time TIMESTAMP NOT NULL, |
| 9 | + event_hour INT, |
| 10 | + temp_celcius INT, |
| 11 | + location_id CHARACTER VARYING COLLATE pg_catalog."default" |
| 12 | +)PARTITION BY RANGE(event_hour); |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +/* Create 12 partition nodes for that above table */ |
| 17 | +-- range start value is inclusive, end value is exclusive |
| 18 | +CREATE TABLE time_series.location_temp_p1 PARTITION OF time_series.location_temp_p |
| 19 | + FOR VALUES FROM (0) TO (2); |
| 20 | + |
| 21 | +-- together we will create index event_time for each partition node table |
| 22 | +CREATE INDEX idx_loc_temp_p1 ON time_series.location_temp_p1(event_time); |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +/* continue creating another 11 nodes */ |
| 27 | +CREATE TABLE time_series.location_temp_p2 PARTITION OF time_series.location_temp_p |
| 28 | + FOR VALUES FROM (2) TO (4); |
| 29 | +CREATE INDEX idx_loc_temp_p2 ON time_series.location_temp_p2(event_time); |
| 30 | + |
| 31 | + |
| 32 | +CREATE TABLE time_series.location_temp_p3 PARTITION OF time_series.location_temp_p |
| 33 | + FOR VALUES FROM (4) TO (6); |
| 34 | +CREATE INDEX idx_loc_temp_p3 ON time_series.location_temp_p3(event_time); |
| 35 | + |
| 36 | + |
| 37 | +CREATE TABLE time_series.location_temp_p4 PARTITION OF time_series.location_temp_p |
| 38 | + FOR VALUES FROM (6) TO (8); |
| 39 | +CREATE INDEX idx_loc_temp_p4 ON time_series.location_temp_p4(event_time); |
| 40 | + |
| 41 | + |
| 42 | +CREATE TABLE time_series.location_temp_p5 PARTITION OF time_series.location_temp_p |
| 43 | + FOR VALUES FROM (8) TO (10); |
| 44 | +CREATE INDEX idx_loc_temp_p5 ON time_series.location_temp_p5(event_time); |
| 45 | + |
| 46 | + |
| 47 | +CREATE TABLE time_series.location_temp_p6 PARTITION OF time_series.location_temp_p |
| 48 | + FOR VALUES FROM (10) TO (12); |
| 49 | +CREATE INDEX idx_loc_temp_p6 ON time_series.location_temp_p5(event_time); |
| 50 | + |
| 51 | + |
| 52 | +CREATE TABLE time_series.location_temp_p7 PARTITION OF time_series.location_temp_p |
| 53 | + FOR VALUES FROM (12) TO (14); |
| 54 | +CREATE INDEX idx_loc_temp_p7 ON time_series.location_temp_p7(event_time); |
| 55 | + |
| 56 | + |
| 57 | +CREATE TABLE time_series.location_temp_p8 PARTITION OF time_series.location_temp_p |
| 58 | + FOR VALUES FROM (14) TO (16); |
| 59 | +CREATE INDEX idx_loc_temp_p8 ON time_series.location_temp_p8(event_time); |
| 60 | + |
| 61 | + |
| 62 | +CREATE TABLE time_series.location_temp_p9 PARTITION OF time_series.location_temp_p |
| 63 | + FOR VALUES FROM (16) TO (18); |
| 64 | +CREATE INDEX idx_loc_temp_9 ON time_series.location_temp_p9(event_time); |
| 65 | + |
| 66 | + |
| 67 | +CREATE TABLE time_series.location_temp_p10 PARTITION OF time_series.location_temp_p |
| 68 | + FOR VALUES FROM (18) TO (20); |
| 69 | +CREATE INDEX idx_loc_temp_p10 ON time_series.location_temp_p10(event_time); |
| 70 | + |
| 71 | + |
| 72 | +CREATE TABLE time_series.location_temp_p11 PARTITION OF time_series.location_temp_p |
| 73 | + FOR VALUES FROM (20) TO (22); |
| 74 | +CREATE INDEX idx_loc_temp_p11 ON time_series.location_temp_p11(event_time); |
| 75 | + |
| 76 | + |
| 77 | +CREATE TABLE time_series.location_temp_p12 PARTITION OF time_series.location_temp_p |
| 78 | + FOR VALUES FROM (22) TO (24); |
| 79 | +CREATE INDEX idx_loc_temp_p12 ON time_series.location_temp_p12(event_time); |
| 80 | + |
| 81 | + |
0 commit comments