diff --git a/src/planner/expand_hypertable.c b/src/planner/expand_hypertable.c index c2c933ca8c8..968c5734672 100644 --- a/src/planner/expand_hypertable.c +++ b/src/planner/expand_hypertable.c @@ -1518,6 +1518,16 @@ ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo * Assert(chunk->table_id == root->simple_rte_array[child_rtindex]->relid); ts_get_private_reloptinfo(child_rel)->cached_chunk_struct = chunk; } + + /* + * This calculation is done by make_one_rel, but it happens before our + * hypertable expansion, so we have to account for newly expanded chunks + * separately. + */ + if (!IS_DUMMY_REL(child_rel)) + { + root->total_table_pages += child_rel->pages; + } } } diff --git a/src/planner/planner.c b/src/planner/planner.c index f627263516a..29a91d5f814 100644 --- a/src/planner/planner.c +++ b/src/planner/planner.c @@ -1181,104 +1181,36 @@ rte_should_expand(const RangeTblEntry *rte) } static void -expand_hypertables(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte) +expand_hypertable(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte) { - bool set_pathlist_for_current_rel = false; - double total_pages; - bool reenabled_inheritance = false; + Assert(rte_should_expand(rte)); + Assert(rti == rel->relid); - for (int i = 1; i < root->simple_rel_array_size; i++) - { - RangeTblEntry *in_rte = root->simple_rte_array[i]; - -#if PG18_GE - /* RTE could be removed due to self-join - * elimination optimization. - * - * https://github.com/postgres/postgres/commit/5f6f95 - */ - if (!in_rte) - { - continue; - } -#endif - - if (rte_should_expand(in_rte) && root->simple_rel_array[i]) - { - RelOptInfo *in_rel = root->simple_rel_array[i]; - Hypertable *ht = ts_planner_get_hypertable(in_rte->relid, CACHE_FLAG_NOCREATE); - - Assert(ht != NULL && in_rel != NULL); - ts_plan_expand_hypertable_chunks(ht, root, in_rel, in_rte->ctename != TS_FK_EXPAND); - - in_rte->inh = true; - reenabled_inheritance = true; - /* Redo set_rel_consider_parallel, as results of the call may no longer be valid - * here (due to adding more tables to the set of tables under consideration here). - * This is especially true if dealing with foreign data wrappers. */ - - /* - * An entry of reloptkind RELOPT_OTHER_MEMBER_REL might still - * be a hypertable here if it was pulled up from a subquery - * as happens with UNION ALL for example. - */ - if (in_rel->reloptkind == RELOPT_BASEREL || - in_rel->reloptkind == RELOPT_OTHER_MEMBER_REL) - { - Assert(in_rte->relkind == RELKIND_RELATION); - ts_set_rel_size(root, in_rel, i, in_rte); - } - - /* if we're activating inheritance during a hypertable's pathlist - * creation then we're past the point at which postgres will add - * paths for the children, and we have to do it ourselves. We delay - * the actual setting of the pathlists until after this loop, - * because set_append_rel_pathlist will eventually call this hook again. - */ - if (in_rte == rte) - { - Assert(rti == (Index) i); - set_pathlist_for_current_rel = true; - } - } - } + Hypertable *ht = ts_planner_get_hypertable(rte->relid, CACHE_FLAG_NOCREATE); + Assert(ht != NULL); + ts_plan_expand_hypertable_chunks(ht, root, rel, rte->ctename != TS_FK_EXPAND); - if (!reenabled_inheritance) - { - return; - } + rte->inh = true; - total_pages = 0; - for (int i = 1; i < root->simple_rel_array_size; i++) + /* + * An entry of reloptkind RELOPT_OTHER_MEMBER_REL might still + * be a hypertable here if it was pulled up from a subquery + * as happens with UNION ALL for example. + */ + if (rel->reloptkind == RELOPT_BASEREL || rel->reloptkind == RELOPT_OTHER_MEMBER_REL) { - RelOptInfo *brel = root->simple_rel_array[i]; - - if (brel == NULL) - { - continue; - } - - Assert(brel->relid == (Index) i); /* sanity check on array */ - - if (IS_DUMMY_REL(brel)) - { - continue; - } - - if (IS_SIMPLE_REL(brel)) - { - total_pages += (double) brel->pages; - } + Assert(rte->relkind == RELKIND_RELATION); + ts_set_rel_size(root, rel, rti, rte); } - root->total_table_pages = total_pages; - - if (set_pathlist_for_current_rel) - { - rel->pathlist = NIL; - rel->partial_pathlist = NIL; - ts_set_append_rel_pathlist(root, rel, rti, rte); - } + /* + * We are past the point at which postgres will add paths for the children, + * so we have to do it ourselves. set_append_rel_pathlist will eventually + * call this hook again for each child chunk. + */ + rel->pathlist = NIL; + rel->partial_pathlist = NIL; + ts_set_append_rel_pathlist(root, rel, rti, rte); } static void @@ -1461,23 +1393,6 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang reltype = ts_classify_relation(root, rel, &ht); - /* Check for unexpanded hypertable */ - if (!rte->inh && ts_rte_is_marked_for_expansion(rte)) - { - expand_hypertables(root, rel, rti, rte); - } - - if (ts_guc_enable_optimizations) - { - ts_planner_constraint_cleanup(root, rel); - } - - /* Call other extensions. Do it after table expansion. */ - if (prev_set_rel_pathlist_hook != NULL) - { - (*prev_set_rel_pathlist_hook)(root, rel, rti, rte); - } - switch (reltype) { case TS_REL_HYPERTABLE_CHILD: @@ -1507,17 +1422,21 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang case TS_REL_HYPERTABLE: if (!rte->inh) { - /* - * This happens with SELECT FROM ONLY hypertable or with an - * empty hypertable. Mark it as dummy, otherwise we'll get a - * scan on hypertable relation itself. It's always empty, so - * this scan is useless and looks misleading. - */ - mark_dummy_rel(rel); - } - else - { - apply_optimizations(root, reltype, rel, rte, ht); + if (ts_rte_is_marked_for_expansion(rte)) + { + expand_hypertable(root, rel, rti, rte); + apply_optimizations(root, reltype, rel, rte, ht); + } + else + { + /* + * This happens with SELECT FROM ONLY hypertable or with an + * empty hypertable. Mark it as dummy, otherwise we'll get a + * scan on hypertable relation itself. It's always empty, so + * this scan is useless and looks misleading. + */ + mark_dummy_rel(rel); + } } break; @@ -1525,6 +1444,17 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang apply_optimizations(root, reltype, rel, rte, ht); break; } + + if (ts_guc_enable_optimizations) + { + ts_planner_constraint_cleanup(root, rel); + } + + /* Call other extensions. Do it after table expansion. */ + if (prev_set_rel_pathlist_hook != NULL) + { + (*prev_set_rel_pathlist_hook)(root, rel, rti, rte); + } } /* This hook is meant to editorialize about the information the planner gets diff --git a/test/expected/append-16.out b/test/expected/append-16.out index cfcc56f18ab..43a9cfe4acb 100644 --- a/test/expected/append-16.out +++ b/test/expected/append-16.out @@ -1748,7 +1748,7 @@ DROP INDEX :INDEX_NAME; Limit (actual rows=3.00 loops=1) -> Merge Join (actual rows=3.00 loops=1) Merge Cond: (m2."time" = m1."time") - Join Filter: (m1.device_id = m2.device_id) + Join Filter: (m2.device_id = m1.device_id) Rows Removed by Join Filter: 4 -> Custom Scan (ChunkAppend) on join_limit m2 (actual rows=3.00 loops=1) Order: m2."time", m2.device_id diff --git a/test/expected/append-17.out b/test/expected/append-17.out index c40d9e1be91..42da8954e60 100644 --- a/test/expected/append-17.out +++ b/test/expected/append-17.out @@ -1743,7 +1743,7 @@ DROP INDEX :INDEX_NAME; Limit (actual rows=3.00 loops=1) -> Merge Join (actual rows=3.00 loops=1) Merge Cond: (m2."time" = m1."time") - Join Filter: (m1.device_id = m2.device_id) + Join Filter: (m2.device_id = m1.device_id) Rows Removed by Join Filter: 4 -> Custom Scan (ChunkAppend) on join_limit m2 (actual rows=3.00 loops=1) Order: m2."time", m2.device_id diff --git a/test/expected/append-18.out b/test/expected/append-18.out index f8fa120309c..5584a964442 100644 --- a/test/expected/append-18.out +++ b/test/expected/append-18.out @@ -1746,7 +1746,7 @@ DROP INDEX :INDEX_NAME; Limit (actual rows=3.00 loops=1) -> Merge Join (actual rows=3.00 loops=1) Merge Cond: (m2."time" = m1."time") - Join Filter: (m1.device_id = m2.device_id) + Join Filter: (m2.device_id = m1.device_id) Rows Removed by Join Filter: 4 -> Custom Scan (ChunkAppend) on join_limit m2 (actual rows=3.00 loops=1) Order: m2."time", m2.device_id diff --git a/test/expected/plan_expand_hypertable-16.out b/test/expected/plan_expand_hypertable-16.out index 43fac46ccb9..4115404edf5 100644 --- a/test/expected/plan_expand_hypertable-16.out +++ b/test/expected/plan_expand_hypertable-16.out @@ -3228,52 +3228,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) :PREFIX @@ -3289,52 +3282,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) \set ECHO errors diff --git a/test/expected/plan_expand_hypertable-17.out b/test/expected/plan_expand_hypertable-17.out index ec87b7e043a..553bfde3eaa 100644 --- a/test/expected/plan_expand_hypertable-17.out +++ b/test/expected/plan_expand_hypertable-17.out @@ -3228,52 +3228,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) :PREFIX @@ -3289,52 +3282,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) \set ECHO errors diff --git a/test/expected/plan_expand_hypertable-18.out b/test/expected/plan_expand_hypertable-18.out index ec87b7e043a..553bfde3eaa 100644 --- a/test/expected/plan_expand_hypertable-18.out +++ b/test/expected/plan_expand_hypertable-18.out @@ -3228,52 +3228,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) :PREFIX @@ -3289,52 +3282,45 @@ SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timesta Hash Cond: (o2_m1."time" = o1_m1."time") -> Nested Loop -> Append - -> Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 - Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_160_chunk o2_m1_1 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_169_chunk o2_m2_2 + -> Seq Scan on _hyper_6_161_chunk o2_m1_2 Filter: (device_id = 2) - -> Seq Scan on _hyper_7_170_chunk o2_m2_3 + -> Seq Scan on _hyper_6_162_chunk o2_m1_3 Filter: (device_id = 2) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_163_chunk o2_m1_4 Filter: (device_id = 2) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2 - Index Cond: ("time" = o2_m2."time") + -> Seq Scan on _hyper_6_164_chunk o2_m1_5 Filter: (device_id = 2) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3 - Index Cond: ("time" = o2_m2."time") + -> Append + -> Index Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1 + Index Cond: (("time" = o2_m1."time") AND ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 2) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk o2_m2_2 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5 - Index Cond: ("time" = o2_m2."time") + -> Index Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk o2_m2_3 + Index Cond: ("time" = o2_m1."time") Filter: (device_id = 2) -> Hash -> Nested Loop -> Append - -> Seq Scan on _hyper_7_165_chunk o1_m2_1 + -> Seq Scan on _hyper_6_160_chunk o1_m1_1 Filter: (device_id = 1) - -> Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 - Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) + -> Seq Scan on _hyper_6_161_chunk o1_m1_2 Filter: (device_id = 1) - -> Append - -> Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_162_chunk o1_m1_3 Filter: (device_id = 1) - -> Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_163_chunk o1_m1_4 Filter: (device_id = 1) - -> Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3 - Index Cond: ("time" = o1_m2."time") + -> Seq Scan on _hyper_6_164_chunk o1_m1_5 Filter: (device_id = 1) - -> Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4 - Index Cond: ("time" = o1_m2."time") + -> Append + -> Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk o1_m2_1 + Index Cond: ("time" = o1_m1."time") Filter: (device_id = 1) - -> Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5 - Index Cond: ("time" = o1_m2."time") + -> Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2 + Index Cond: (("time" = o1_m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)) Filter: (device_id = 1) \set ECHO errors