@@ -645,10 +645,15 @@ func (m *Memo) String() string {
645645 return b .String ()
646646}
647647
648- // CostDebugString returns a string representation of the memo with cost
648+ // LogCostDebugString logs a string representation of the memo with cost
649649// information for each expression, ordered by best to worst for each group,
650650// displayed in a tree structure.
651- func (m * Memo ) CostDebugString () interface {} {
651+ // Only logs if tracing is enabled.
652+ func (m * Memo ) LogCostDebugString () {
653+ if m .root == nil || ! m .Tracer .TraceEnabled {
654+ return
655+ }
656+
652657 exprs := make ([]string , m .cnt )
653658 groups := make ([]* ExprGroup , 0 )
654659
@@ -685,18 +690,20 @@ func (m *Memo) CostDebugString() interface{} {
685690 }
686691 b .WriteString (fmt .Sprintf ("%s G%d: %s\n " , beg , i + 1 , g ))
687692 }
688- return b .String ()
693+
694+ m .Tracer .Log ("Completed cost-based optimization:\n %s" , b .String ())
689695}
690696
691- // BestPlanDebugString returns a physical tree representation of the best plan for each group in the tree that is
697+ // LogBestPlanDebugString logs a physical tree representation of the best plan for each group in the tree that is
692698// referenced by the best plan in the root. This differs from other debug strings in that it represents the groups
693699// as children of their parents, rather than as a flat list, and only includes groups that are part of the best plan.
694- func (m * Memo ) BestPlanDebugString () interface {} {
695- if m .root == nil {
696- return ""
700+ // Only logs if tracing is enabled.
701+ func (m * Memo ) LogBestPlanDebugString () {
702+ if m .root == nil || ! m .Tracer .TraceEnabled {
703+ return
697704 }
698705
699- return m .root .BestPlanDebugString ()
706+ m . Tracer . Log ( "Best root plan: \n %s" , m .root .BestPlanDebugString () )
700707}
701708
702709type tableProps struct {
0 commit comments