Skip to content
51 changes: 25 additions & 26 deletions tsl/src/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,51 +54,50 @@ tsl_create_upper_paths_hook(PlannerInfo *root, UpperRelationKind stage, RelOptIn
RelOptInfo *output_rel, TsRelType input_reltype, Hypertable *ht,
void *extra)
{
/*
* Gapfill node cannot be disabled if the query specifies it, so it runs
* regardless of the timescaledb.enable_optimizations GUC.
*/
switch (stage)
if (ts_guc_enable_optimizations)
{

switch (stage)
{
case UPPERREL_GROUP_AGG:
if (input_reltype != TS_REL_HYPERTABLE_CHILD)
if (ts_guc_enable_chunkwise_aggregation && input_rel != NULL &&
!IS_DUMMY_REL(input_rel) && output_rel != NULL &&
involves_hypertable(root, input_rel))
{
plan_add_gapfill(root, output_rel);
tsl_pushdown_partial_agg(root, ht, input_rel, output_rel, extra);
}
break;
case UPPERREL_WINDOW:
if (IsA(linitial(input_rel->pathlist), CustomPath))

if (root->numOrderedAggs && !IS_DUMMY_REL(input_rel) && output_rel != NULL)
{
gapfill_adjust_window_targetlist(root, input_rel, output_rel);
tsl_skip_scan_paths_add(root, input_rel, output_rel, stage);
}
break;
case UPPERREL_DISTINCT:
tsl_skip_scan_paths_add(root, input_rel, output_rel, stage);
break;
default:
break;
}
}

if (!ts_guc_enable_optimizations)
{
return;
}

/*
* Gapfill node cannot be disabled if the query specifies it, so it runs
* regardless of the timescaledb.enable_optimizations GUC.
*/
switch (stage)
{
case UPPERREL_GROUP_AGG:
if (ts_guc_enable_chunkwise_aggregation && input_rel != NULL &&
!IS_DUMMY_REL(input_rel) && output_rel != NULL &&
involves_hypertable(root, input_rel))
if (input_reltype != TS_REL_HYPERTABLE_CHILD)
{
tsl_pushdown_partial_agg(root, ht, input_rel, output_rel, extra);
plan_add_gapfill(root, output_rel);
}

if (root->numOrderedAggs && !IS_DUMMY_REL(input_rel) && output_rel != NULL)
break;
case UPPERREL_WINDOW:
if (IsA(linitial(input_rel->pathlist), CustomPath))
{
tsl_skip_scan_paths_add(root, input_rel, output_rel, stage);
gapfill_adjust_window_targetlist(root, input_rel, output_rel);
}
break;
case UPPERREL_DISTINCT:
tsl_skip_scan_paths_add(root, input_rel, output_rel, stage);
break;
default:
break;
}
Expand Down
Loading