Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use postgres implementation of estimate_hashagg_tablesize #2467

Merged
merged 1 commit into from Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/compat.h
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
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
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
8 changes: 4 additions & 4 deletions src/plan_add_hashagg.c
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,9 +64,8 @@ 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,
&agg_partial_costs,
d_num_partial_groups);
hashagg_table_size =
estimate_hashagg_tablesize(cheapest_partial_path, &agg_partial_costs, d_num_partial_groups);

/*
* Tentatively produce a partial HashAgg Path, depending on if it looks as
Expand Down Expand Up @@ -146,7 +146,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