github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/optbuilder/show_trace.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package optbuilder
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
    15  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    16  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    17  	"github.com/cockroachdb/errors"
    18  )
    19  
    20  func (b *Builder) buildShowTrace(
    21  	showTrace *tree.ShowTraceForSession, inScope *scope,
    22  ) (outScope *scope) {
    23  	outScope = inScope.push()
    24  
    25  	switch showTrace.TraceType {
    26  	case tree.ShowTraceRaw, tree.ShowTraceKV:
    27  		if showTrace.Compact {
    28  			b.synthesizeResultColumns(outScope, sqlbase.ShowCompactTraceColumns)
    29  		} else {
    30  			b.synthesizeResultColumns(outScope, sqlbase.ShowTraceColumns)
    31  		}
    32  
    33  	case tree.ShowTraceReplica:
    34  		b.synthesizeResultColumns(outScope, sqlbase.ShowReplicaTraceColumns)
    35  
    36  	default:
    37  		panic(errors.AssertionFailedf("SHOW %s not supported", showTrace.TraceType))
    38  	}
    39  
    40  	outScope.expr = b.factory.ConstructShowTraceForSession(&memo.ShowTracePrivate{
    41  		TraceType: showTrace.TraceType,
    42  		Compact:   showTrace.Compact,
    43  		ColList:   colsToColList(outScope.cols),
    44  	})
    45  	return outScope
    46  }