From 08231c8aacd17152f315ad36d95c031fb46073aa Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Tue, 29 Aug 2023 14:47:57 +0200 Subject: [PATCH] Export is_decompress_chunk_path / is_gapfill_path 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. --- src/gapfill.c | 13 +++++++++++++ src/gapfill.h | 13 +++++++++++++ src/nodes/chunk_append/chunk_append.c | 21 +++++++++++++++++++++ src/nodes/chunk_append/chunk_append.h | 1 + src/planner/add_hashagg.c | 16 ++-------------- tsl/src/nodes/skip_scan/planner.c | 24 +----------------------- 6 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 src/gapfill.h diff --git a/src/gapfill.c b/src/gapfill.c index d5c835555..e4661e092 100644 --- a/src/gapfill.c +++ b/src/gapfill.c @@ -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 diff --git a/src/gapfill.h b/src/gapfill.h new file mode 100644 index 000000000..4bcb35d96 --- /dev/null +++ b/src/gapfill.h @@ -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 diff --git a/src/nodes/chunk_append/chunk_append.c b/src/nodes/chunk_append/chunk_append.c index ba6bb51a1..6b0b672a3 100644 --- a/src/nodes/chunk_append/chunk_append.c +++ b/src/nodes/chunk_append/chunk_append.c @@ -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) diff --git a/src/nodes/chunk_append/chunk_append.h b/src/nodes/chunk_append/chunk_append.h index 220f292e6..6426edebf 100644 --- a/src/nodes/chunk_append/chunk_append.h +++ b/src/nodes/chunk_append/chunk_append.h @@ -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); diff --git a/src/planner/add_hashagg.c b/src/planner/add_hashagg.c index eb20621d1..7999b390c 100644 --- a/src/planner/add_hashagg.c +++ b/src/planner/add_hashagg.c @@ -23,6 +23,7 @@ #include "planner.h" #include "import/planner.h" #include "utils.h" +#include "gapfill.h" #include "guc.h" #include "estimate.h" @@ -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 @@ -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)); diff --git a/tsl/src/nodes/skip_scan/planner.c b/tsl/src/nodes/skip_scan/planner.c index caec36130..8fd76f411 100644 --- a/tsl/src/nodes/skip_scan/planner.c +++ b/tsl/src/nodes/skip_scan/planner.c @@ -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); @@ -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 { @@ -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) {