@@ -28,11 +28,9 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
28
28
Append (actual rows=3000 loops=1)
29
29
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=959 loops=1)
30
30
-> Seq Scan on compress_hyper_2_4_chunk (actual rows=1 loops=1)
31
- -> Seq Scan on _hyper_1_3_chunk (actual rows=0 loops=1)
32
31
-> Custom Scan (ColumnarScan) on _hyper_1_5_chunk (actual rows=2041 loops=1)
33
32
-> Seq Scan on compress_hyper_2_6_chunk (actual rows=3 loops=1)
34
- -> Seq Scan on _hyper_1_5_chunk (actual rows=0 loops=1)
35
- (7 rows)
33
+ (5 rows)
36
34
37
35
SELECT first(time,rn), last(time,rn) FROM (SELECT ROW_NUMBER() OVER () as rn, time FROM metrics) sub;
38
36
first | last
@@ -45,13 +43,11 @@ ROLLBACK;
45
43
BEGIN;
46
44
COPY metrics FROM PROGRAM 'seq 3000 | xargs -II date -d "2025-01-01 - I minute" +"%Y-%m-%d %H:%M:%S,d1,0.I"' WITH (FORMAT CSV);
47
45
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
48
- QUERY PLAN
49
- ---------------------------------------------------------------------------------
50
- Append (actual rows=3000 loops=1)
51
- -> Custom Scan (ColumnarScan) on _hyper_1_7_chunk (actual rows=3000 loops=1)
52
- -> Seq Scan on compress_hyper_2_8_chunk (actual rows=3 loops=1)
53
- -> Seq Scan on _hyper_1_7_chunk (actual rows=0 loops=1)
54
- (4 rows)
46
+ QUERY PLAN
47
+ ---------------------------------------------------------------------------
48
+ Custom Scan (ColumnarScan) on _hyper_1_7_chunk (actual rows=3000 loops=1)
49
+ -> Seq Scan on compress_hyper_2_8_chunk (actual rows=3 loops=1)
50
+ (2 rows)
55
51
56
52
SELECT first(time,rn), last(time,rn) FROM (SELECT ROW_NUMBER() OVER () as rn, time FROM metrics) sub;
57
53
first | last
@@ -70,11 +66,9 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
70
66
Append (actual rows=3000 loops=1)
71
67
-> Custom Scan (ColumnarScan) on _hyper_1_9_chunk (actual rows=959 loops=1)
72
68
-> Seq Scan on compress_hyper_2_10_chunk (actual rows=1 loops=1)
73
- -> Seq Scan on _hyper_1_9_chunk (actual rows=0 loops=1)
74
69
-> Custom Scan (ColumnarScan) on _hyper_1_11_chunk (actual rows=2041 loops=1)
75
70
-> Seq Scan on compress_hyper_2_12_chunk (actual rows=3 loops=1)
76
- -> Seq Scan on _hyper_1_11_chunk (actual rows=0 loops=1)
77
- (7 rows)
71
+ (5 rows)
78
72
79
73
SELECT first(time,rn), last(time,rn) FROM (SELECT ROW_NUMBER() OVER () as rn, time FROM metrics) sub;
80
74
first | last
@@ -87,13 +81,11 @@ ROLLBACK;
87
81
BEGIN;
88
82
COPY metrics FROM PROGRAM 'seq 3000 | xargs -II date -d "2025-01-01 - I minute" +"%Y-%m-%d %H:%M:%S,d1,0.I"' WITH (FORMAT CSV);
89
83
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
90
- QUERY PLAN
91
- ----------------------------------------------------------------------------------
92
- Append (actual rows=3000 loops=1)
93
- -> Custom Scan (ColumnarScan) on _hyper_1_13_chunk (actual rows=3000 loops=1)
94
- -> Seq Scan on compress_hyper_2_14_chunk (actual rows=3 loops=1)
95
- -> Seq Scan on _hyper_1_13_chunk (actual rows=0 loops=1)
96
- (4 rows)
84
+ QUERY PLAN
85
+ ----------------------------------------------------------------------------
86
+ Custom Scan (ColumnarScan) on _hyper_1_13_chunk (actual rows=3000 loops=1)
87
+ -> Seq Scan on compress_hyper_2_14_chunk (actual rows=3 loops=1)
88
+ (2 rows)
97
89
98
90
SELECT first(time,rn), last(time,rn) FROM (SELECT ROW_NUMBER() OVER () as rn, time FROM metrics) sub;
99
91
first | last
@@ -136,19 +128,17 @@ SET timescaledb.enable_direct_compress_copy = true;
136
128
SET timescaledb.enable_direct_compress_copy_client_sorted = true;
137
129
COPY metrics FROM PROGRAM 'seq 3000 | xargs -II date -d "2025-01-01 - I minute" +"%Y-%m-%d %H:%M:%S,d1,0.I"' WITH (FORMAT CSV);
138
130
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
139
- QUERY PLAN
140
- ----------------------------------------------------------------------------------
141
- Append (actual rows=3000 loops=1)
142
- -> Custom Scan (ColumnarScan) on _hyper_1_19_chunk (actual rows=3000 loops=1)
143
- -> Seq Scan on compress_hyper_2_20_chunk (actual rows=3 loops=1)
144
- -> Seq Scan on _hyper_1_19_chunk (actual rows=0 loops=1)
145
- (4 rows)
131
+ QUERY PLAN
132
+ ----------------------------------------------------------------------------
133
+ Custom Scan (ColumnarScan) on _hyper_1_19_chunk (actual rows=3000 loops=1)
134
+ -> Seq Scan on compress_hyper_2_20_chunk (actual rows=3 loops=1)
135
+ (2 rows)
146
136
147
137
-- status should be 9
148
138
SELECT DISTINCT status FROM _timescaledb_catalog.chunk WHERE compressed_chunk_id IS NOT NULL;
149
139
status
150
140
--------
151
- 9
141
+ 1
152
142
(1 row)
153
143
154
144
ROLLBACK;
@@ -158,19 +148,17 @@ SET timescaledb.enable_direct_compress_copy = true;
158
148
SET timescaledb.enable_direct_compress_copy_client_sorted = false;
159
149
COPY metrics FROM PROGRAM 'seq 3000 | xargs -II date -d "2025-01-01 - I minute" +"%Y-%m-%d %H:%M:%S,d1,0.I"' WITH (FORMAT CSV);
160
150
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
161
- QUERY PLAN
162
- ----------------------------------------------------------------------------------
163
- Append (actual rows=3000 loops=1)
164
- -> Custom Scan (ColumnarScan) on _hyper_1_21_chunk (actual rows=3000 loops=1)
165
- -> Seq Scan on compress_hyper_2_22_chunk (actual rows=3 loops=1)
166
- -> Seq Scan on _hyper_1_21_chunk (actual rows=0 loops=1)
167
- (4 rows)
151
+ QUERY PLAN
152
+ ----------------------------------------------------------------------------
153
+ Custom Scan (ColumnarScan) on _hyper_1_21_chunk (actual rows=3000 loops=1)
154
+ -> Seq Scan on compress_hyper_2_22_chunk (actual rows=3 loops=1)
155
+ (2 rows)
168
156
169
157
-- status should be 11
170
158
SELECT DISTINCT status FROM _timescaledb_catalog.chunk WHERE compressed_chunk_id IS NOT NULL;
171
159
status
172
160
--------
173
- 11
161
+ 3
174
162
(1 row)
175
163
176
164
ROLLBACK;
@@ -181,13 +169,11 @@ SET timescaledb.enable_direct_compress_copy = true;
181
169
SET timescaledb.enable_direct_compress_copy_client_sorted = true;
182
170
COPY metrics FROM PROGRAM 'seq 0 0.2 9.8 | sed -e ''s!.[0-9]$!!'' | xargs -II date -d "2025-01-01 - I minute" +"%Y-%m-%d %H:%M:%S,dI,0.I"' WITH (FORMAT CSV);
183
171
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM metrics;
184
- QUERY PLAN
185
- --------------------------------------------------------------------------------
186
- Append (actual rows=50 loops=1)
187
- -> Custom Scan (ColumnarScan) on _hyper_1_23_chunk (actual rows=50 loops=1)
188
- -> Seq Scan on compress_hyper_2_24_chunk (actual rows=10 loops=1)
189
- -> Seq Scan on _hyper_1_23_chunk (actual rows=0 loops=1)
190
- (4 rows)
172
+ QUERY PLAN
173
+ --------------------------------------------------------------------------
174
+ Custom Scan (ColumnarScan) on _hyper_1_23_chunk (actual rows=50 loops=1)
175
+ -> Seq Scan on compress_hyper_2_24_chunk (actual rows=10 loops=1)
176
+ (2 rows)
191
177
192
178
SELECT format('%I.%I',schema_name,table_name) AS "COMPRESSED_CHUNK" FROM _timescaledb_catalog.chunk where compressed_chunk_id IS NULL \gset
193
179
-- should have 10 batches
@@ -215,3 +201,107 @@ SELECT DISTINCT status FROM _timescaledb_catalog.chunk WHERE compressed_chunk_id
215
201
(0 rows)
216
202
217
203
ROLLBACK;
204
+ -- test chunk status handling
205
+ CREATE TABLE metrics_status(time timestamptz) WITH (tsdb.hypertable,tsdb.partition_column='time');
206
+ -- normal insert should result in chunk status 0
207
+ INSERT INTO metrics_status SELECT '2025-01-01';
208
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
209
+ chunk_status_text
210
+ -------------------
211
+ {}
212
+ (1 row)
213
+
214
+ BEGIN;
215
+ -- compressed copy into uncompressed chunk should result in chunk status 11 (compressed,partial,unordered)
216
+ SET timescaledb.enable_direct_compress_copy = true;
217
+ SET timescaledb.enable_direct_compress_copy_client_sorted = false;
218
+ COPY metrics_status FROM STDIN;
219
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
220
+ chunk_status_text
221
+ --------------------------------
222
+ {COMPRESSED,UNORDERED,PARTIAL}
223
+ (1 row)
224
+
225
+ ROLLBACK;
226
+ BEGIN;
227
+ -- compressed sorted copy into uncompressed chunk should result in chunk status 9 (compressed,partial)
228
+ SET timescaledb.enable_direct_compress_copy = true;
229
+ SET timescaledb.enable_direct_compress_copy_client_sorted = true;
230
+ COPY metrics_status FROM STDIN;
231
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
232
+ chunk_status_text
233
+ ----------------------
234
+ {COMPRESSED,PARTIAL}
235
+ (1 row)
236
+
237
+ ROLLBACK;
238
+ TRUNCATE metrics_status;
239
+ BEGIN;
240
+ -- compressed copy into new chunk should result in chunk status 3 (compressed,unordered)
241
+ SET timescaledb.enable_direct_compress_copy = true;
242
+ SET timescaledb.enable_direct_compress_copy_client_sorted = false;
243
+ COPY metrics_status FROM STDIN;
244
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
245
+ chunk_status_text
246
+ ------------------------
247
+ {COMPRESSED,UNORDERED}
248
+ (1 row)
249
+
250
+ ROLLBACK;
251
+ BEGIN;
252
+ -- compressed sorted copy into new chunk should result in chunk status 1 (compressed)
253
+ SET timescaledb.enable_direct_compress_copy = true;
254
+ SET timescaledb.enable_direct_compress_copy_client_sorted = true;
255
+ COPY metrics_status FROM STDIN;
256
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
257
+ chunk_status_text
258
+ -------------------
259
+ {COMPRESSED}
260
+ (1 row)
261
+
262
+ ROLLBACK;
263
+ SET timescaledb.enable_direct_compress_copy = false;
264
+ SET timescaledb.enable_direct_compress_copy_client_sorted = false;
265
+ INSERT INTO metrics_status SELECT '2025-01-01';
266
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
267
+ chunk_status_text
268
+ -------------------
269
+ {}
270
+ (1 row)
271
+
272
+ SELECT compress_chunk(show_chunks('metrics_status'));
273
+ compress_chunk
274
+ -----------------------------------------
275
+ _timescaledb_internal._hyper_3_33_chunk
276
+ (1 row)
277
+
278
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
279
+ chunk_status_text
280
+ -------------------
281
+ {COMPRESSED}
282
+ (1 row)
283
+
284
+ BEGIN;
285
+ -- compressed copy into fully compressed chunk should result in chunk status 3 (compressed,unordered)
286
+ SET timescaledb.enable_direct_compress_copy = true;
287
+ SET timescaledb.enable_direct_compress_copy_client_sorted = false;
288
+ COPY metrics_status FROM STDIN;
289
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
290
+ chunk_status_text
291
+ ------------------------
292
+ {COMPRESSED,UNORDERED}
293
+ (1 row)
294
+
295
+ ROLLBACK;
296
+ BEGIN;
297
+ -- compressed copy new chunk should result in chunk status 1 (compressed)
298
+ SET timescaledb.enable_direct_compress_copy = true;
299
+ SET timescaledb.enable_direct_compress_copy_client_sorted = true;
300
+ COPY metrics_status FROM STDIN;
301
+ SELECT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics_status') chunk;
302
+ chunk_status_text
303
+ -------------------
304
+ {COMPRESSED}
305
+ (1 row)
306
+
307
+ ROLLBACK;
0 commit comments