diff --git a/src/planner/expand_hypertable.c b/src/planner/expand_hypertable.c index 0308dfba41d..7cfff920cec 100644 --- a/src/planner/expand_hypertable.c +++ b/src/planner/expand_hypertable.c @@ -353,6 +353,52 @@ constify_timestamptz_op_interval(PlannerInfo *root, OpExpr *constraint) constraint->inputcollid); } +static bool +extract_opexpr_parts(Expr *node, OpExpr **op, FuncExpr **time_bucket, Expr **value, Oid *opno) +{ + if (!IsA(node, OpExpr)) + { + return false; + } + + *op = castNode(OpExpr, node); + if (list_length((*op)->args) != 2) + { + return false; + } + + Expr *left = linitial((*op)->args); + Expr *right = lsecond((*op)->args); + + if (IsA(left, FuncExpr) && IsA(right, Const)) + { + *time_bucket = castNode(FuncExpr, left); + *value = right; + *opno = (*op)->opno; + } + else if (IsA(right, FuncExpr)) + { + *time_bucket = castNode(FuncExpr, right); + *value = left; + *opno = get_commutator((*op)->opno); + + if (!OidIsValid(opno)) + return false; + } + else + { + return false; + } + + if (!is_time_bucket_function((Expr *) *time_bucket) || !IsA(*value, Const) || + castNode(Const, *value)->constisnull) + { + return false; + } + + return true; +} + /* * Transform time_bucket calls of the following form in WHERE clause: * @@ -390,79 +436,53 @@ constify_timestamptz_op_interval(PlannerInfo *root, OpExpr *constraint) Expr * ts_transform_time_bucket_comparison(Expr *node) { - if (!IsA(node, OpExpr)) - { - return NULL; - } + FuncExpr *time_bucket; + Expr *value; + OpExpr *op; + Oid opno; - OpExpr *op = castNode(OpExpr, node); - if (list_length(op->args) != 2) + if (!extract_opexpr_parts(node, &op, &time_bucket, &value, &opno)) { return NULL; } - Expr *left = linitial(op->args); - Expr *right = lsecond(op->args); + Const *width = linitial(time_bucket->args); - FuncExpr *time_bucket = NULL; - Expr *value = NULL; - if (IsA(left, FuncExpr) && IsA(right, Const)) - { - time_bucket = castNode(FuncExpr, left); - value = right; - } - else if (IsA(right, FuncExpr)) - { - time_bucket = castNode(FuncExpr, right); - value = left; - } - else - { + if (!IsA(width, Const) || width->constisnull) return NULL; - } - if (list_length(time_bucket->args) != 2) - { + /* 3 or more args should have Const 3rd arg */ + if (list_length(time_bucket->args) > 2 && !IsA(lthird(time_bucket->args), Const)) return NULL; - } - if (!is_time_bucket_function((Expr *) time_bucket)) - { + /* 5 args variants should have Const 4rd and 5th arg */ + if (list_length(time_bucket->args) == 5 && + (!IsA(lfourth(time_bucket->args), Const) || !IsA(lfifth(time_bucket->args), Const))) return NULL; - } - Const *width = linitial(time_bucket->args); - Oid opno = op->opno; + Assert(list_length(time_bucket->args) == 2 || list_length(time_bucket->args) == 3 || + list_length(time_bucket->args) == 5); + TypeCacheEntry *tce; int strategy; - if (list_length(time_bucket->args) != 2 || !IsA(value, Const) || !IsA(width, Const)) - return NULL; - - /* - * if time_bucket call is on wrong side we switch operator - */ - if (IsA(right, FuncExpr)) - { - opno = get_commutator(op->opno); - - if (!OidIsValid(opno)) - return NULL; - } - tce = lookup_type_cache(exprType((Node *) time_bucket), TYPECACHE_BTREE_OPFAMILY); strategy = get_op_opfamily_strategy(opno, tce->btree_opf); if (strategy == BTGreaterStrategyNumber || strategy == BTGreaterEqualStrategyNumber) { - /* column > value */ + /* Since time_bucket will always shift the input to the left this + * transformation is always safe even in the presence of offset variants. + * + * column > value + */ op = copyObject(op); op->args = list_make2(lsecond(time_bucket->args), value); /* * if we switched operator we need to adjust OpExpr as well */ - if (IsA(right, FuncExpr)) + if (op->opno != opno) { op->opno = opno; op->opfuncid = InvalidOid; @@ -477,14 +497,15 @@ ts_transform_time_bucket_comparison(Expr *node) Datum datum; int64 integralValue, integralWidth; - if (castNode(Const, value)->constisnull || width->constisnull) - return NULL; - switch (tce->type_id) { case INT2OID: case INT4OID: case INT8OID: + /* We can support the offset variants of time_bucket as the + * amount of shifting they do is never bigger than the bucketing + * width. + */ integralValue = const_datum_get_int(castNode(Const, value)); integralWidth = const_datum_get_int(width); @@ -493,10 +514,11 @@ ts_transform_time_bucket_comparison(Expr *node) /* * When the time_bucket constraint matches the start of the bucket - * and we have a less than constraint we can skip adding the - * full bucket. + * and we have a less than constraint and no offset we can skip + * adding the full bucket. */ - if (strategy == BTLessStrategyNumber && integralValue % integralWidth == 0) + if (strategy == BTLessStrategyNumber && list_length(time_bucket->args) == 2 && + integralValue % integralWidth == 0) datum = int_get_datum(integralValue, tce->type_id); else datum = int_get_datum(integralValue + integralWidth, tce->type_id); @@ -512,6 +534,10 @@ ts_transform_time_bucket_comparison(Expr *node) case DATEOID: { + /* We can support the offset/origin variants of time_bucket + * as the amount of shifting they do is never bigger than the + * bucketing width. + */ Assert(width->consttype == INTERVALOID); Interval *interval = DatumGetIntervalP(width->constvalue); @@ -534,10 +560,11 @@ ts_transform_time_bucket_comparison(Expr *node) /* * When the time_bucket constraint matches the start of the bucket - * and we have a less than constraint we can skip adding the - * full bucket. + * and we have a less than constraint and no offset or origin we can + * skip adding the full bucket. */ - if (strategy == BTLessStrategyNumber && integralValue % integralWidth == 0) + if (strategy == BTLessStrategyNumber && list_length(time_bucket->args) == 2 && + integralValue % integralWidth == 0) datum = DateADTGetDatum(integralValue); else datum = DateADTGetDatum(integralValue + integralWidth); @@ -555,6 +582,10 @@ ts_transform_time_bucket_comparison(Expr *node) case TIMESTAMPOID: case TIMESTAMPTZOID: { + /* We can support the offset/origin/timezone variants of time_bucket + * as the amount of shifting they do is never bigger than the + * bucketing width. + */ Assert(width->consttype == INTERVALOID); Interval *interval = DatumGetIntervalP(width->constvalue); @@ -587,10 +618,11 @@ ts_transform_time_bucket_comparison(Expr *node) /* * When the time_bucket constraint matches the start of the bucket - * and we have a less than constraint we can skip adding the - * full bucket. + * and we have a less than constraint and no other modifying arguments + * we can skip adding the full bucket. */ - if (strategy == BTLessStrategyNumber && integralValue % integralWidth == 0) + if (strategy == BTLessStrategyNumber && list_length(time_bucket->args) == 2 && + integralValue % integralWidth == 0) datum = int_get_datum(integralValue, tce->type_id); else datum = int_get_datum(integralValue + integralWidth, tce->type_id); diff --git a/test/expected/plan_expand_hypertable-13.out b/test/expected/plan_expand_hypertable-13.out index ad769d85a06..b4ef7bfcbe1 100644 --- a/test/expected/plan_expand_hypertable-13.out +++ b/test/expected/plan_expand_hypertable-13.out @@ -1113,6 +1113,455 @@ time_bucket exclusion Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time"))) (9 rows) +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(9 rows) + +\qecho timestamp time_bucket exclusion +timestamp time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamp; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) +(11 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +\qecho timestamptz time_bucket exclusion +timestamptz time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamptz; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + \qecho test overflow behaviour of time_bucket exclusion test overflow behaviour of time_bucket exclusion :PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time; diff --git a/test/expected/plan_expand_hypertable-14.out b/test/expected/plan_expand_hypertable-14.out index ad769d85a06..b4ef7bfcbe1 100644 --- a/test/expected/plan_expand_hypertable-14.out +++ b/test/expected/plan_expand_hypertable-14.out @@ -1113,6 +1113,455 @@ time_bucket exclusion Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time"))) (9 rows) +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(9 rows) + +\qecho timestamp time_bucket exclusion +timestamp time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamp; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) +(11 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +\qecho timestamptz time_bucket exclusion +timestamptz time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamptz; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + \qecho test overflow behaviour of time_bucket exclusion test overflow behaviour of time_bucket exclusion :PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time; diff --git a/test/expected/plan_expand_hypertable-15.out b/test/expected/plan_expand_hypertable-15.out index ad769d85a06..b4ef7bfcbe1 100644 --- a/test/expected/plan_expand_hypertable-15.out +++ b/test/expected/plan_expand_hypertable-15.out @@ -1113,6 +1113,455 @@ time_bucket exclusion Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time"))) (9 rows) +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(9 rows) + +\qecho timestamp time_bucket exclusion +timestamp time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamp; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) +(11 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +\qecho timestamptz time_bucket exclusion +timestamptz time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamptz; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + \qecho test overflow behaviour of time_bucket exclusion test overflow behaviour of time_bucket exclusion :PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time; diff --git a/test/expected/plan_expand_hypertable-16.out b/test/expected/plan_expand_hypertable-16.out index bc14b66b42b..84d40a9f091 100644 --- a/test/expected/plan_expand_hypertable-16.out +++ b/test/expected/plan_expand_hypertable-16.out @@ -1113,6 +1113,455 @@ time_bucket exclusion Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time"))) (9 rows) +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)) +(9 rows) + +:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '20'::bigint) AND ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(7 rows) + +:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Sort + Sort Key: _hyper_1_1_chunk."time" + -> Append + -> Seq Scan on _hyper_1_1_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_2_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) + -> Seq Scan on _hyper_1_3_chunk + Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))) +(9 rows) + +\qecho timestamp time_bucket exclusion +timestamp time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamp; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone) +(11 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamp + Order: metrics_timestamp."time" + -> Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + -> Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone) +(8 rows) + +\qecho timestamptz time_bucket exclusion +timestamptz time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamptz; + count +------- + 5 +(1 row) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk + Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + Custom Scan (ChunkAppend) on metrics_timestamptz + Order: metrics_timestamptz."time" + -> Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + -> Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk + Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) + Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone) +(8 rows) + \qecho test overflow behaviour of time_bucket exclusion test overflow behaviour of time_bucket exclusion :PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time; diff --git a/test/sql/include/plan_expand_hypertable_query.sql b/test/sql/include/plan_expand_hypertable_query.sql index 44199c22d5f..0997aa00fe7 100644 --- a/test/sql/include/plan_expand_hypertable_query.sql +++ b/test/sql/include/plan_expand_hypertable_query.sql @@ -165,6 +165,46 @@ SELECT * FROM cte ORDER BY value; :PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time) ORDER BY time; :PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time) ORDER BY time; +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time; +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time; +:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time; +:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time; +:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time; + +\qecho timestamp time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamp; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time; + +\qecho timestamptz time_bucket exclusion +SELECT count(DISTINCT tableoid) FROM metrics_timestamptz; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time; +:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time; + \qecho test overflow behaviour of time_bucket exclusion :PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time;