Skip to content

Commit

Permalink
Use postgres implementation of estimate_hashagg_tablesize
Browse files Browse the repository at this point in the history
Only use our own implementation of estimate_hashagg_tablesize on
versions where the postgres implementation is static.
  • Loading branch information
svenklemm committed Sep 29, 2020
1 parent 423e8fa commit 4259951
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
#define create_append_path_compat create_append_path
#endif

/*
* estimate_hashagg_tablesize is a static function in PG11 and earlier so we map
* to our own copy when it's not available
*/
#if PG11
#define estimate_hashagg_tablesize(p, c, n) ts_estimate_hashagg_tablesize(p, c, n)
#endif

#include <commands/vacuum.h>
#include <commands/defrem.h>

Expand Down
2 changes: 2 additions & 0 deletions src/import/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ ts_make_inh_translation_list(Relation oldrelation, Relation newrelation, Index n
*translated_vars = vars;
}

#if PG11
/* copied exactly from planner.c */
size_t
ts_estimate_hashagg_tablesize(struct Path *path, const struct AggClauseCosts *agg_costs,
Expand All @@ -184,6 +185,7 @@ ts_estimate_hashagg_tablesize(struct Path *path, const struct AggClauseCosts *ag
*/
return hashentrysize * dNumGroups;
}
#endif

/* copied verbatim from planner.c */
struct PathTarget *
Expand Down
2 changes: 2 additions & 0 deletions src/import/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

extern TSDLLEXPORT void ts_make_inh_translation_list(Relation oldrelation, Relation newrelation,
Index newvarno, List **translated_vars);
#if PG11
extern size_t ts_estimate_hashagg_tablesize(struct Path *path,
const struct AggClauseCosts *agg_costs,
double dNumGroups);
#endif

extern struct PathTarget *ts_make_partial_grouping_target(struct PlannerInfo *root,
PathTarget *grouping_target);
Expand Down
5 changes: 3 additions & 2 deletions src/plan_add_hashagg.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <optimizer/cost.h>
#include "compat-msvc-exit.h"

#include "compat.h"
#include "plan_add_hashagg.h"
#include "import/planner.h"
#include "utils.h"
Expand Down Expand Up @@ -63,7 +64,7 @@ plan_add_parallel_hashagg(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *
get_agg_clause_costs(root, parse->havingQual, AGGSPLIT_FINAL_DESERIAL, &agg_final_costs);
}

hashagg_table_size = ts_estimate_hashagg_tablesize(cheapest_partial_path,
hashagg_table_size = estimate_hashagg_tablesize(cheapest_partial_path,
&agg_partial_costs,
d_num_partial_groups);

Expand Down Expand Up @@ -146,7 +147,7 @@ ts_plan_add_hashagg(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *output
if (!IS_VALID_ESTIMATE(d_num_groups))
return;

hashaggtablesize = ts_estimate_hashagg_tablesize(cheapest_path, &agg_costs, d_num_groups);
hashaggtablesize = estimate_hashagg_tablesize(cheapest_path, &agg_costs, d_num_groups);

if (hashaggtablesize >= work_mem * UINT64CONST(1024))
return;
Expand Down

0 comments on commit 4259951

Please sign in to comment.