Skip to content

Commit

Permalink
Remove costing index scan of hypertable parent
Browse files Browse the repository at this point in the history
When computing cost for a merge join path, an index scan will be done
on the relation to find the actual variable range using
`get_actual_variable_range()`, which will include an index scan of the
hypertable parent.

In addition to being unneccessary, it can also cause problems in
situations where the hypertable parent contains data as a result of a
bug.

There is a check that an index scan is not done for a partitioned
table, so we do the same here by setting the indexlist to NIL after
hypertable expansion. The index list is needed while expanding the
hypertables to construct correct index scans for chunks of a
hypertable.
  • Loading branch information
mkindahl committed Mar 3, 2025
1 parent b665a4b commit 326688a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_7768
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #7768 Remove costing index scan of hypertable parent
13 changes: 13 additions & 0 deletions src/planner/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,19 @@ timescaledb_set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, Rang
#endif
TS_FALLTHROUGH;
default:
/*
* Set the indexlist for a hypertable parent to NIL since we
* should not try to do any index scans on hypertable parents,
* similar to how it works for partitioned tables.
*
* This can happen when building a merge join path and computing
* cost for it. See get_actual_variable_range().
*
* This has to be after the hypertable is expanded, since the
* indexlist is used during hypertable expansion.
*/
if (reltype == TS_REL_HYPERTABLE)
rel->indexlist = NIL;
apply_optimizations(root, reltype, rel, rte, ht);
break;
}
Expand Down

0 comments on commit 326688a

Please sign in to comment.