@@ -396,13 +396,22 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
396
396
clauses );
397
397
}
398
398
399
+ static double
400
+ predict_num_groups (PlannerInfo * root , RelOptInfo * rel , List * group_exprs )
401
+ {
402
+ return -1 ;
403
+ }
404
+
399
405
double
400
406
aqo_estimate_num_groups_hook (PlannerInfo * root , List * groupExprs ,
401
407
RelOptInfo * rel , List * * pgset ,
402
408
EstimationInfo * estinfo )
403
409
{
404
410
double input_rows = rel -> cheapest_total_path -> rows ;
405
411
double nGroups = -1 ;
412
+ ListCell * lc ;
413
+ int i = 0 ;
414
+ List * group_exprs = NIL ;
406
415
407
416
if (!query_context .use_aqo )
408
417
{
@@ -419,5 +428,33 @@ aqo_estimate_num_groups_hook(PlannerInfo *root, List *groupExprs,
419
428
if (prev_estimate_num_groups_hook != NULL )
420
429
elog (WARNING , "AQO replaced another estimator of a groups number" );
421
430
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 );
422
459
return estimate_num_groups (root , groupExprs , input_rows , pgset , estinfo );
423
460
}
0 commit comments