Skip to content

Commit

Permalink
Export is_decompress_chunk_path / is_gapfill_path
Browse files Browse the repository at this point in the history
This patch adds the 'ts_' prefix to the function names of
is_decompress_chunk_path and is_gapfill_path and makes them available
for use by other parts of TimescaleDB.
  • Loading branch information
jnidzwetzki committed Aug 31, 2023
1 parent fa04a06 commit 08231c8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
13 changes: 13 additions & 0 deletions src/gapfill.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
#include "cross_module_fn.h"
#include "compat/compat.h"
#include "export.h"
#include "gapfill.h"

bool
ts_is_gapfill_path(Path *path)
{
if (IsA(path, CustomPath))
{
CustomPath *cpath = castNode(CustomPath, path);
if (strcmp(cpath->methods->CustomName, GAPFILL_PATH_NAME) == 0)
return true;
}
return false;
}

/*
* stub function to trigger locf and interpolate in gapfill node
Expand Down
13 changes: 13 additions & 0 deletions src/gapfill.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/
#ifndef TIMESCALEDB_GAPFILL_H
#define TIMESCALEDB_GAPFILL_H

#define GAPFILL_PATH_NAME "GapFill"

extern bool ts_is_gapfill_path(Path *path);

#endif
21 changes: 21 additions & 0 deletions src/nodes/chunk_append/chunk_append.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ create_group_subpath(PlannerInfo *root, RelOptInfo *rel, List *group, List *path
}
}

ChunkAppendPath *
ts_chunk_append_path_copy(ChunkAppendPath *ca, List *subpaths)
{
ListCell *lc;
double total_cost = 0, rows = 0;
ChunkAppendPath *new = palloc(sizeof(ChunkAppendPath));
memcpy(new, ca, sizeof(ChunkAppendPath));
new->cpath.custom_paths = subpaths;

foreach (lc, subpaths)
{
Path *child = lfirst(lc);
total_cost += child->total_cost;
rows += child->rows;
}
new->cpath.path.total_cost = total_cost;
new->cpath.path.rows = rows;

return new;
}

Path *
ts_chunk_append_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht, Path *subpath,
bool parallel_aware, bool ordered, List *nested_oids)
Expand Down
1 change: 1 addition & 0 deletions src/nodes/chunk_append/chunk_append.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef struct ChunkAppendPath
int first_partial_path;
} ChunkAppendPath;

extern TSDLLEXPORT ChunkAppendPath *ts_chunk_append_path_copy(ChunkAppendPath *ca, List *subpaths);
extern Path *ts_chunk_append_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht,
Path *subpath, bool parallel_aware, bool ordered,
List *nested_oids);
Expand Down
16 changes: 2 additions & 14 deletions src/planner/add_hashagg.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "planner.h"
#include "import/planner.h"
#include "utils.h"
#include "gapfill.h"
#include "guc.h"
#include "estimate.h"

Expand All @@ -38,19 +39,6 @@
* optimization fixes the statistics and adds the HashAggregate plan if appropriate.
* */

#define GAPFILL_PATH_NAME "GapFill"
static bool
is_gapfill_path(Path *path)
{
if (IsA(path, CustomPath))
{
CustomPath *cpath = castNode(CustomPath, path);
if (strcmp(cpath->methods->CustomName, GAPFILL_PATH_NAME) == 0)
return true;
}
return false;
}

/* Add a parallel HashAggregate plan.
* This code is similar to parts of create_grouping_paths */
static void
Expand Down Expand Up @@ -163,7 +151,7 @@ ts_plan_add_hashagg(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *output
return;

/* Don't add HashAgg path if this is a gapfill query */
if (is_gapfill_path(linitial(output_rel->pathlist)))
if (ts_is_gapfill_path(linitial(output_rel->pathlist)))
return;

MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
Expand Down
24 changes: 1 addition & 23 deletions tsl/src/nodes/skip_scan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ static OpExpr *fix_indexqual(IndexOptInfo *index, RestrictInfo *rinfo, AttrNumbe
static bool build_skip_qual(PlannerInfo *root, SkipScanPath *skip_scan_path, IndexPath *index_path,
Var *var);
static List *build_subpath(PlannerInfo *root, List *subpaths, double ndistinct);
static ChunkAppendPath *copy_chunk_append_path(ChunkAppendPath *ca, List *subpaths);
static Var *get_distinct_var(PlannerInfo *root, IndexPath *index_path,
SkipScanPath *skip_scan_path);
static TargetEntry *tlist_member_match_var(Var *var, List *targetlist);
Expand Down Expand Up @@ -293,7 +292,7 @@ tsl_skip_scan_paths_add(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *ou
* information used for creating the original one and we don't want to
* duplicate all the checks done when creating the original one.
*/
subpath = (Path *) copy_chunk_append_path(ca, new_paths);
subpath = (Path *) ts_chunk_append_path_copy(ca, new_paths);
}
else
{
Expand All @@ -318,27 +317,6 @@ tsl_skip_scan_paths_add(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *ou
}
}

static ChunkAppendPath *
copy_chunk_append_path(ChunkAppendPath *ca, List *subpaths)
{
ListCell *lc;
double total_cost = 0, rows = 0;
ChunkAppendPath *new = palloc(sizeof(ChunkAppendPath));
memcpy(new, ca, sizeof(ChunkAppendPath));
new->cpath.custom_paths = subpaths;

foreach (lc, subpaths)
{
Path *child = lfirst(lc);
total_cost += child->total_cost;
rows += child->rows;
}
new->cpath.path.total_cost = total_cost;
new->cpath.path.rows = rows;

return new;
}

static SkipScanPath *
skip_scan_path_create(PlannerInfo *root, IndexPath *index_path, double ndistinct)
{
Expand Down

0 comments on commit 08231c8

Please sign in to comment.