-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathmerge_dml.out
More file actions
264 lines (257 loc) · 10.3 KB
/
Copy pathmerge_dml.out
File metadata and controls
264 lines (257 loc) · 10.3 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- create source table
CREATE TABLE source (
filler_1 int,
filler_2 int,
filler_3 int,
time timestamptz NOT NULL,
device_id int
);
INSERT INTO source (time, device_id, filler_2, filler_3, filler_1)
SELECT time,
device_id,
device_id + 134,
device_id + 209,
device_id + 0.50127
FROM generate_series('2000-01-01 0:00:00+0'::timestamptz, '2000-01-05 23:55:00+0', '20m') gtime (time),
generate_series(1, 5, 1) gdevice (device_id);
-- create corresponding PG tables to compare against hypertables
CREATE table metrics_pg as SELECT * FROM metrics;
CREATE table metrics_space_pg as SELECT * FROM metrics_space;
CREATE table metrics_compressed_pg as SELECT * FROM metrics_compressed;
CREATE table metrics_space_compressed_pg as SELECT * FROM metrics_space_compressed;
-- MERGE UDPATE matched rows for normal PG tables
MERGE INTO metrics_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics_pg);
-- MERGE UDPATE matched rows for hypertable
MERGE INTO metrics t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics_pg);
SELECT CASE WHEN EXISTS (TABLE metrics EXCEPT TABLE metrics_pg)
OR EXISTS (TABLE metrics_pg EXCEPT TABLE metrics)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE DELETE matched rows for normal PG tables
MERGE INTO metrics_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
-- MERGE DELETE matched rows for hypertable
MERGE INTO metrics t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
SELECT CASE WHEN EXISTS (TABLE metrics EXCEPT TABLE metrics_pg)
OR EXISTS (TABLE metrics_pg EXCEPT TABLE metrics)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE INSERT/DELETE matched rows for normal PG tables
MERGE INTO metrics_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- MERGE INSERT/DELETE matched rows for hypertable
MERGE INTO metrics t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- result should be 'same'
SELECT CASE WHEN EXISTS (TABLE metrics EXCEPT TABLE metrics_pg)
OR EXISTS (TABLE metrics_pg EXCEPT TABLE metrics)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE INSERT/DELETE matched rows for normal PG tables
MERGE INTO metrics_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- MERGE INSERT/DELETE matched rows for hypertable
MERGE INTO metrics t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- result should be 'same'
SELECT CASE WHEN EXISTS (TABLE metrics EXCEPT TABLE metrics_pg)
OR EXISTS (TABLE metrics_pg EXCEPT TABLE metrics)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE UDPATE matched rows for normal PG tables
MERGE INTO metrics_space_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics_pg);
-- MERGE UDPATE matched rows for space partitioned hypertable
MERGE INTO metrics_space t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics_pg);
-- result should be 'same'
SELECT CASE WHEN EXISTS (TABLE metrics_space EXCEPT TABLE metrics_space_pg)
OR EXISTS (TABLE metrics_space_pg EXCEPT TABLE metrics_space)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE DELETE matched rows for normal PG tables
MERGE INTO metrics_space_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
-- MERGE DELETE matched rows for space partitioned hypertable
MERGE INTO metrics_space t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
-- result should be 'same'
SELECT CASE WHEN EXISTS (TABLE metrics_space EXCEPT TABLE metrics_space_pg)
OR EXISTS (TABLE metrics_space_pg EXCEPT TABLE metrics_space)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
-- MERGE INSERT matched rows for normal PG tables
MERGE INTO metrics_space_pg t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- MERGE INSERT matched rows for space partitioned hypertable
MERGE INTO metrics_space t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
(s.time, s.device_id, 1,2,3,4);
-- result should be 'same'
SELECT CASE WHEN EXISTS (TABLE metrics_space EXCEPT TABLE metrics_space_pg)
OR EXISTS (TABLE metrics_space_pg EXCEPT TABLE metrics_space)
THEN 'different'
ELSE 'same'
END AS result;
result
--------
same
\set ON_ERROR_STOP 0
-- MERGE UDPATE matched rows for compressed hypertable
-- should report error as UPDATE is not allowed on compressed hypertable
MERGE INTO metrics_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE DELETE matched rows for compressed hypertable
-- should report error as DELETE is not allowed on compressed hypertable
MERGE INTO metrics_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE UDPATE/INSERT matched rows for compressed hypertable
-- should report error as UPDATE is not allowed on compressed hypertable
MERGE INTO metrics_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics)
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
('2021-11-01 00:00:05', 2, 1,2,3,4);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE DELETE/INSERT matched rows for compressed hypertable
-- should report error as DELETE is not allowed on compressed hypertable
MERGE INTO metrics_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
('2021-11-01 00:00:05', 2, 1,2,3,4);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE UDPATE matched rows for space partitioned compressed hypertable
-- should report error as UPDATE is not allowed on compressed hypertable
MERGE INTO metrics_space_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE DELETE matched rows for space partitioned compressed hypertable
-- should report error as DELETE is not allowed on compressed hypertable
MERGE INTO metrics_space_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE;
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE UDPATE/INSERT matched rows for space partitioned compressed hypertable
-- should report error as UPDATE is not allowed on compressed hypertable
MERGE INTO metrics_space_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
UPDATE SET v1 = s.filler_1 * 1.23, v2 = (SELECT DISTINCT count(time) from metrics)
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
('2021-11-01 00:00:05', 2, 1,2,3,4);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
-- MERGE DELETE/INSERT matched rows for space partitioned compressed hypertable
-- should report error as DELETE is not allowed on compressed hypertable
MERGE INTO metrics_space_compressed t
USING source s
ON t.time = s.time AND t.device_id = s.device_id
WHEN MATCHED THEN
DELETE
WHEN NOT MATCHED THEN
INSERT (time, device_id, v0, v1, v2, v3) VALUES
('2021-11-01 00:00:05', 2, 1,2,3,4);
ERROR: The MERGE command with UPDATE/DELETE merge actions is not supported on compressed hypertables
\set ON_ERROR_STOP 1