@@ -635,16 +635,20 @@ func (opc *optPlanningCtx) buildNonIdealGenericPlan() bool {
635
635
// ideal generic query plan is always chosen, if it exists. A non-ideal generic
636
636
// plan is chosen if CustomPlanThreshold custom plans have already been built
637
637
// and the generic plan is optimal or it has not yet been built.
638
- func (opc * optPlanningCtx ) chooseGenericPlan () bool {
638
+ func (opc * optPlanningCtx ) chooseGenericPlan (ctx context. Context ) bool {
639
639
ps := opc .p .stmt .Prepared
640
640
// Always use an ideal generic plan.
641
641
if ps .IdealGenericPlan {
642
+ opc .log (ctx , "ideal generic plan" )
642
643
return true
643
644
}
644
645
switch opc .p .SessionData ().PlanCacheMode {
645
646
case sessiondatapb .PlanCacheModeForceGeneric :
646
647
return true
647
648
case sessiondatapb .PlanCacheModeAuto :
649
+ if log .ExpensiveLogEnabled (ctx , 1 ) {
650
+ log .Eventf (ctx , "%s" , ps .Costs .Summary ())
651
+ }
648
652
return ps .Costs .NumCustom () >= prep .CustomPlanThreshold &&
649
653
(! ps .Costs .HasGeneric () || ps .Costs .IsGenericOptimal ())
650
654
default :
@@ -706,7 +710,7 @@ func (opc *optPlanningCtx) chooseValidPreparedMemo(ctx context.Context) (*memo.M
706
710
707
711
// NOTE: The generic or base memos returned below could be nil if they have
708
712
// not yet been built.
709
- if opc .chooseGenericPlan () {
713
+ if opc .chooseGenericPlan (ctx ) {
710
714
return prep .GenericMemo , nil
711
715
}
712
716
return prep .BaseMemo , nil
@@ -775,7 +779,7 @@ func (opc *optPlanningCtx) fetchPreparedMemo(ctx context.Context) (_ *memo.Memo,
775
779
prep .Costs .SetGeneric (newMemo .RootExpr ().Cost ())
776
780
// Now that the cost of the generic plan is known, we need to
777
781
// re-evaluate the decision to use a generic or custom plan.
778
- if ! opc .chooseGenericPlan () {
782
+ if ! opc .chooseGenericPlan (ctx ) {
779
783
// The generic plan that we just built is too expensive, so we need
780
784
// to build a custom plan. We recursively call fetchPreparedMemo in
781
785
// case we have a custom plan that can be reused as a starting point
0 commit comments