8000 Fill hook on a number of groups estimation with a gag code · postgrespro/aqo@8f45ee6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f45ee6

Browse files
danolivoAndrey Lepikhov
authored andcommitted
Fill hook on a number of groups estimation with a gag code
1 parent b3a669c commit 8f45ee6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cardinality_hooks.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,22 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
396396
clauses);
397397
}
398398

399+
static double
400+
predict_num_groups(PlannerInfo *root, RelOptInfo *rel, List *group_exprs)
401+
{
402+
return -1;
403+
}
404+
399405
double
400406
aqo_estimate_num_groups_hook(PlannerInfo *root, List *groupExprs,
401407
RelOptInfo *rel, List **pgset,
402408
EstimationInfo *estinfo)
403409
{
404410
double input_rows = rel->cheapest_total_path->rows;
405411
double nGroups = -1;
412+
ListCell *lc;
413+
int i = 0;
414+
List *group_exprs = NIL;
406415

407416
if (!query_context.use_aqo)
408417
{
@@ -419,5 +428,33 @@ aqo_estimate_num_groups_hook(PlannerInfo *root, List *groupExprs,
419428
if (prev_estimate_num_groups_hook != NULL)
420429
elog(WARNING, "AQO replaced another estimator of a groups number");
421430

431+
/* Zero the estinfo output parameter, if non-NULL */
432+
if (estinfo != NULL)
433+
memset(estinfo, 0, sizeof(EstimationInfo));
434+
435+
if (groupExprs == NIL || (pgset && list_length(*pgset) < 1))
436+
return 1.0;
437+
438+
foreach(lc, groupExprs)
439+
{
440+
Node *groupexpr = (Node *) lfirst(lc);
441+
442+
/* is expression in this grouping set? */
443+
if (pgset && !list_member_int(*pgset, i++))
444+
continue;
445+
446+
group_exprs = lappend(group_exprs, groupexpr);
447+
}
448+
449+
if (group_exprs != NIL)
450+
{
451+
double predicted;
452+
453+
predicted = predict_num_groups(root, rel, group_exprs);
454+
if (predicted > 0.)
455+
return predicted;
456+
}
457+
458+
pfree(group_exprs);
422459
return estimate_num_groups(root, groupExprs, input_rows, pgset, estinfo);
423460
}

0 commit comments

Comments
 (0)
0