mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 10:33:27 +08:00
Remove constified now() constraints from plan
Commit 35ea80ff added an optimization to enable expressions with now() to be used during plan-time chunk exclusion by constifying the now() expression. The added constified constraints were left in the plan even though they were only required during the hypertable explansion. This patch marks those constified constraints and removes them once they are no longer required.
This commit is contained in:
parent
d249954be0
commit
dcb7dcc506
@ -3,6 +3,7 @@ set(SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/add_hashagg.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/agg_bookend.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/constify_now.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/constraint_cleanup.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/expand_hypertable.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/partialize.c)
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
||||
|
@ -130,6 +130,7 @@ static OpExpr *
|
||||
constify_now_expr(PlannerInfo *root, OpExpr *op)
|
||||
{
|
||||
op = copyObject(op);
|
||||
op->location = PLANNER_LOCATION_MAGIC;
|
||||
if (IsA(lsecond(op->args), FuncExpr))
|
||||
{
|
||||
/*
|
||||
@ -162,6 +163,7 @@ constify_now_expr(PlannerInfo *root, OpExpr *op)
|
||||
*/
|
||||
lsecond(op->args) = estimate_expression_value(root, (Node *) op_inner);
|
||||
Assert(IsA(lsecond(op->args), Const));
|
||||
op->location = PLANNER_LOCATION_MAGIC;
|
||||
return op;
|
||||
}
|
||||
}
|
||||
|
123
src/planner/constraint_cleanup.c
Normal file
123
src/planner/constraint_cleanup.c
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file and its contents are licensed under the Apache License 2.0.
|
||||
* Please see the included NOTICE for copyright information and
|
||||
* LICENSE-APACHE for a copy of the license.
|
||||
*/
|
||||
|
||||
#include <postgres.h>
|
||||
#include <nodes/pathnodes.h>
|
||||
|
||||
#include "planner.h"
|
||||
|
||||
/*
|
||||
* This code deals with removing the intermediate constraints
|
||||
* we added before planning to improve chunk exclusion.
|
||||
*/
|
||||
|
||||
static bool
|
||||
restrictinfo_is_marked(RestrictInfo *ri)
|
||||
{
|
||||
switch (nodeTag(ri->clause))
|
||||
{
|
||||
case T_OpExpr:
|
||||
return castNode(OpExpr, ri->clause)->location == PLANNER_LOCATION_MAGIC;
|
||||
case T_ScalarArrayOpExpr:
|
||||
return castNode(ScalarArrayOpExpr, ri->clause)->location == PLANNER_LOCATION_MAGIC;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove marked constraints from RestrictInfo clause.
|
||||
*/
|
||||
static List *
|
||||
restrictinfo_cleanup(List *restrictinfos, bool *pfiltered)
|
||||
{
|
||||
List *filtered_ri = NIL;
|
||||
ListCell *lc;
|
||||
bool filtered = false;
|
||||
if (!restrictinfos)
|
||||
return NULL;
|
||||
|
||||
foreach (lc, restrictinfos)
|
||||
{
|
||||
RestrictInfo *ri = (RestrictInfo *) lfirst(lc);
|
||||
if (restrictinfo_is_marked(ri))
|
||||
{
|
||||
filtered = true;
|
||||
continue;
|
||||
}
|
||||
filtered_ri = lappend(filtered_ri, ri);
|
||||
}
|
||||
|
||||
if (pfiltered)
|
||||
*pfiltered = filtered;
|
||||
|
||||
return filtered ? filtered_ri : restrictinfos;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove marked constraints from IndexPath.
|
||||
*/
|
||||
static void
|
||||
indexpath_cleanup(IndexPath *path)
|
||||
{
|
||||
ListCell *lc;
|
||||
List *filtered_ic = NIL;
|
||||
path->indexinfo->indrestrictinfo = restrictinfo_cleanup(path->indexinfo->indrestrictinfo, NULL);
|
||||
|
||||
foreach (lc, path->indexclauses)
|
||||
{
|
||||
IndexClause *iclause = lfirst_node(IndexClause, lc);
|
||||
if (restrictinfo_is_marked(iclause->rinfo))
|
||||
continue;
|
||||
|
||||
filtered_ic = lappend(filtered_ic, iclause);
|
||||
}
|
||||
path->indexclauses = filtered_ic;
|
||||
}
|
||||
|
||||
void
|
||||
ts_planner_constraint_cleanup(PlannerInfo *root, RelOptInfo *rel)
|
||||
{
|
||||
ListCell *lc;
|
||||
bool filtered = false;
|
||||
if (rel->baserestrictinfo)
|
||||
rel->baserestrictinfo = restrictinfo_cleanup(rel->baserestrictinfo, &filtered);
|
||||
|
||||
/*
|
||||
* If we added constraints those will be present in baserestrictinfo.
|
||||
* If we did not remove anything from baserestrictinfo in the step
|
||||
* above we can skip looking in the paths.
|
||||
*/
|
||||
if (filtered)
|
||||
{
|
||||
/*
|
||||
* For seqscan cleaning up baserestrictinfo is enough but for
|
||||
* BitmapHeapPath and IndexPath we need some extra steps.
|
||||
*/
|
||||
foreach (lc, rel->pathlist)
|
||||
{
|
||||
switch (nodeTag(lfirst(lc)))
|
||||
{
|
||||
case T_BitmapHeapPath:
|
||||
{
|
||||
BitmapHeapPath *path = lfirst_node(BitmapHeapPath, lc);
|
||||
if (IsA(path->bitmapqual, IndexPath))
|
||||
indexpath_cleanup(castNode(IndexPath, path->bitmapqual));
|
||||
|
||||
break;
|
||||
}
|
||||
case T_IndexPath:
|
||||
{
|
||||
indexpath_cleanup(castNode(IndexPath, lfirst(lc)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1107,6 +1107,9 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang
|
||||
break;
|
||||
case TS_REL_CHUNK:
|
||||
case TS_REL_CHUNK_CHILD:
|
||||
if (ts_guc_enable_optimizations)
|
||||
ts_planner_constraint_cleanup(root, rel);
|
||||
|
||||
if (IS_UPDL_CMD(root->parse))
|
||||
{
|
||||
BaserelInfoEntry *chunk_cache_entry =
|
||||
|
@ -16,6 +16,13 @@
|
||||
#include "guc.h"
|
||||
|
||||
#define CHUNK_EXCL_FUNC_NAME "chunks_in"
|
||||
/*
|
||||
* Constraints created during planning to improve chunk exclusion
|
||||
* will be marked with this value as location so they can be easily
|
||||
* identified and removed when they are no longer needed.
|
||||
* Removal happens in timescaledb_set_rel_pathlist hook.
|
||||
*/
|
||||
#define PLANNER_LOCATION_MAGIC -29811
|
||||
|
||||
typedef struct Chunk Chunk;
|
||||
typedef struct TsFdwRelInfo TsFdwRelInfo;
|
||||
@ -95,5 +102,6 @@ extern void ts_preprocess_first_last_aggregates(PlannerInfo *root, List *tlist);
|
||||
extern void ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo *rel);
|
||||
extern void ts_plan_expand_timebucket_annotate(PlannerInfo *root, RelOptInfo *rel);
|
||||
extern Node *ts_constify_now(PlannerInfo *root, List *rtable, Node *node);
|
||||
extern void ts_planner_constraint_cleanup(PlannerInfo *root, RelOptInfo *rel);
|
||||
|
||||
#endif /* TIMESCALEDB_PLANNER_H */
|
||||
|
@ -14,91 +14,111 @@ SET timescaledb.current_timestamp_mock TO '1990-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() - '24h'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() - '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
-- test bitmapheapscan
|
||||
SET enable_indexscan TO false;
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
RESET enable_indexscan;
|
||||
-- test multiple constraints
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND device_id = 2;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND (device_id = 2 OR device_id = 3);
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
(10 rows)
|
||||
|
||||
@ -106,11 +126,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
-- variants we don't optimize
|
||||
@ -233,11 +253,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX WITH q1 AS (
|
||||
@ -264,11 +284,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m2.time > now();
|
||||
@ -281,11 +301,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m1.time > now() AND m2.time > now();
|
||||
@ -293,19 +313,19 @@ QUERY PLAN
|
||||
Nested Loop
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- only top-level constraints in WHERE clause are constified
|
||||
@ -339,11 +359,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- test UPDATE
|
||||
@ -357,11 +377,11 @@ QUERY PLAN
|
||||
-> Seq Scan on metrics
|
||||
Filter: (("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone) AND ("time" > now()))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
-- test DELETE
|
||||
@ -375,11 +395,11 @@ QUERY PLAN
|
||||
-> Seq Scan on metrics
|
||||
Filter: (("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone) AND ("time" > now()))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
-- test chunks actually get excluded
|
||||
@ -396,7 +416,7 @@ SET timescaledb.current_timestamp_mock TO '2000-01-14';
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Fri Jan 14 00:00:00 2000 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(2 rows)
|
||||
|
||||
CREATE TABLE const_now(time timestamptz, time2 timestamptz, value float);
|
||||
@ -446,9 +466,9 @@ PREPARE p1 AS SELECT FROM prep_const_now WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
@ -460,9 +480,9 @@ SET timescaledb.current_timestamp_mock TO '3002-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
|
@ -14,91 +14,111 @@ SET timescaledb.current_timestamp_mock TO '1990-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() - '24h'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() - '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
-- test bitmapheapscan
|
||||
SET enable_indexscan TO false;
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
RESET enable_indexscan;
|
||||
-- test multiple constraints
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND device_id = 2;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND (device_id = 2 OR device_id = 3);
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
(10 rows)
|
||||
|
||||
@ -106,11 +126,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
-- variants we don't optimize
|
||||
@ -233,11 +253,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX WITH q1 AS (
|
||||
@ -264,11 +284,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m2.time > now();
|
||||
@ -281,11 +301,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m1.time > now() AND m2.time > now();
|
||||
@ -293,19 +313,19 @@ QUERY PLAN
|
||||
Nested Loop
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- only top-level constraints in WHERE clause are constified
|
||||
@ -339,11 +359,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- test UPDATE
|
||||
@ -357,11 +377,11 @@ QUERY PLAN
|
||||
-> Seq Scan on metrics
|
||||
Filter: (("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone) AND ("time" > now()))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
-- test DELETE
|
||||
@ -375,11 +395,11 @@ QUERY PLAN
|
||||
-> Seq Scan on metrics
|
||||
Filter: (("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone) AND ("time" > now()))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
-- test chunks actually get excluded
|
||||
@ -396,7 +416,7 @@ SET timescaledb.current_timestamp_mock TO '2000-01-14';
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Fri Jan 14 00:00:00 2000 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(2 rows)
|
||||
|
||||
CREATE TABLE const_now(time timestamptz, time2 timestamptz, value float);
|
||||
@ -446,9 +466,9 @@ PREPARE p1 AS SELECT FROM prep_const_now WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
@ -460,9 +480,9 @@ SET timescaledb.current_timestamp_mock TO '3002-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
|
@ -14,91 +14,111 @@ SET timescaledb.current_timestamp_mock TO '1990-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= now()) AND ("time" >= 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() - '24h'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() - '@ 24 hours'::interval)) AND ("time" > 'Sun Dec 31 00:00:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() - '@ 24 hours'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time > now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > (now() + '@ 10 mins'::interval)) AND ("time" > 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() - '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() - '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
(7 rows)
|
||||
|
||||
-- test bitmapheapscan
|
||||
SET enable_indexscan TO false;
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
-> Bitmap Heap Scan on _hyper_X_X_chunk
|
||||
Recheck Cond: ("time" > now())
|
||||
-> Bitmap Index Scan on _hyper_X_X_chunk_metrics_time_idx
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
RESET enable_indexscan;
|
||||
-- test multiple constraints
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND device_id = 2;
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ((device_id = 2) AND ("time" >= (now() + '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND (device_id = 2 OR device_id = 3);
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" >= (now() + '@ 10 mins'::interval))
|
||||
Filter: ((device_id = 2) OR (device_id = 3))
|
||||
(10 rows)
|
||||
|
||||
@ -106,11 +126,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)) AND ("time" >= 'Mon Jan 01 00:10:00 1990 PST'::timestamp with time zone) AND ("time" >= 'Sun Dec 31 23:50:00 1989 PST'::timestamp with time zone))
|
||||
Index Cond: (("time" >= (now() + '@ 10 mins'::interval)) AND ("time" >= (now() - '@ 10 mins'::interval)))
|
||||
(7 rows)
|
||||
|
||||
-- variants we don't optimize
|
||||
@ -233,11 +253,11 @@ QUERY PLAN
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(7 rows)
|
||||
|
||||
:PREFIX WITH q1 AS (
|
||||
@ -264,11 +284,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m2.time > now();
|
||||
@ -281,11 +301,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
:PREFIX SELECT FROM metrics m1, metrics m2 WHERE m1.time > now() AND m2.time > now();
|
||||
@ -293,19 +313,19 @@ QUERY PLAN
|
||||
Nested Loop
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m1_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- only top-level constraints in WHERE clause are constified
|
||||
@ -339,11 +359,11 @@ QUERY PLAN
|
||||
-> Materialize
|
||||
-> Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(16 rows)
|
||||
|
||||
-- test UPDATE
|
||||
@ -357,11 +377,11 @@ QUERY PLAN
|
||||
-> Result
|
||||
-> Append
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(13 rows)
|
||||
|
||||
-- test DELETE
|
||||
@ -374,11 +394,11 @@ QUERY PLAN
|
||||
Delete on _hyper_X_X_chunk metrics_3
|
||||
-> Append
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_1
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_2
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk metrics_3
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Mon Jan 01 00:00:00 1990 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(12 rows)
|
||||
|
||||
-- test chunks actually get excluded
|
||||
@ -395,7 +415,7 @@ SET timescaledb.current_timestamp_mock TO '2000-01-14';
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
QUERY PLAN
|
||||
Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Fri Jan 14 00:00:00 2000 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(2 rows)
|
||||
|
||||
CREATE TABLE const_now(time timestamptz, time2 timestamptz, value float);
|
||||
@ -445,9 +465,9 @@ PREPARE p1 AS SELECT FROM prep_const_now WHERE time > now();
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
@ -459,9 +479,9 @@ SET timescaledb.current_timestamp_mock TO '3002-01-01';
|
||||
QUERY PLAN
|
||||
Append
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
-> Index Only Scan using _hyper_X_X_chunk_prep_const_now_time_idx on _hyper_X_X_chunk
|
||||
Index Cond: (("time" > now()) AND ("time" > 'Thu Jan 01 00:00:00 3001 PST'::timestamp with time zone))
|
||||
Index Cond: ("time" > now())
|
||||
(5 rows)
|
||||
|
||||
EXECUTE p1;
|
||||
|
@ -20,6 +20,11 @@ SET timescaledb.current_timestamp_mock TO '1990-01-01';
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() - '10m'::interval;
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval;
|
||||
|
||||
-- test bitmapheapscan
|
||||
SET enable_indexscan TO false;
|
||||
:PREFIX SELECT FROM metrics WHERE time > now();
|
||||
RESET enable_indexscan;
|
||||
|
||||
-- test multiple constraints
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND device_id = 2;
|
||||
:PREFIX SELECT FROM metrics WHERE time >= now() + '10m'::interval AND (device_id = 2 OR device_id = 3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user