diff --git a/tsl/src/decompress_chunk/decompress_chunk.c b/tsl/src/decompress_chunk/decompress_chunk.c index c6f8fa006..f91dce46e 100644 --- a/tsl/src/decompress_chunk/decompress_chunk.c +++ b/tsl/src/decompress_chunk/decompress_chunk.c @@ -26,6 +26,7 @@ #include "decompress_chunk/decompress_chunk.h" #include "decompress_chunk/planner.h" #include "decompress_chunk/qual_pushdown.h" +#include "utils.h" #define DECOMPRESS_CHUNK_CPU_TUPLE_COST 0.01 #define DECOMPRESS_CHUNK_BATCH_SIZE 1000 @@ -35,9 +36,65 @@ static CustomPathMethods decompress_chunk_path_methods = { .PlanCustomPath = decompress_chunk_plan_create, }; -static RangeTblEntry *decompress_chunk_make_rte(PlannerInfo *root, Oid compressed_relid, - LOCKMODE lockmode); -static void create_compressed_scan_paths(PlannerInfo *root, DecompressChunkPath *path); +static RangeTblEntry *decompress_chunk_make_rte(Oid compressed_relid, LOCKMODE lockmode); +static void create_compressed_scan_paths(PlannerInfo *root, RelOptInfo *compressed_rel, + int parallel_workers); + +static Path *decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *chunk_rel, + RelOptInfo *compressed_rel, Hypertable *ht, + List *compression_info, int parallel_workers); + +static Index decompress_chunk_add_plannerinfo(PlannerInfo *root, Chunk *chunk); + +void +ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hypertable *ht, + Chunk *chunk) +{ + Index compressed_index; + RelOptInfo *compressed_rel; + Path *path; + List *compression_info = get_hypertablecompression_info(ht->fd.id); + /* + * since we rely on parallel coordination from the scan below + * this node it is probably not beneficial to have more + * than a single worker per chunk + */ + int parallel_workers = 1; + + Assert(chunk->fd.compressed_chunk_id > 0); + + chunk_rel->pathlist = NIL; + chunk_rel->partial_pathlist = NIL; + + /* add RangeTblEntry and RelOptInfo for compressed chunk */ + compressed_index = decompress_chunk_add_plannerinfo(root, chunk); + compressed_rel = root->simple_rel_array[compressed_index]; + + compressed_rel->consider_parallel = chunk_rel->consider_parallel; + + pushdown_quals(root, chunk_rel, compressed_rel, compression_info); + set_baserel_size_estimates(root, compressed_rel); + chunk_rel->rows = compressed_rel->rows * DECOMPRESS_CHUNK_BATCH_SIZE; + create_compressed_scan_paths(root, + compressed_rel, + compressed_rel->consider_parallel ? parallel_workers : 0); + + /* create non-parallel path */ + path = decompress_chunk_path_create(root, chunk_rel, compressed_rel, ht, compression_info, 0); + add_path(chunk_rel, path); + + /* create parallel path */ + if (compressed_rel->consider_parallel && list_length(compressed_rel->partial_pathlist) > 0) + { + path = decompress_chunk_path_create(root, + chunk_rel, + compressed_rel, + ht, + compression_info, + parallel_workers); + add_partial_path(chunk_rel, path); + } +} /* * calculate cost for DecompressChunkPath @@ -56,48 +113,18 @@ cost_decompress_chunk(Path *path, Path *compressed_path) path->total_cost = compressed_path->total_cost + path->rows * DECOMPRESS_CHUNK_CPU_TUPLE_COST; } -Path * -ts_decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht, Chunk *chunk, - Path *subpath) +/* + * create RangeTblEntry and RelOptInfo for the compressed chunk + * and add it to PlannerInfo + */ +static Index +decompress_chunk_add_plannerinfo(PlannerInfo *root, Chunk *chunk) { - DecompressChunkPath *path; Index compressed_index = root->simple_rel_array_size; - Index chunk_index = rel->relid; Chunk *compressed_chunk = ts_chunk_get_by_id(chunk->fd.compressed_chunk_id, 0, true); Oid compressed_relid = compressed_chunk->table_id; - AppendRelInfo *appinfo; + RangeTblEntry *compressed_rte; - path = (DecompressChunkPath *) newNode(sizeof(DecompressChunkPath), T_CustomPath); - - path->chunk_rel = rel; - path->chunk_rte = planner_rt_fetch(chunk_index, root); - path->hypertable_id = ht->fd.id; - path->compression_info = get_hypertablecompression_info(ht->fd.id); - -#if PG96 || PG10 - appinfo = find_childrel_appendrelinfo(root, rel); -#else - appinfo = root->append_rel_array[rel->relid]; -#endif - - path->ht_rte = planner_rt_fetch(appinfo->parent_relid, root); - - path->cpath.path.pathtype = T_CustomScan; - path->cpath.path.parent = rel; - path->cpath.path.pathtarget = rel->reltarget; - path->cpath.path.param_info = subpath->param_info; - - path->cpath.path.parallel_aware = false; - path->cpath.path.parallel_safe = subpath->parallel_safe; - path->cpath.path.parallel_workers = subpath->parallel_workers; - - path->cpath.flags = CUSTOMPATH_SUPPORT_BACKWARD_SCAN; - path->cpath.methods = &decompress_chunk_path_methods; - - /* - * create RangeTblEntry and RelOptInfo for the compressed chunk - * and add it to PlannerInfo - */ root->simple_rel_array_size++; root->simple_rel_array = repalloc(root->simple_rel_array, root->simple_rel_array_size * sizeof(RelOptInfo *)); @@ -109,25 +136,62 @@ ts_decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable * root->append_rel_array[compressed_index] = NULL; #endif - path->compressed_rte = decompress_chunk_make_rte(root, compressed_relid, AccessShareLock); + compressed_rte = decompress_chunk_make_rte(compressed_relid, AccessShareLock); + root->simple_rte_array[compressed_index] = compressed_rte; - root->simple_rte_array[compressed_index] = path->compressed_rte; - root->parse->rtable = lappend(root->parse->rtable, path->compressed_rte); + root->parse->rtable = lappend(root->parse->rtable, compressed_rte); root->simple_rel_array[compressed_index] = NULL; #if PG96 - path->compressed_rel = build_simple_rel(root, compressed_index, RELOPT_BASEREL); + root->simple_rel_array[compressed_index] = + build_simple_rel(root, compressed_index, RELOPT_BASEREL); #else - path->compressed_rel = build_simple_rel(root, compressed_index, NULL); + root->simple_rel_array[compressed_index] = build_simple_rel(root, compressed_index, NULL); #endif - root->simple_rel_array[compressed_index] = path->compressed_rel; - pushdown_quals(path); - set_baserel_size_estimates(root, path->compressed_rel); + return compressed_index; +} + +static Path * +decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *chunk_rel, RelOptInfo *compressed_rel, + Hypertable *ht, List *compression_info, int parallel_workers) +{ + DecompressChunkPath *path; + AppendRelInfo *appinfo; + bool parallel_safe = false; + + path = (DecompressChunkPath *) newNode(sizeof(DecompressChunkPath), T_CustomPath); + + path->chunk_rel = chunk_rel; + path->chunk_rte = planner_rt_fetch(chunk_rel->relid, root); + path->compressed_rel = compressed_rel; + path->compressed_rte = planner_rt_fetch(compressed_rel->relid, root); + path->hypertable_id = ht->fd.id; + path->compression_info = compression_info; + + appinfo = ts_get_appendrelinfo(root, chunk_rel->relid); + path->ht_rte = planner_rt_fetch(appinfo->parent_relid, root); + + path->cpath.path.pathtype = T_CustomScan; + path->cpath.path.parent = chunk_rel; + path->cpath.path.pathtarget = chunk_rel->reltarget; + + path->cpath.flags = CUSTOMPATH_SUPPORT_BACKWARD_SCAN; + path->cpath.methods = &decompress_chunk_path_methods; + path->cpath.path.rows = path->compressed_rel->rows * DECOMPRESS_CHUNK_BATCH_SIZE; - create_compressed_scan_paths(root, path); - path->cpath.custom_paths = list_make1(path->compressed_rel->cheapest_total_path); + if (parallel_workers > 0 && list_length(compressed_rel->partial_pathlist) > 0) + parallel_safe = true; + + path->cpath.path.parallel_aware = false; + path->cpath.path.parallel_safe = parallel_safe; + path->cpath.path.parallel_workers = parallel_workers; + + if (parallel_safe) + path->cpath.custom_paths = list_make1(linitial(compressed_rel->partial_pathlist)); + else + path->cpath.custom_paths = list_make1(compressed_rel->cheapest_total_path); cost_decompress_chunk(&path->cpath.path, path->compressed_rel->cheapest_total_path); @@ -135,24 +199,30 @@ ts_decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable * } static void -create_compressed_scan_paths(PlannerInfo *root, DecompressChunkPath *path) +create_compressed_scan_paths(PlannerInfo *root, RelOptInfo *compressed_rel, int parallel_workers) { - List *pathlist = NIL; Path *compressed_path; - compressed_path = create_seqscan_path(root, path->compressed_rel, NULL, 0); - pathlist = lappend(pathlist, compressed_path); + /* create non parallel scan path */ + compressed_path = create_seqscan_path(root, compressed_rel, NULL, 0); + add_path(compressed_rel, compressed_path); - path->compressed_rel->pathlist = pathlist; + /* create parallel scan path */ + if (compressed_rel->consider_parallel && parallel_workers > 0) + { + compressed_path = create_seqscan_path(root, compressed_rel, NULL, parallel_workers); + Assert(compressed_path->parallel_aware); + add_partial_path(compressed_rel, compressed_path); + } - set_cheapest(path->compressed_rel); + set_cheapest(compressed_rel); } /* * create RangeTblEntry for compressed chunk */ static RangeTblEntry * -decompress_chunk_make_rte(PlannerInfo *root, Oid compressed_relid, LOCKMODE lockmode) +decompress_chunk_make_rte(Oid compressed_relid, LOCKMODE lockmode) { RangeTblEntry *rte = makeNode(RangeTblEntry); Relation r = heap_open(compressed_relid, lockmode); diff --git a/tsl/src/decompress_chunk/decompress_chunk.h b/tsl/src/decompress_chunk/decompress_chunk.h index ee4251cd7..5c7a378b8 100644 --- a/tsl/src/decompress_chunk/decompress_chunk.h +++ b/tsl/src/decompress_chunk/decompress_chunk.h @@ -27,8 +27,8 @@ typedef struct DecompressChunkPath bool reverse; } DecompressChunkPath; -extern Path *ts_decompress_chunk_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht, - Chunk *chunk, Path *subpath); +void ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht, + Chunk *chunk); FormData_hypertable_compression *get_column_compressioninfo(List *hypertable_compression_info, char *column_name); diff --git a/tsl/src/decompress_chunk/qual_pushdown.c b/tsl/src/decompress_chunk/qual_pushdown.c index 470af2114..d2ec16fcd 100644 --- a/tsl/src/decompress_chunk/qual_pushdown.c +++ b/tsl/src/decompress_chunk/qual_pushdown.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -21,158 +22,94 @@ #include "decompress_chunk/qual_pushdown.h" #include "hypertable_compression.h" -static void pushdown_nulltest(DecompressChunkPath *path, NullTest *op); -static void pushdown_opexpr(DecompressChunkPath *path, OpExpr *op); -static void pushdown_scalararrayopexpr(DecompressChunkPath *path, ScalarArrayOpExpr *op); -static bool can_pushdown_var(DecompressChunkPath *path, Var *chunk_var, Var **compressed_var); +typedef struct QualPushdownContext +{ + RelOptInfo *chunk_rel; + RelOptInfo *compressed_rel; + RangeTblEntry *chunk_rte; + RangeTblEntry *compressed_rte; + List *compression_info; + bool can_pushdown; +} QualPushdownContext; + +static bool adjust_expression(Node *node, QualPushdownContext *context); void -pushdown_quals(DecompressChunkPath *path) +pushdown_quals(PlannerInfo *root, RelOptInfo *chunk_rel, RelOptInfo *compressed_rel, + List *compression_info) { ListCell *lc; + QualPushdownContext context = { + .chunk_rel = chunk_rel, + .compressed_rel = compressed_rel, + .chunk_rte = planner_rt_fetch(chunk_rel->relid, root), + .compressed_rte = planner_rt_fetch(compressed_rel->relid, root), + .compression_info = compression_info, + }; - foreach (lc, path->chunk_rel->baserestrictinfo) + foreach (lc, chunk_rel->baserestrictinfo) { RestrictInfo *ri = lfirst(lc); - - switch (nodeTag(ri->clause)) + Expr *expr = copyObject(ri->clause); + context.can_pushdown = true; + adjust_expression((Node *) expr, &context); + if (context.can_pushdown) { - case T_NullTest: - pushdown_nulltest(path, castNode(NullTest, ri->clause)); - break; - case T_OpExpr: - pushdown_opexpr(path, castNode(OpExpr, ri->clause)); - break; - case T_ScalarArrayOpExpr: - pushdown_scalararrayopexpr(path, castNode(ScalarArrayOpExpr, ri->clause)); - break; - default: - break; + compressed_rel->baserestrictinfo = + lappend(compressed_rel->baserestrictinfo, make_simple_restrictinfo(expr)); } } } static bool -can_pushdown_var(DecompressChunkPath *path, Var *chunk_var, Var **compressed_var) +adjust_expression(Node *node, QualPushdownContext *context) { - char *column_name; - FormData_hypertable_compression *compressioninfo; - - Assert(chunk_var->varno == path->chunk_rel->relid); - - /* ignore system attibutes or whole row references */ - if (!IsA(chunk_var, Var) || chunk_var->varattno <= 0) + if (node == NULL) return false; - column_name = get_attname_compat(path->chunk_rte->relid, chunk_var->varattno, false); - compressioninfo = get_column_compressioninfo(path->compression_info, column_name); - - /* we can only push down quals for segmentby columns */ - if (compressioninfo->segmentby_column_index > 0) + switch (nodeTag(node)) { - AttrNumber compressed_attno = get_attnum(path->compressed_rte->relid, column_name); - Var *var = copyObject(chunk_var); - - var->varno = path->compressed_rel->relid; - var->varattno = compressed_attno; - - *compressed_var = var; - - return true; - } - - return false; -} - -static void -pushdown_nulltest(DecompressChunkPath *path, NullTest *op) -{ - Var *compressed_var; - - if (!IsA(op->arg, Var)) - return; - - if (can_pushdown_var(path, castNode(Var, op->arg), &compressed_var)) - { - NullTest *compressed_op = copyObject(op); - RestrictInfo *compressed_ri; - compressed_op->arg = (Expr *) compressed_var; - - compressed_ri = make_simple_restrictinfo((Expr *) compressed_op); - - path->compressed_rel->baserestrictinfo = - lappend(path->compressed_rel->baserestrictinfo, compressed_ri); - } -} - -static void -pushdown_opexpr(DecompressChunkPath *path, OpExpr *op) -{ - bool var_on_left = false; - Expr *left, *right; - - if (list_length(op->args) != 2) - return; - - left = linitial(op->args); - right = lsecond(op->args); - - /* we only support Var OP Const / Const OP Var for now */ - if ((IsA(left, Var) && IsA(right, Const)) || (IsA(left, Const) && IsA(right, Var))) - { - Var *var, *compressed_var; - - if (IsA(left, Var)) - var_on_left = true; - - var = var_on_left ? (Var *) left : (Var *) right; - - /* we can only push down quals for segmentby columns */ - if (can_pushdown_var(path, var, &compressed_var)) + case T_OpExpr: + case T_ScalarArrayOpExpr: + case T_List: + case T_Const: + case T_NullTest: + break; + case T_Var: { - OpExpr *compressed_op = copyObject(op); - RestrictInfo *compressed_ri; + Var *var = castNode(Var, node); + char *column_name; + FormData_hypertable_compression *compressioninfo; + AttrNumber compressed_attno; - if (var_on_left) - compressed_op->args = list_make2(compressed_var, copyObject(right)); - else - compressed_op->args = list_make2(copyObject(left), compressed_var); + /* ignore system attibutes or whole row references */ + if (var->varattno <= 0) + { + context->can_pushdown = false; + return true; + } - compressed_ri = make_simple_restrictinfo((Expr *) compressed_op); + column_name = get_attname_compat(context->chunk_rte->relid, var->varattno, false); + compressioninfo = get_column_compressioninfo(context->compression_info, column_name); - path->compressed_rel->baserestrictinfo = - lappend(path->compressed_rel->baserestrictinfo, compressed_ri); - } - } -} - -static void -pushdown_scalararrayopexpr(DecompressChunkPath *path, ScalarArrayOpExpr *op) -{ - Expr *left, *right; - - if (list_length(op->args) != 2) - return; - - left = linitial(op->args); - right = lsecond(op->args); - - if (IsA(left, Var) && IsA(right, Const)) - { - Var *compressed_var; - - /* we can only push down quals for segmentby columns */ - if (can_pushdown_var(path, castNode(Var, left), &compressed_var)) - { - ScalarArrayOpExpr *compressed_op = copyObject(op); - RestrictInfo *compressed_ri; - - compressed_op->args = list_make2(compressed_var, copyObject(right)); - - compressed_ri = make_simple_restrictinfo((Expr *) compressed_op); - - path->compressed_rel->baserestrictinfo = - lappend(path->compressed_rel->baserestrictinfo, compressed_ri); + /* we can only push down quals for segmentby columns */ + if (compressioninfo->segmentby_column_index <= 0) + { + context->can_pushdown = false; + return true; + } + + compressed_attno = get_attnum(context->compressed_rte->relid, column_name); + var->varno = context->compressed_rel->relid; + var->varattno = compressed_attno; + + break; } + default: + context->can_pushdown = false; + return true; + break; } + + return expression_tree_walker(node, adjust_expression, context); } diff --git a/tsl/src/decompress_chunk/qual_pushdown.h b/tsl/src/decompress_chunk/qual_pushdown.h index be6405a39..88422eb3e 100644 --- a/tsl/src/decompress_chunk/qual_pushdown.h +++ b/tsl/src/decompress_chunk/qual_pushdown.h @@ -8,4 +8,5 @@ #include "decompress_chunk/decompress_chunk.h" -void pushdown_quals(DecompressChunkPath *path); +void pushdown_quals(PlannerInfo *root, RelOptInfo *chunk_rel, RelOptInfo *compressed_rel, + List *compression_info); diff --git a/tsl/src/planner.c b/tsl/src/planner.c index 305270d8d..e10853ca1 100644 --- a/tsl/src/planner.c +++ b/tsl/src/planner.c @@ -36,10 +36,6 @@ tsl_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb Chunk *chunk = ts_chunk_get_by_relid(rte->relid, 0, true); if (chunk->fd.compressed_chunk_id > 0) - { - rel->pathlist = list_make1( - ts_decompress_chunk_path_create(root, rel, ht, chunk, linitial(rel->pathlist))); - rel->partial_pathlist = NIL; - } + ts_decompress_chunk_generate_paths(root, rel, ht, chunk); } } diff --git a/tsl/test/expected/transparent_decompression-10.out b/tsl/test/expected/transparent_decompression-10.out index 0492f18da..0b15780a1 100644 --- a/tsl/test/expected/transparent_decompression-10.out +++ b/tsl/test/expected/transparent_decompression-10.out @@ -24,11 +24,26 @@ INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + ALTER TABLE metrics DROP COLUMN filler_3; INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); ANALYZE metrics; +-- create identical hypertable with space partitioning +CREATE TABLE metrics_space(filler_1 int, filler_2 int, filler_3 int, time timestamptz NOT NULL, device_id int, v1 float, v2 float, v3 float); +SELECT create_hypertable('metrics_space','time','device_id',3); + create_hypertable +---------------------------- + (2,public,metrics_space,t) +(1 row) + +ALTER TABLE metrics_space DROP COLUMN filler_1; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-01 0:00:00+0'::timestamptz,'2000-01-05 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_2; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-06 0:00:00+0'::timestamptz,'2000-01-12 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_3; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ANALYZE metrics_space; -- run queries on uncompressed hypertable and store result \set PREFIX '' \set ECHO none --- compress some chunks on the hypertable -ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time asc nulls last', timescaledb.compress_segmentby='device_id'); +-- compress first and last chunk on the hypertable +ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); WARNING: Timescale License expired SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'); compress_chunk @@ -42,6 +57,39 @@ SELECT compress_chunk('_timescaledb_internal._hyper_1_3_chunk'); (1 row) +-- compress some chunks on space partitioned hypertable +-- we compress all chunks of first time slice, none of second, and 2 of the last time slice +ALTER TABLE metrics_space SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_4_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_5_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_6_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_10_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_11_chunk'); + compress_chunk +---------------- + +(1 row) + -- run queries on compressed hypertable and store result \set PREFIX '' \set ECHO none @@ -56,12 +104,13 @@ SELECT -- will be not stable and differ depending on worker assignment SET max_parallel_workers_per_gather TO 0; -- get explain for queries on hypertable with compression +\set TEST_TABLE 'metrics' \ir :TEST_QUERY_NAME -- 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. -- this should use DecompressChunk node -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time LIMIT 5; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=5 loops=1) @@ -72,7 +121,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -81,12 +130,12 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test RECORD by itself -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Custom Scan (ChunkAppend) on metrics (actual rows=5472 loops=1) @@ -96,7 +145,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -107,7 +156,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (21 rows) @@ -119,8 +168,8 @@ SET max_parallel_workers_per_gather TO 0; COALESCE(NULL,v1,v2) AS "coalesce", NULL AS "NULL", 'text' AS "text", - metrics AS "RECORD" -FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------------ Sort (actual rows=10944 loops=1) @@ -130,7 +179,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10944 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=2880 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=4 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=4 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 6 -> Seq Scan on _hyper_1_2_chunk (actual rows=4032 loops=1) @@ -138,31 +187,31 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 6048 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=4032 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=6 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=6 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 9 (18 rows) -- test empty targetlist -:PREFIX SELECT FROM metrics; +:PREFIX SELECT FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------- Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (6 rows) -- test empty resultset -:PREFIX SELECT * FROM metrics WHERE device_id < 0; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; QUERY PLAN --------------------------------------------------------------------------------- Append (actual rows=0 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=0 loops=1) Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=0 loops=1) Filter: (device_id < 0) Rows Removed by Filter: 10 -> Seq Scan on _hyper_1_2_chunk (actual rows=0 loops=1) @@ -170,26 +219,26 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 10080 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=0 loops=1) Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=0 loops=1) Filter: (device_id < 0) Rows Removed by Filter: 15 (14 rows) -- test targetlist not referencing columns -:PREFIX SELECT 1 FROM metrics; +:PREFIX SELECT 1 FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------------- Result (actual rows=27360 loops=1) -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (7 rows) -- test constraints not present in targetlist -:PREFIX SELECT v1 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN ------------------------------------------------------------------------------------------ Sort (actual rows=5472 loops=1) @@ -198,7 +247,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -206,13 +255,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (17 rows) -- test order not present in targetlist -:PREFIX SELECT v2 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN ------------------------------------------------------------------------------------------ Sort (actual rows=5472 loops=1) @@ -221,7 +270,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -229,19 +278,19 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (17 rows) -- test column with all NULL -:PREFIX SELECT v3 FROM metrics WHERE device_id = 1; +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; QUERY PLAN ------------------------------------------------------------------------------------ Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -249,7 +298,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (14 rows) @@ -258,7 +307,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- test qual pushdown -- -- time is not segment by column so should not be pushed down -:PREFIX SELECT * FROM metrics WHERE time < '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; QUERY PLAN --------------------------------------------------------------------------------------------------------------- Sort (actual rows=10560 loops=1) @@ -267,13 +316,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10560 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=3360 loops=1) Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) (9 rows) -- device_id constraint should be pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -284,7 +333,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -293,12 +342,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test IS NULL / IS NOT NULL -:PREFIX SELECT * FROM metrics WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -308,17 +357,17 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) Filter: (device_id IS NOT NULL) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) Filter: (device_id IS NOT NULL) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) Filter: (device_id IS NOT NULL) (15 rows) -:PREFIX SELECT * FROM metrics WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit (actual rows=0 loops=1) @@ -328,7 +377,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=0 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) Rows Removed by Filter: 10 -> Seq Scan on _hyper_1_2_chunk (actual rows=0 loops=1) @@ -336,13 +385,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 10080 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) Rows Removed by Filter: 15 (18 rows) -- test IN (Const,Const) -:PREFIX SELECT * FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------ Limit (actual rows=10 loops=1) @@ -352,7 +401,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10944 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=2880 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=4 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=4 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 6 -> Seq Scan on _hyper_1_2_chunk (actual rows=4032 loops=1) @@ -360,13 +409,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 6048 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=4032 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=6 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=6 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 9 (18 rows) -- test cast pushdown -:PREFIX SELECT * FROM metrics WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -377,7 +426,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -386,12 +435,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test expressions -:PREFIX SELECT * FROM metrics WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -402,7 +451,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 3) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -411,13 +460,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 3) (19 rows) -- test function calls -- not yet pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -430,14 +479,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = length("substring"(version(), 1, 3))) Rows Removed by Filter: 5760 - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) Filter: (device_id = length("substring"(version(), 1, 3))) -> Sort (never executed) Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = length("substring"(version(), 1, 3))) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) (18 rows) -- @@ -445,7 +494,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- -- test plan time exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------- Sort (actual rows=16795 loops=1) @@ -457,12 +506,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 3365 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (10 rows) -- test runtime exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------- Sort (actual rows=16795 loops=1) @@ -475,24 +524,24 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 3365 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (11 rows) -- test aggregate -:PREFIX SELECT count(*) FROM metrics; +:PREFIX SELECT count(*) FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (7 rows) -- test aggregate with GROUP BY -:PREFIX SELECT count(*) FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN ------------------------------------------------------------------------------------------------- Sort (actual rows=5 loops=1) @@ -502,14 +551,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (11 rows) -- test window functions with GROUP BY -:PREFIX SELECT sum(count(*)) OVER () FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN ------------------------------------------------------------------------------------------------------- Sort (actual rows=5 loops=1) @@ -520,15 +569,15 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (12 rows) -- test CTE :PREFIX WITH -q AS (SELECT v1 FROM metrics ORDER BY time) +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) SELECT * FROM q ORDER BY v1; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- @@ -542,20 +591,20 @@ SELECT * FROM q ORDER BY v1; Sort Key: _hyper_1_1_chunk."time" Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Sort (actual rows=10080 loops=1) Sort Key: _hyper_1_3_chunk."time" Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) -> CTE Scan on q (actual rows=27360 loops=1) (18 rows) -- test CTE join :PREFIX WITH -q1 AS (SELECT time, v1 FROM metrics WHERE device_id=1 ORDER BY time), -q2 AS (SELECT time, v2 FROM metrics WHERE device_id=2 ORDER BY time) +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- @@ -569,7 +618,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -580,7 +629,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 CTE q2 @@ -591,7 +640,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=1440 loops=1) Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_4_chunk compress_hyper_2_4_chunk_1 (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk compress_hyper_3_13_chunk_1 (actual rows=2 loops=1) Filter: (device_id = 2) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=2016 loops=1) @@ -602,7 +651,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=2016 loops=1) Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_5_chunk compress_hyper_2_5_chunk_1 (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk compress_hyper_3_14_chunk_1 (actual rows=3 loops=1) Filter: (device_id = 2) Rows Removed by Filter: 12 -> Sort (actual rows=5472 loops=1) @@ -616,7 +665,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; (54 rows) -- test prepared statement -PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; :PREFIX EXECUTE prep; QUERY PLAN ------------------------------------------------------------------------------------------ @@ -624,7 +673,7 @@ PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -632,7 +681,7 @@ PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (15 rows) @@ -676,15 +725,909 @@ EXECUTE prep; DEALLOCATE prep; -- test explicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1 INNER JOIN metrics m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; -- test implicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1, metrics m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; -- test self-join with sub-query -- XXX FIXME --- :PREFIX SELECT * FROM (SELECT * FROM metrics m1) m1 INNER JOIN (SELECT * FROM metrics m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; -- test system columns -- XXX FIXME ---SELECT xmin FROM metrics ORDER BY time; +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +\set TEST_TABLE 'metrics_space' +\ir :TEST_QUERY_NAME +-- 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. +-- this should use DecompressChunk node +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=5 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=5 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test RECORD by itself +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_space (actual rows=5472 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) +(18 rows) + +-- test expressions +:PREFIX SELECT + time_bucket('1d',time), + v1 + v2 AS "sum", + COALESCE(NULL,v1,v2) AS "coalesce", + NULL AS "NULL", + 'text' AS "text", + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=10944 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Result (actual rows=10944 loops=1) + -> Append (actual rows=10944 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4 + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4032 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 6 +(28 rows) + +-- test empty targetlist +:PREFIX SELECT FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------- + Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(15 rows) + +-- test empty resultset +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 2 + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 6 + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 2 + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 3 + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 9 + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) +(34 rows) + +-- test targetlist not referencing columns +:PREFIX SELECT 1 FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------------- + Result (actual rows=27360 loops=1) + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(16 rows) + +-- test constraints not present in targetlist +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=5472 loops=1) + Sort Key: _hyper_2_10_chunk.v1 + Sort Method: quicksort + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(14 rows) + +-- test order not present in targetlist +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=5472 loops=1) + Sort Key: _hyper_2_10_chunk.v1 + Sort Method: quicksort + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(14 rows) + +-- test column with all NULL +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; + QUERY PLAN +------------------------------------------------------------------------------------- + Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(11 rows) + +-- +-- test qual pushdown +-- +-- time is not segment by column so should not be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort (actual rows=10560 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=10560 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=672 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 1344 + -> Index Scan using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=2016 loops=1) + Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_2_9_chunk (actual rows=672 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 1344 +(21 rows) + +-- device_id constraint should be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test IS NULL / IS NOT NULL +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: top-N heapsort + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) +(33 rows) + +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------ + Limit (actual rows=0 loops=1) + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 2 + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 6 + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 2 + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 3 + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 9 + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) +(38 rows) + +-- test IN (Const,Const) +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: top-N heapsort + -> Append (actual rows=10944 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4 + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4032 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 6 +(28 rows) + +-- test cast pushdown +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test expressions +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id = 3) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed) + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed) + Filter: (device_id = 3) +(14 rows) + +-- test function calls +-- not yet pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Merge Append (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + Rows Removed by Filter: 4320 + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: top-N heapsort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (never executed) + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Merge Append (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + -> Sort (never executed) + Sort Key: _hyper_2_11_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_11_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_19_chunk (never executed) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) +(60 rows) + +-- +-- test constraint exclusion +-- +-- test plan time exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=16795 loops=1) + Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=16795 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=1343 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 673 + -> Seq Scan on _hyper_2_8_chunk (actual rows=4029 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 2019 + -> Seq Scan on _hyper_2_9_chunk (actual rows=1343 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 673 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) +(21 rows) + +-- test runtime exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=16795 loops=1) + Sort Key: metrics_space."time", metrics_space.device_id + Sort Method: quicksort + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=16795 loops=1) + -> Merge Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 4320 + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (actual rows=6715 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=1343 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 673 + -> Seq Scan on _hyper_2_8_chunk (actual rows=4029 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 2019 + -> Seq Scan on _hyper_2_9_chunk (actual rows=1343 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 673 + -> Merge Append (actual rows=10080 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) +(36 rows) + +-- test aggregate +:PREFIX SELECT count(*) FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------------- + Aggregate (actual rows=1 loops=1) + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(16 rows) + +-- test aggregate with GROUP BY +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> HashAggregate (actual rows=5 loops=1) + Group Key: _hyper_2_4_chunk.device_id + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(20 rows) + +-- test window functions with GROUP BY +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> WindowAgg (actual rows=5 loops=1) + -> HashAggregate (actual rows=5 loops=1) + Group Key: _hyper_2_4_chunk.device_id + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(21 rows) + +-- test CTE +:PREFIX WITH +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) +SELECT * FROM q ORDER BY v1; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------- + Sort (actual rows=27360 loops=1) + Sort Key: q.v1 + Sort Method: quicksort + CTE q + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=27360 loops=1) + Order: metrics_space."time" + -> Merge Append (actual rows=7200 loops=1) + Sort Key: _hyper_2_4_chunk."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Sort (actual rows=4320 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=4320 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (actual rows=10080 loops=1) + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Merge Append (actual rows=10080 loops=1) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Sort (actual rows=6048 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=6048 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (actual rows=2016 loops=1) + -> CTE Scan on q (actual rows=27360 loops=1) +(57 rows) + +-- test CTE join +:PREFIX WITH +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) +SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------ + Merge Join (actual rows=5472 loops=1) + Merge Cond: (q1."time" = q2."time") + CTE q1 + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=5472 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + CTE q2 + -> Custom Scan (ChunkAppend) on metrics_space metrics_space_1 (actual rows=5472 loops=1) + Order: metrics_space_1."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = 2) + Rows Removed by Filter: 4 + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=2016 loops=1) + Index Cond: (device_id = 2) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = 2) + Rows Removed by Filter: 6 + -> Sort (actual rows=5472 loops=1) + Sort Key: q1."time" + Sort Method: quicksort + -> CTE Scan on q1 (actual rows=5472 loops=1) + -> Sort (actual rows=5472 loops=1) + Sort Key: q2."time" + Sort Method: quicksort + -> CTE Scan on q2 (actual rows=5472 loops=1) +(50 rows) + +-- test prepared statement +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; +:PREFIX EXECUTE prep; + QUERY PLAN +------------------------------------------------------------------------------------------- + Aggregate (actual rows=1 loops=1) + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(12 rows) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +DEALLOCATE prep; +-- test explicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; +-- test implicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- test self-join with sub-query +-- XXX FIXME +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- test system columns +-- XXX FIXME +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +-- run query with parallel enabled to ensure nothing is preventing parallel execution +-- this is just a sanity check, the result queries dont run with parallel disabled +SET max_parallel_workers_per_gather TO 4; +EXPLAIN (costs off) SELECT * FROM metrics ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk + -> Seq Scan on compress_hyper_3_13_chunk + -> Seq Scan on _hyper_1_2_chunk + -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk + -> Seq Scan on compress_hyper_3_14_chunk +(8 rows) + +EXPLAIN (costs off) SELECT * FROM metrics_space ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(17 rows) + -- diff compressed and uncompressed results :DIFF_CMD diff --git a/tsl/test/expected/transparent_decompression-11.out b/tsl/test/expected/transparent_decompression-11.out index 0492f18da..15e415eb9 100644 --- a/tsl/test/expected/transparent_decompression-11.out +++ b/tsl/test/expected/transparent_decompression-11.out @@ -24,11 +24,26 @@ INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + ALTER TABLE metrics DROP COLUMN filler_3; INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); ANALYZE metrics; +-- create identical hypertable with space partitioning +CREATE TABLE metrics_space(filler_1 int, filler_2 int, filler_3 int, time timestamptz NOT NULL, device_id int, v1 float, v2 float, v3 float); +SELECT create_hypertable('metrics_space','time','device_id',3); + create_hypertable +---------------------------- + (2,public,metrics_space,t) +(1 row) + +ALTER TABLE metrics_space DROP COLUMN filler_1; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-01 0:00:00+0'::timestamptz,'2000-01-05 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_2; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-06 0:00:00+0'::timestamptz,'2000-01-12 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_3; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ANALYZE metrics_space; -- run queries on uncompressed hypertable and store result \set PREFIX '' \set ECHO none --- compress some chunks on the hypertable -ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time asc nulls last', timescaledb.compress_segmentby='device_id'); +-- compress first and last chunk on the hypertable +ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); WARNING: Timescale License expired SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'); compress_chunk @@ -42,6 +57,39 @@ SELECT compress_chunk('_timescaledb_internal._hyper_1_3_chunk'); (1 row) +-- compress some chunks on space partitioned hypertable +-- we compress all chunks of first time slice, none of second, and 2 of the last time slice +ALTER TABLE metrics_space SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_4_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_5_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_6_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_10_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_11_chunk'); + compress_chunk +---------------- + +(1 row) + -- run queries on compressed hypertable and store result \set PREFIX '' \set ECHO none @@ -56,12 +104,13 @@ SELECT -- will be not stable and differ depending on worker assignment SET max_parallel_workers_per_gather TO 0; -- get explain for queries on hypertable with compression +\set TEST_TABLE 'metrics' \ir :TEST_QUERY_NAME -- 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. -- this should use DecompressChunk node -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time LIMIT 5; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=5 loops=1) @@ -72,7 +121,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -81,12 +130,12 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test RECORD by itself -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Custom Scan (ChunkAppend) on metrics (actual rows=5472 loops=1) @@ -96,7 +145,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -107,7 +156,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (21 rows) @@ -119,8 +168,8 @@ SET max_parallel_workers_per_gather TO 0; COALESCE(NULL,v1,v2) AS "coalesce", NULL AS "NULL", 'text' AS "text", - metrics AS "RECORD" -FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------------ Sort (actual rows=10944 loops=1) @@ -130,7 +179,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10944 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=2880 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=4 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=4 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 6 -> Seq Scan on _hyper_1_2_chunk (actual rows=4032 loops=1) @@ -138,31 +187,31 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 6048 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=4032 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=6 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=6 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 9 (18 rows) -- test empty targetlist -:PREFIX SELECT FROM metrics; +:PREFIX SELECT FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------- Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (6 rows) -- test empty resultset -:PREFIX SELECT * FROM metrics WHERE device_id < 0; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; QUERY PLAN --------------------------------------------------------------------------------- Append (actual rows=0 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=0 loops=1) Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=0 loops=1) Filter: (device_id < 0) Rows Removed by Filter: 10 -> Seq Scan on _hyper_1_2_chunk (actual rows=0 loops=1) @@ -170,26 +219,26 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 10080 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=0 loops=1) Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=0 loops=1) Filter: (device_id < 0) Rows Removed by Filter: 15 (14 rows) -- test targetlist not referencing columns -:PREFIX SELECT 1 FROM metrics; +:PREFIX SELECT 1 FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------------- Result (actual rows=27360 loops=1) -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (7 rows) -- test constraints not present in targetlist -:PREFIX SELECT v1 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN ------------------------------------------------------------------------------------------ Sort (actual rows=5472 loops=1) @@ -198,7 +247,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -206,13 +255,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (17 rows) -- test order not present in targetlist -:PREFIX SELECT v2 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN ------------------------------------------------------------------------------------------ Sort (actual rows=5472 loops=1) @@ -221,7 +270,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -229,19 +278,19 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (17 rows) -- test column with all NULL -:PREFIX SELECT v3 FROM metrics WHERE device_id = 1; +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; QUERY PLAN ------------------------------------------------------------------------------------ Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -249,7 +298,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (14 rows) @@ -258,7 +307,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- test qual pushdown -- -- time is not segment by column so should not be pushed down -:PREFIX SELECT * FROM metrics WHERE time < '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; QUERY PLAN --------------------------------------------------------------------------------------------------------------- Sort (actual rows=10560 loops=1) @@ -267,13 +316,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10560 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=3360 loops=1) Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) (9 rows) -- device_id constraint should be pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -284,7 +333,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -293,12 +342,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test IS NULL / IS NOT NULL -:PREFIX SELECT * FROM metrics WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -308,17 +357,17 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) Filter: (device_id IS NOT NULL) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) Filter: (device_id IS NOT NULL) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) Filter: (device_id IS NOT NULL) (15 rows) -:PREFIX SELECT * FROM metrics WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit (actual rows=0 loops=1) @@ -328,7 +377,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=0 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) Rows Removed by Filter: 10 -> Seq Scan on _hyper_1_2_chunk (actual rows=0 loops=1) @@ -336,13 +385,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 10080 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=0 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=0 loops=1) Filter: (device_id IS NULL) Rows Removed by Filter: 15 (18 rows) -- test IN (Const,Const) -:PREFIX SELECT * FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------ Limit (actual rows=10 loops=1) @@ -352,7 +401,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append (actual rows=10944 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=2880 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=4 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=4 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 6 -> Seq Scan on _hyper_1_2_chunk (actual rows=4032 loops=1) @@ -360,13 +409,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 6048 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=4032 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=6 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=6 loops=1) Filter: (device_id = ANY ('{1,2}'::integer[])) Rows Removed by Filter: 9 (18 rows) -- test cast pushdown -:PREFIX SELECT * FROM metrics WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -377,7 +426,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -386,12 +435,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 1) (19 rows) -- test expressions -:PREFIX SELECT * FROM metrics WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -402,7 +451,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Method: top-N heapsort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 3) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) @@ -411,13 +460,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) Filter: (device_id = 3) (19 rows) -- test function calls -- not yet pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) @@ -430,14 +479,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = length("substring"(version(), 1, 3))) Rows Removed by Filter: 5760 - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed) Filter: (device_id = length("substring"(version(), 1, 3))) -> Sort (never executed) Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (device_id = length("substring"(version(), 1, 3))) - -> Seq Scan on compress_hyper_2_5_chunk (never executed) + -> Seq Scan on compress_hyper_3_14_chunk (never executed) (18 rows) -- @@ -445,7 +494,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- -- test plan time exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------- Sort (actual rows=16795 loops=1) @@ -457,12 +506,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 3365 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (10 rows) -- test runtime exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------- Sort (actual rows=16795 loops=1) @@ -475,24 +524,24 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Rows Removed by Filter: 3365 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (11 rows) -- test aggregate -:PREFIX SELECT count(*) FROM metrics; +:PREFIX SELECT count(*) FROM :TEST_TABLE; QUERY PLAN ------------------------------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (7 rows) -- test aggregate with GROUP BY -:PREFIX SELECT count(*) FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN ------------------------------------------------------------------------------------------------- Sort (actual rows=5 loops=1) @@ -502,14 +551,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (11 rows) -- test window functions with GROUP BY -:PREFIX SELECT sum(count(*)) OVER () FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN ------------------------------------------------------------------------------------------------------- Sort (actual rows=5 loops=1) @@ -520,15 +569,15 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append (actual rows=27360 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Seq Scan on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) (12 rows) -- test CTE :PREFIX WITH -q AS (SELECT v1 FROM metrics ORDER BY time) +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) SELECT * FROM q ORDER BY v1; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- @@ -542,20 +591,20 @@ SELECT * FROM q ORDER BY v1; Sort Key: _hyper_1_1_chunk."time" Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=7200 loops=1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=10 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=10 loops=1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=10080 loops=1) -> Sort (actual rows=10080 loops=1) Sort Key: _hyper_1_3_chunk."time" Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=10080 loops=1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=15 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=15 loops=1) -> CTE Scan on q (actual rows=27360 loops=1) (18 rows) -- test CTE join :PREFIX WITH -q1 AS (SELECT time, v1 FROM metrics WHERE device_id=1 ORDER BY time), -q2 AS (SELECT time, v2 FROM metrics WHERE device_id=2 ORDER BY time) +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- @@ -569,7 +618,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -580,7 +629,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 CTE q2 @@ -591,7 +640,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=1440 loops=1) Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_4_chunk compress_hyper_2_4_chunk_1 (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk compress_hyper_3_13_chunk_1 (actual rows=2 loops=1) Filter: (device_id = 2) Rows Removed by Filter: 8 -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=2016 loops=1) @@ -602,7 +651,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Method: quicksort -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=2016 loops=1) Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_5_chunk compress_hyper_2_5_chunk_1 (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk compress_hyper_3_14_chunk_1 (actual rows=3 loops=1) Filter: (device_id = 2) Rows Removed by Filter: 12 -> Sort (actual rows=5472 loops=1) @@ -616,7 +665,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; (54 rows) -- test prepared statement -PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; :PREFIX EXECUTE prep; QUERY PLAN ------------------------------------------------------------------------------------------ @@ -624,7 +673,7 @@ PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; -> Append (actual rows=5472 loops=1) -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1440 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk (actual rows=2 loops=1) + -> Seq Scan on compress_hyper_3_13_chunk (actual rows=2 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 8 -> Seq Scan on _hyper_1_2_chunk (actual rows=2016 loops=1) @@ -632,7 +681,7 @@ PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; Rows Removed by Filter: 8064 -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (actual rows=2016 loops=1) Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk (actual rows=3 loops=1) + -> Seq Scan on compress_hyper_3_14_chunk (actual rows=3 loops=1) Filter: (device_id = 1) Rows Removed by Filter: 12 (15 rows) @@ -676,15 +725,909 @@ EXECUTE prep; DEALLOCATE prep; -- test explicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1 INNER JOIN metrics m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; -- test implicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1, metrics m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; -- test self-join with sub-query -- XXX FIXME --- :PREFIX SELECT * FROM (SELECT * FROM metrics m1) m1 INNER JOIN (SELECT * FROM metrics m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; -- test system columns -- XXX FIXME ---SELECT xmin FROM metrics ORDER BY time; +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +\set TEST_TABLE 'metrics_space' +\ir :TEST_QUERY_NAME +-- 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. +-- this should use DecompressChunk node +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=5 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=5 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test RECORD by itself +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_space (actual rows=5472 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) +(18 rows) + +-- test expressions +:PREFIX SELECT + time_bucket('1d',time), + v1 + v2 AS "sum", + COALESCE(NULL,v1,v2) AS "coalesce", + NULL AS "NULL", + 'text' AS "text", + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=10944 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Result (actual rows=10944 loops=1) + -> Append (actual rows=10944 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4 + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4032 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 6 +(28 rows) + +-- test empty targetlist +:PREFIX SELECT FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------- + Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(15 rows) + +-- test empty resultset +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 2 + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 6 + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 2 + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 3 + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=0 loops=1) + Filter: (device_id < 0) + Rows Removed by Filter: 9 + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk (actual rows=0 loops=1) + Index Cond: (device_id < 0) +(34 rows) + +-- test targetlist not referencing columns +:PREFIX SELECT 1 FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------------- + Result (actual rows=27360 loops=1) + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(16 rows) + +-- test constraints not present in targetlist +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=5472 loops=1) + Sort Key: _hyper_2_10_chunk.v1 + Sort Method: quicksort + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(14 rows) + +-- test order not present in targetlist +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=5472 loops=1) + Sort Key: _hyper_2_10_chunk.v1 + Sort Method: quicksort + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(14 rows) + +-- test column with all NULL +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; + QUERY PLAN +------------------------------------------------------------------------------------- + Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(11 rows) + +-- +-- test qual pushdown +-- +-- time is not segment by column so should not be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort (actual rows=10560 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=10560 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Index Scan using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=672 loops=1) + Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=2016 loops=1) + Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (actual rows=672 loops=1) + Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) +(19 rows) + +-- device_id constraint should be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test IS NULL / IS NOT NULL +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: top-N heapsort + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: (device_id IS NOT NULL) +(33 rows) + +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------ + Limit (actual rows=0 loops=1) + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 2 + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 6 + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 2 + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 3 + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=0 loops=1) + Filter: (device_id IS NULL) + Rows Removed by Filter: 9 + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk (actual rows=0 loops=1) + Index Cond: (device_id IS NULL) +(38 rows) + +-- test IN (Const,Const) +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + Sort Method: top-N heapsort + -> Append (actual rows=10944 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4 + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 4032 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = ANY ('{1,2}'::integer[])) + Rows Removed by Filter: 6 +(28 rows) + +-- test cast pushdown +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = 1) + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + Filter: (device_id = 1) +(18 rows) + +-- test expressions +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: top-N heapsort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id = 3) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed) + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed) + Filter: (device_id = 3) +(14 rows) + +-- test function calls +-- not yet pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------- + Limit (actual rows=10 loops=1) + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) + Order: metrics_space."time" + -> Merge Append (actual rows=10 loops=1) + Sort Key: _hyper_2_4_chunk."time" + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=0 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + Rows Removed by Filter: 4320 + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Sort (actual rows=10 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: top-N heapsort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (never executed) + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Merge Append (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_18_chunk (never executed) + -> Sort (never executed) + Sort Key: _hyper_2_11_chunk."time" + -> Sort (never executed) + Sort Key: _hyper_2_11_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_19_chunk (never executed) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed) + Filter: (device_id = length("substring"(version(), 1, 3))) +(60 rows) + +-- +-- test constraint exclusion +-- +-- test plan time exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort (actual rows=16795 loops=1) + Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id + Sort Method: quicksort + -> Append (actual rows=16795 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=1343 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 673 + -> Seq Scan on _hyper_2_8_chunk (actual rows=4029 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 2019 + -> Seq Scan on _hyper_2_9_chunk (actual rows=1343 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + Rows Removed by Filter: 673 + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) +(21 rows) + +-- test runtime exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=16795 loops=1) + Sort Key: metrics_space."time", metrics_space.device_id + Sort Method: quicksort + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=16795 loops=1) + -> Merge Append (actual rows=0 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 4320 + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=0 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 1440 + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (actual rows=6715 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=1343 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 673 + -> Seq Scan on _hyper_2_8_chunk (actual rows=4029 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 2019 + -> Seq Scan on _hyper_2_9_chunk (actual rows=1343 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + Rows Removed by Filter: 673 + -> Merge Append (actual rows=10080 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) +(36 rows) + +-- test aggregate +:PREFIX SELECT count(*) FROM :TEST_TABLE; + QUERY PLAN +------------------------------------------------------------------------------------------- + Aggregate (actual rows=1 loops=1) + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(16 rows) + +-- test aggregate with GROUP BY +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> HashAggregate (actual rows=5 loops=1) + Group Key: _hyper_2_4_chunk.device_id + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(20 rows) + +-- test window functions with GROUP BY +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Sort (actual rows=5 loops=1) + Sort Key: _hyper_2_4_chunk.device_id + Sort Method: quicksort + -> WindowAgg (actual rows=5 loops=1) + -> HashAggregate (actual rows=5 loops=1) + Group Key: _hyper_2_4_chunk.device_id + -> Append (actual rows=27360 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Seq Scan on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Seq Scan on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Seq Scan on _hyper_2_12_chunk (actual rows=2016 loops=1) +(21 rows) + +-- test CTE +:PREFIX WITH +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) +SELECT * FROM q ORDER BY v1; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------- + Sort (actual rows=27360 loops=1) + Sort Key: q.v1 + Sort Method: quicksort + CTE q + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=27360 loops=1) + Order: metrics_space."time" + -> Merge Append (actual rows=7200 loops=1) + Sort Key: _hyper_2_4_chunk."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + -> Sort (actual rows=4320 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=4320 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=4320 loops=1) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=6 loops=1) + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_6_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=1440 loops=1) + -> Seq Scan on compress_hyper_4_17_chunk (actual rows=2 loops=1) + -> Merge Append (actual rows=10080 loops=1) + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=6048 loops=1) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (actual rows=2016 loops=1) + -> Merge Append (actual rows=10080 loops=1) + Sort Key: _hyper_2_10_chunk."time" + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + -> Sort (actual rows=6048 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Sort (actual rows=6048 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=6048 loops=1) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=9 loops=1) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (actual rows=2016 loops=1) + -> CTE Scan on q (actual rows=27360 loops=1) +(57 rows) + +-- test CTE join +:PREFIX WITH +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) +SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------ + Merge Join (actual rows=5472 loops=1) + Merge Cond: (q1."time" = q2."time") + CTE q1 + -> Custom Scan (ChunkAppend) on metrics_space (actual rows=5472 loops=1) + Order: metrics_space."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_4_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_10_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + CTE q2 + -> Custom Scan (ChunkAppend) on metrics_space metrics_space_1 (actual rows=5472 loops=1) + Order: metrics_space_1."time" + -> Sort (actual rows=1440 loops=1) + Sort Key: _hyper_2_5_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1440 loops=1) + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_16_chunk (actual rows=2 loops=1) + Filter: (device_id = 2) + Rows Removed by Filter: 4 + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=2016 loops=1) + Index Cond: (device_id = 2) + -> Sort (actual rows=2016 loops=1) + Sort Key: _hyper_2_11_chunk."time" + Sort Method: quicksort + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (actual rows=2016 loops=1) + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_19_chunk (actual rows=3 loops=1) + Filter: (device_id = 2) + Rows Removed by Filter: 6 + -> Sort (actual rows=5472 loops=1) + Sort Key: q1."time" + Sort Method: quicksort + -> CTE Scan on q1 (actual rows=5472 loops=1) + -> Sort (actual rows=5472 loops=1) + Sort Key: q2."time" + Sort Method: quicksort + -> CTE Scan on q2 (actual rows=5472 loops=1) +(50 rows) + +-- test prepared statement +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; +:PREFIX EXECUTE prep; + QUERY PLAN +------------------------------------------------------------------------------------------- + Aggregate (actual rows=1 loops=1) + -> Append (actual rows=5472 loops=1) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk (actual rows=3 loops=1) + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=1440 loops=1) + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk (actual rows=2 loops=1) + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk (actual rows=2016 loops=1) + Filter: (device_id = 1) +(12 rows) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +DEALLOCATE prep; +-- test explicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; +-- test implicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- test self-join with sub-query +-- XXX FIXME +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- test system columns +-- XXX FIXME +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +-- run query with parallel enabled to ensure nothing is preventing parallel execution +-- this is just a sanity check, the result queries dont run with parallel disabled +SET max_parallel_workers_per_gather TO 4; +EXPLAIN (costs off) SELECT * FROM metrics ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk + -> Seq Scan on compress_hyper_3_13_chunk + -> Seq Scan on _hyper_1_2_chunk + -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk + -> Seq Scan on compress_hyper_3_14_chunk +(8 rows) + +EXPLAIN (costs off) SELECT * FROM metrics_space ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------ + Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Gather + Workers Planned: 4 + -> Parallel Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Parallel Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Parallel Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Parallel Seq Scan on compress_hyper_4_17_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Parallel Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Parallel Seq Scan on compress_hyper_4_19_chunk + -> Parallel Seq Scan on _hyper_2_8_chunk + -> Parallel Seq Scan on _hyper_2_7_chunk + -> Parallel Seq Scan on _hyper_2_9_chunk + -> Parallel Seq Scan on _hyper_2_12_chunk +(19 rows) + -- diff compressed and uncompressed results :DIFF_CMD diff --git a/tsl/test/expected/transparent_decompression-9.6.out b/tsl/test/expected/transparent_decompression-9.6.out index 2e7d434d7..97ae3890a 100644 --- a/tsl/test/expected/transparent_decompression-9.6.out +++ b/tsl/test/expected/transparent_decompression-9.6.out @@ -24,11 +24,26 @@ INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + ALTER TABLE metrics DROP COLUMN filler_3; INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); ANALYZE metrics; +-- create identical hypertable with space partitioning +CREATE TABLE metrics_space(filler_1 int, filler_2 int, filler_3 int, time timestamptz NOT NULL, device_id int, v1 float, v2 float, v3 float); +SELECT create_hypertable('metrics_space','time','device_id',3); + create_hypertable +---------------------------- + (2,public,metrics_space,t) +(1 row) + +ALTER TABLE metrics_space DROP COLUMN filler_1; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-01 0:00:00+0'::timestamptz,'2000-01-05 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_2; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-06 0:00:00+0'::timestamptz,'2000-01-12 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_3; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ANALYZE metrics_space; -- run queries on uncompressed hypertable and store result \set PREFIX '' \set ECHO none --- compress some chunks on the hypertable -ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time asc nulls last', timescaledb.compress_segmentby='device_id'); +-- compress first and last chunk on the hypertable +ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); WARNING: Timescale License expired SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'); compress_chunk @@ -42,6 +57,39 @@ SELECT compress_chunk('_timescaledb_internal._hyper_1_3_chunk'); (1 row) +-- compress some chunks on space partitioned hypertable +-- we compress all chunks of first time slice, none of second, and 2 of the last time slice +ALTER TABLE metrics_space SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_4_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_5_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_6_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_10_chunk'); + compress_chunk +---------------- + +(1 row) + +SELECT compress_chunk('_timescaledb_internal._hyper_2_11_chunk'); + compress_chunk +---------------- + +(1 row) + -- run queries on compressed hypertable and store result \set PREFIX '' \set ECHO none @@ -56,12 +104,13 @@ SELECT -- will be not stable and differ depending on worker assignment SET max_parallel_workers_per_gather TO 0; -- get explain for queries on hypertable with compression +\set TEST_TABLE 'metrics' \ir :TEST_QUERY_NAME -- 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. -- this should use DecompressChunk node -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time LIMIT 5; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; QUERY PLAN --------------------------------------------------------------------------------------------- Limit @@ -71,7 +120,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 1) @@ -79,12 +128,12 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (17 rows) -- test RECORD by itself -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; QUERY PLAN --------------------------------------------------------------------------------------- Custom Scan (ChunkAppend) on metrics @@ -93,7 +142,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 1) @@ -101,7 +150,7 @@ SET max_parallel_workers_per_gather TO 0; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (16 rows) @@ -112,8 +161,8 @@ SET max_parallel_workers_per_gather TO 0; COALESCE(NULL,v1,v2) AS "coalesce", NULL AS "NULL", 'text' AS "text", - metrics AS "RECORD" -FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; QUERY PLAN -------------------------------------------------------------------------- Sort @@ -122,60 +171,60 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) (14 rows) -- test empty targetlist -:PREFIX SELECT FROM metrics; +:PREFIX SELECT FROM :TEST_TABLE; QUERY PLAN --------------------------------------------------------- Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Seq Scan on _hyper_1_2_chunk -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (6 rows) -- test empty resultset -:PREFIX SELECT * FROM metrics WHERE device_id < 0; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; QUERY PLAN --------------------------------------------------------- Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id < 0) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id < 0) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id < 0) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id < 0) (11 rows) -- test targetlist not referencing columns -:PREFIX SELECT 1 FROM metrics; +:PREFIX SELECT 1 FROM :TEST_TABLE; QUERY PLAN --------------------------------------------------------------- Result -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Seq Scan on _hyper_1_2_chunk -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (7 rows) -- test constraints not present in targetlist -:PREFIX SELECT v1 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN --------------------------------------------------------------- Sort @@ -183,18 +232,18 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = 1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (13 rows) -- test order not present in targetlist -:PREFIX SELECT v2 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; QUERY PLAN --------------------------------------------------------------- Sort @@ -202,30 +251,30 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = 1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (13 rows) -- test column with all NULL -:PREFIX SELECT v3 FROM metrics WHERE device_id = 1; +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; QUERY PLAN --------------------------------------------------------- Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = 1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (11 rows) @@ -233,7 +282,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- test qual pushdown -- -- time is not segment by column so should not be pushed down -:PREFIX SELECT * FROM metrics WHERE time < '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; QUERY PLAN ----------------------------------------------------------------------------------------------- Sort @@ -241,13 +290,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) (8 rows) -- device_id constraint should be pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit @@ -257,7 +306,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 1) @@ -265,12 +314,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (17 rows) -- test IS NULL / IS NOT NULL -:PREFIX SELECT * FROM metrics WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN ----------------------------------------------------------------------- Limit @@ -279,17 +328,17 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id IS NOT NULL) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id IS NOT NULL) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id IS NOT NULL) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id IS NOT NULL) (14 rows) -:PREFIX SELECT * FROM metrics WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; QUERY PLAN ----------------------------------------------------------------------- Limit @@ -298,18 +347,18 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id IS NULL) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id IS NULL) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id IS NULL) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id IS NULL) (14 rows) -- test IN (Const,Const) -:PREFIX SELECT * FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; QUERY PLAN -------------------------------------------------------------------------- Limit @@ -318,18 +367,18 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = ANY ('{1,2}'::integer[])) (14 rows) -- test cast pushdown -:PREFIX SELECT * FROM metrics WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit @@ -339,7 +388,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 1) @@ -347,12 +396,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (17 rows) -- test expressions -:PREFIX SELECT * FROM metrics WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit @@ -362,7 +411,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 3) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 3) @@ -370,13 +419,13 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 3) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 3) (17 rows) -- test function calls -- not yet pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; QUERY PLAN --------------------------------------------------------------------------------------------- Limit @@ -387,14 +436,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = length("substring"(version(), 1, 3))) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = length("substring"(version(), 1, 3))) -> Sort Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = length("substring"(version(), 1, 3))) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (16 rows) -- @@ -402,7 +451,7 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- -- test plan time exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------------- Sort @@ -412,12 +461,12 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (8 rows) -- test runtime exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; QUERY PLAN ------------------------------------------------------------------------------------ Sort @@ -428,24 +477,24 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (9 rows) -- test aggregate -:PREFIX SELECT count(*) FROM metrics; +:PREFIX SELECT count(*) FROM :TEST_TABLE; QUERY PLAN --------------------------------------------------------------- Aggregate -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Seq Scan on _hyper_1_2_chunk -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (7 rows) -- test aggregate with GROUP BY -:PREFIX SELECT count(*) FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN --------------------------------------------------------------------- Sort @@ -454,14 +503,14 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Seq Scan on _hyper_1_2_chunk -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (10 rows) -- test window functions with GROUP BY -:PREFIX SELECT sum(count(*)) OVER () FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; QUERY PLAN --------------------------------------------------------------------------- Sort @@ -471,15 +520,15 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; Group Key: _hyper_1_1_chunk.device_id -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Seq Scan on _hyper_1_2_chunk -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk (11 rows) -- test CTE :PREFIX WITH -q AS (SELECT v1 FROM metrics ORDER BY time) +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) SELECT * FROM q ORDER BY v1; QUERY PLAN ----------------------------------------------------------------------------------------------- @@ -491,19 +540,19 @@ SELECT * FROM q ORDER BY v1; -> Sort Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk -> Sort Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk -> CTE Scan on q (15 rows) -- test CTE join :PREFIX WITH -q1 AS (SELECT time, v1 FROM metrics WHERE device_id=1 ORDER BY time), -q2 AS (SELECT time, v2 FROM metrics WHERE device_id=2 ORDER BY time) +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ @@ -516,7 +565,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Key: _hyper_1_1_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk Filter: (device_id = 1) @@ -524,7 +573,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Key: _hyper_1_3_chunk."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) CTE q2 -> Custom Scan (ChunkAppend) on metrics metrics_1 @@ -533,7 +582,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Key: _hyper_1_1_chunk_1."time" -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk _hyper_1_1_chunk_1 Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_4_chunk compress_hyper_2_4_chunk_1 + -> Seq Scan on compress_hyper_3_13_chunk compress_hyper_3_13_chunk_1 Filter: (device_id = 2) -> Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 Filter: (device_id = 2) @@ -541,7 +590,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; Sort Key: _hyper_1_3_chunk_1."time" -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk _hyper_1_3_chunk_1 Filter: (device_id = 2) - -> Seq Scan on compress_hyper_2_5_chunk compress_hyper_2_5_chunk_1 + -> Seq Scan on compress_hyper_3_14_chunk compress_hyper_3_14_chunk_1 Filter: (device_id = 2) -> Sort Sort Key: q1."time" @@ -552,7 +601,7 @@ SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; (42 rows) -- test prepared statement -PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; :PREFIX EXECUTE prep; QUERY PLAN --------------------------------------------------------------- @@ -560,13 +609,13 @@ PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; -> Append -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_4_chunk + -> Seq Scan on compress_hyper_3_13_chunk Filter: (device_id = 1) -> Seq Scan on _hyper_1_2_chunk Filter: (device_id = 1) -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk Filter: (device_id = 1) - -> Seq Scan on compress_hyper_2_5_chunk + -> Seq Scan on compress_hyper_3_14_chunk Filter: (device_id = 1) (12 rows) @@ -609,15 +658,838 @@ EXECUTE prep; DEALLOCATE prep; -- test explicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1 INNER JOIN metrics m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; -- test implicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1, metrics m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; -- test self-join with sub-query -- XXX FIXME --- :PREFIX SELECT * FROM (SELECT * FROM metrics m1) m1 INNER JOIN (SELECT * FROM metrics m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; -- test system columns -- XXX FIXME ---SELECT xmin FROM metrics ORDER BY time; +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +\set TEST_TABLE 'metrics_space' +\ir :TEST_QUERY_NAME +-- 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. +-- this should use DecompressChunk node +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Limit + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + Filter: (device_id = 1) + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) +(17 rows) + +-- test RECORD by itself +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + Filter: (device_id = 1) + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) +(16 rows) + +-- test expressions +:PREFIX SELECT + time_bucket('1d',time), + v1 + v2 AS "sum", + COALESCE(NULL,v1,v2) AS "coalesce", + NULL AS "NULL", + 'text' AS "text", + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; + QUERY PLAN +-------------------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Result + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) +(24 rows) + +-- test empty targetlist +:PREFIX SELECT FROM :TEST_TABLE; + QUERY PLAN +---------------------------------------------------------- + Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(15 rows) + +-- test empty resultset +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; + QUERY PLAN +------------------------------------------------------------------------------------------------ + Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_17_chunk + Filter: (device_id < 0) + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk + Index Cond: (device_id < 0) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk + Index Cond: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id < 0) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id < 0) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id < 0) + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk + Index Cond: (device_id < 0) +(29 rows) + +-- test targetlist not referencing columns +:PREFIX SELECT 1 FROM :TEST_TABLE; + QUERY PLAN +---------------------------------------------------------------- + Result + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(16 rows) + +-- test constraints not present in targetlist +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +---------------------------------------------------------------- + Sort + Sort Key: _hyper_2_10_chunk.v1 + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = 1) +(13 rows) + +-- test order not present in targetlist +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; + QUERY PLAN +---------------------------------------------------------------- + Sort + Sort Key: _hyper_2_10_chunk.v1 + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = 1) +(13 rows) + +-- test column with all NULL +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; + QUERY PLAN +---------------------------------------------------------- + Append + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = 1) +(11 rows) + +-- +-- test qual pushdown +-- +-- time is not segment by column so should not be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk + Index Cond: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_2_9_chunk + Filter: ("time" < 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) +(18 rows) + +-- device_id constraint should be pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Limit + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + Filter: (device_id = 1) + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) +(17 rows) + +-- test IS NULL / IS NOT NULL +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +----------------------------------------------------------------------- + Limit + -> Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_17_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_8_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_9_chunk + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id IS NOT NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id IS NOT NULL) + -> Seq Scan on _hyper_2_12_chunk + Filter: (device_id IS NOT NULL) +(32 rows) + +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------------------ + Limit + -> Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_17_chunk + Filter: (device_id IS NULL) + -> Index Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk + Index Cond: (device_id IS NULL) + -> Index Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk + Index Cond: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id IS NULL) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id IS NULL) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id IS NULL) + -> Index Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk + Index Cond: (device_id IS NULL) +(32 rows) + +-- test IN (Const,Const) +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +-------------------------------------------------------------------------- + Limit + -> Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on _hyper_2_8_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id = ANY ('{1,2}'::integer[])) +(24 rows) + +-- test cast pushdown +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Limit + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + Filter: (device_id = 1) + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) +(17 rows) + +-- test expressions +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; + QUERY PLAN +----------------------------------------------------------------------------------------------------- + Limit + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_6_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: (device_id = 3) + -> Seq Scan on compress_hyper_4_17_chunk + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk + Filter: (device_id = 3) + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk + Filter: (device_id = 3) +(13 rows) + +-- test function calls +-- not yet pushed down +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------- + Limit + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Merge Append + Sort Key: _hyper_2_4_chunk."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_15_chunk + -> Sort + Sort Key: _hyper_2_5_chunk."time" + -> Sort + Sort Key: _hyper_2_5_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_16_chunk + -> Sort + Sort Key: _hyper_2_6_chunk."time" + -> Sort + Sort Key: _hyper_2_6_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_17_chunk + -> Merge Append + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk + Index Cond: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk + Index Cond: (device_id = length("substring"(version(), 1, 3))) + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Merge Append + Sort Key: _hyper_2_10_chunk."time" + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_18_chunk + -> Sort + Sort Key: _hyper_2_11_chunk."time" + -> Sort + Sort Key: _hyper_2_11_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) + -> Seq Scan on compress_hyper_4_19_chunk + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk + Filter: (device_id = length("substring"(version(), 1, 3))) +(52 rows) + +-- +-- test constraint exclusion +-- +-- test plan time exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id + -> Append + -> Seq Scan on _hyper_2_7_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_2_8_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_2_9_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk + Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone) +(17 rows) + +-- test runtime exclusion +-- first chunk should be excluded +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; + QUERY PLAN +------------------------------------------------------------------------------------------ + Sort + Sort Key: metrics_space."time", metrics_space.device_id + -> Custom Scan (ChunkAppend) on metrics_space + -> Merge Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_17_chunk + -> Merge Append + -> Seq Scan on _hyper_2_7_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on _hyper_2_8_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on _hyper_2_9_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Merge Append + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk + Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone) +(29 rows) + +-- test aggregate +:PREFIX SELECT count(*) FROM :TEST_TABLE; + QUERY PLAN +---------------------------------------------------------------- + Aggregate + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(16 rows) + +-- test aggregate with GROUP BY +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +---------------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk.device_id + -> HashAggregate + Group Key: _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(19 rows) + +-- test window functions with GROUP BY +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; + QUERY PLAN +---------------------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk.device_id + -> WindowAgg + -> HashAggregate + Group Key: _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(20 rows) + +-- test CTE +:PREFIX WITH +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) +SELECT * FROM q ORDER BY v1; + QUERY PLAN +------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: q.v1 + CTE q + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Merge Append + Sort Key: _hyper_2_4_chunk."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Sort + Sort Key: _hyper_2_5_chunk."time" + -> Sort + Sort Key: _hyper_2_5_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Sort + Sort Key: _hyper_2_6_chunk."time" + -> Sort + Sort Key: _hyper_2_6_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Merge Append + Sort Key: _hyper_2_7_chunk."time" + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk + -> Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk + -> Merge Append + Sort Key: _hyper_2_10_chunk."time" + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Sort + Sort Key: _hyper_2_11_chunk."time" + -> Sort + Sort Key: _hyper_2_11_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk + -> CTE Scan on q +(46 rows) + +-- test CTE join +:PREFIX WITH +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) +SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- + Merge Join + Merge Cond: (q1."time" = q2."time") + CTE q1 + -> Custom Scan (ChunkAppend) on metrics_space + Order: metrics_space."time" + -> Sort + Sort Key: _hyper_2_4_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk + Filter: (device_id = 1) + -> Sort + Sort Key: _hyper_2_10_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) + CTE q2 + -> Custom Scan (ChunkAppend) on metrics_space metrics_space_1 + Order: metrics_space_1."time" + -> Sort + Sort Key: _hyper_2_5_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_16_chunk + Filter: (device_id = 2) + -> Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk + Index Cond: (device_id = 2) + -> Sort + Sort Key: _hyper_2_11_chunk."time" + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + Filter: (device_id = 2) + -> Seq Scan on compress_hyper_4_19_chunk + Filter: (device_id = 2) + -> Sort + Sort Key: q1."time" + -> CTE Scan on q1 + -> Sort + Sort Key: q2."time" + -> CTE Scan on q2 +(42 rows) + +-- test prepared statement +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; +:PREFIX EXECUTE prep; + QUERY PLAN +---------------------------------------------------------------- + Aggregate + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_18_chunk + Filter: (device_id = 1) + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + Filter: (device_id = 1) + -> Seq Scan on compress_hyper_4_15_chunk + Filter: (device_id = 1) + -> Seq Scan on _hyper_2_7_chunk + Filter: (device_id = 1) +(12 rows) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +EXECUTE prep; + count +------- + 5472 +(1 row) + +DEALLOCATE prep; +-- test explicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; +-- test implicit self-join +-- XXX FIXME +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- test self-join with sub-query +-- XXX FIXME +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- test system columns +-- XXX FIXME +--SELECT xmin FROM :TEST_TABLE ORDER BY time; +-- run query with parallel enabled to ensure nothing is preventing parallel execution +-- this is just a sanity check, the result queries dont run with parallel disabled +SET max_parallel_workers_per_gather TO 4; +EXPLAIN (costs off) SELECT * FROM metrics ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk + -> Seq Scan on compress_hyper_3_13_chunk + -> Seq Scan on _hyper_1_2_chunk + -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk + -> Seq Scan on compress_hyper_3_14_chunk +(8 rows) + +EXPLAIN (costs off) SELECT * FROM metrics_space ORDER BY time, device_id; + QUERY PLAN +----------------------------------------------------------------- + Sort + Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id + -> Append + -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk + -> Seq Scan on compress_hyper_4_15_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_5_chunk + -> Seq Scan on compress_hyper_4_16_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_6_chunk + -> Seq Scan on compress_hyper_4_17_chunk + -> Seq Scan on _hyper_2_7_chunk + -> Seq Scan on _hyper_2_8_chunk + -> Seq Scan on _hyper_2_9_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk + -> Seq Scan on compress_hyper_4_18_chunk + -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk + -> Seq Scan on compress_hyper_4_19_chunk + -> Seq Scan on _hyper_2_12_chunk +(17 rows) + -- diff compressed and uncompressed results :DIFF_CMD diff --git a/tsl/test/sql/include/transparent_decompression_query.sql b/tsl/test/sql/include/transparent_decompression_query.sql index e707bfd3a..532d3168c 100644 --- a/tsl/test/sql/include/transparent_decompression_query.sql +++ b/tsl/test/sql/include/transparent_decompression_query.sql @@ -4,10 +4,10 @@ -- this should use DecompressChunk node -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time LIMIT 5; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 5; -- test RECORD by itself -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time; -- test expressions :PREFIX SELECT @@ -16,53 +16,53 @@ COALESCE(NULL,v1,v2) AS "coalesce", NULL AS "NULL", 'text' AS "text", - metrics AS "RECORD" -FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; + :TEST_TABLE AS "RECORD" +FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id; -- test empty targetlist -:PREFIX SELECT FROM metrics; +:PREFIX SELECT FROM :TEST_TABLE; -- test empty resultset -:PREFIX SELECT * FROM metrics WHERE device_id < 0; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id < 0; -- test targetlist not referencing columns -:PREFIX SELECT 1 FROM metrics; +:PREFIX SELECT 1 FROM :TEST_TABLE; -- test constraints not present in targetlist -:PREFIX SELECT v1 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v1 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; -- test order not present in targetlist -:PREFIX SELECT v2 FROM metrics WHERE device_id = 1 ORDER BY v1; +:PREFIX SELECT v2 FROM :TEST_TABLE WHERE device_id = 1 ORDER BY v1; -- test column with all NULL -:PREFIX SELECT v3 FROM metrics WHERE device_id = 1; +:PREFIX SELECT v3 FROM :TEST_TABLE WHERE device_id = 1; -- -- test qual pushdown -- -- time is not segment by column so should not be pushed down -:PREFIX SELECT * FROM metrics WHERE time < '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time < '2000-01-08' ORDER BY time, device_id; -- device_id constraint should be pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time, device_id LIMIT 10; -- test IS NULL / IS NOT NULL -:PREFIX SELECT * FROM metrics WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; -:PREFIX SELECT * FROM metrics WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NOT NULL ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IS NULL ORDER BY time, device_id LIMIT 10; -- test IN (Const,Const) -:PREFIX SELECT * FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id IN (1,2) ORDER BY time, device_id LIMIT 10; -- test cast pushdown -:PREFIX SELECT * FROM metrics WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = '1'::text::int ORDER BY time, device_id LIMIT 10; -- test expressions -:PREFIX SELECT * FROM metrics WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = 1 + 4/2 ORDER BY time, device_id LIMIT 10; -- test function calls -- not yet pushed down -:PREFIX SELECT * FROM metrics WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; +:PREFIX SELECT * FROM :TEST_TABLE WHERE device_id = length(substring(version(),1,3)) ORDER BY time, device_id LIMIT 10; -- -- test constraint exclusion @@ -70,34 +70,34 @@ FROM metrics WHERE device_id IN (1,2) ORDER BY time, device_id; -- test plan time exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08' ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08' ORDER BY time, device_id; -- test runtime exclusion -- first chunk should be excluded -:PREFIX SELECT * FROM metrics WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; +:PREFIX SELECT * FROM :TEST_TABLE WHERE time > '2000-01-08'::text::timestamptz ORDER BY time, device_id; -- test aggregate -:PREFIX SELECT count(*) FROM metrics; +:PREFIX SELECT count(*) FROM :TEST_TABLE; -- test aggregate with GROUP BY -:PREFIX SELECT count(*) FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT count(*) FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; -- test window functions with GROUP BY -:PREFIX SELECT sum(count(*)) OVER () FROM metrics GROUP BY device_id ORDER BY device_id; +:PREFIX SELECT sum(count(*)) OVER () FROM :TEST_TABLE GROUP BY device_id ORDER BY device_id; -- test CTE :PREFIX WITH -q AS (SELECT v1 FROM metrics ORDER BY time) +q AS (SELECT v1 FROM :TEST_TABLE ORDER BY time) SELECT * FROM q ORDER BY v1; -- test CTE join :PREFIX WITH -q1 AS (SELECT time, v1 FROM metrics WHERE device_id=1 ORDER BY time), -q2 AS (SELECT time, v2 FROM metrics WHERE device_id=2 ORDER BY time) +q1 AS (SELECT time, v1 FROM :TEST_TABLE WHERE device_id=1 ORDER BY time), +q2 AS (SELECT time, v2 FROM :TEST_TABLE WHERE device_id=2 ORDER BY time) SELECT * FROM q1 INNER JOIN q2 ON q1.time=q2.time ORDER BY q1.time; -- test prepared statement -PREPARE prep AS SELECT count(time) FROM metrics WHERE device_id = 1; +PREPARE prep AS SELECT count(time) FROM :TEST_TABLE WHERE device_id = 1; :PREFIX EXECUTE prep; EXECUTE prep; EXECUTE prep; @@ -109,17 +109,17 @@ DEALLOCATE prep; -- test explicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1 INNER JOIN metrics m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1 INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time ORDER BY m1.time; -- test implicit self-join -- XXX FIXME --- :PREFIX SELECT * FROM metrics m1, metrics m2 WHERE m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM :TEST_TABLE m1, :TEST_TABLE m2 WHERE m1.time = m2.time ORDER BY m1.time; -- test self-join with sub-query -- XXX FIXME --- :PREFIX SELECT * FROM (SELECT * FROM metrics m1) m1 INNER JOIN (SELECT * FROM metrics m2) m2 ON m1.time = m2.time ORDER BY m1.time; +-- :PREFIX SELECT * FROM (SELECT * FROM :TEST_TABLE m1) m1 INNER JOIN (SELECT * FROM :TEST_TABLE m2) m2 ON m1.time = m2.time ORDER BY m1.time; -- test system columns -- XXX FIXME ---SELECT xmin FROM metrics ORDER BY time; +--SELECT xmin FROM :TEST_TABLE ORDER BY time; diff --git a/tsl/test/sql/transparent_decompression.sql.in b/tsl/test/sql/transparent_decompression.sql.in index 23a9d57d6..2c45f4032 100644 --- a/tsl/test/sql/transparent_decompression.sql.in +++ b/tsl/test/sql/transparent_decompression.sql.in @@ -24,26 +24,53 @@ ALTER TABLE metrics DROP COLUMN filler_3; INSERT INTO metrics(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); ANALYZE metrics; +-- create identical hypertable with space partitioning +CREATE TABLE metrics_space(filler_1 int, filler_2 int, filler_3 int, time timestamptz NOT NULL, device_id int, v1 float, v2 float, v3 float); +SELECT create_hypertable('metrics_space','time','device_id',3); + +ALTER TABLE metrics_space DROP COLUMN filler_1; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-01 0:00:00+0'::timestamptz,'2000-01-05 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_2; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-06 0:00:00+0'::timestamptz,'2000-01-12 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ALTER TABLE metrics_space DROP COLUMN filler_3; +INSERT INTO metrics_space(time,device_id,v1,v2,v3) SELECT time, device_id, device_id + 0.25, device_id + 0.5, NULL FROM generate_series('2000-01-13 0:00:00+0'::timestamptz,'2000-01-19 23:55:00+0','5m') gtime(time), generate_series(1,5,1) gdevice(device_id); +ANALYZE metrics_space; + -- run queries on uncompressed hypertable and store result \set PREFIX '' \set ECHO none SET client_min_messages TO error; \o :TEST_RESULTS_UNCOMPRESSED +\set TEST_TABLE 'metrics' +\ir :TEST_QUERY_NAME +\set TEST_TABLE 'metrics_space' \ir :TEST_QUERY_NAME \o RESET client_min_messages; \set ECHO all --- compress some chunks on the hypertable -ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time asc nulls last', timescaledb.compress_segmentby='device_id'); +-- compress first and last chunk on the hypertable +ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk'); SELECT compress_chunk('_timescaledb_internal._hyper_1_3_chunk'); +-- compress some chunks on space partitioned hypertable +-- we compress all chunks of first time slice, none of second, and 2 of the last time slice +ALTER TABLE metrics_space SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='device_id'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_4_chunk'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_5_chunk'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_6_chunk'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_10_chunk'); +SELECT compress_chunk('_timescaledb_internal._hyper_2_11_chunk'); + -- run queries on compressed hypertable and store result \set PREFIX '' \set ECHO none SET client_min_messages TO error; \o :TEST_RESULTS_COMPRESSED +\set TEST_TABLE 'metrics' +\ir :TEST_QUERY_NAME +\set TEST_TABLE 'metrics_space' \ir :TEST_QUERY_NAME \o RESET client_min_messages; @@ -62,7 +89,16 @@ SELECT SET max_parallel_workers_per_gather TO 0; -- get explain for queries on hypertable with compression +\set TEST_TABLE 'metrics' \ir :TEST_QUERY_NAME +\set TEST_TABLE 'metrics_space' +\ir :TEST_QUERY_NAME + +-- run query with parallel enabled to ensure nothing is preventing parallel execution +-- this is just a sanity check, the result queries dont run with parallel disabled +SET max_parallel_workers_per_gather TO 4; +EXPLAIN (costs off) SELECT * FROM metrics ORDER BY time, device_id; +EXPLAIN (costs off) SELECT * FROM metrics_space ORDER BY time, device_id; -- diff compressed and uncompressed results :DIFF_CMD