debugtrace

package
v1.1.0-beta.0...-70f5218 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeJSONCommon

func EncodeJSONCommon(input any) ([]byte, error)

EncodeJSONCommon contains some common logic for the debug trace, like disabling EscapeHTML and recording error.

func EnterContextCommon

func EnterContextCommon(sctx planctx.PlanContext)

EnterContextCommon records the function name of the caller, then creates and enter a new context for this debug trace structure.

func LeaveContextCommon

func LeaveContextCommon(sctx planctx.PlanContext)

LeaveContextCommon makes the debug trace goes to its parent context.

func RecordAnyValuesWithNames

func RecordAnyValuesWithNames(
	s planctx.PlanContext,
	vals ...any,
)

RecordAnyValuesWithNames is a general debug trace logic for recording some values of any type with a name. The vals arguments should be a slice like ["name1", value1, "name2", value2]. The names must be string, the values can be any type.

Types

type OptimizerDebugTraceRoot

type OptimizerDebugTraceRoot struct {
	// contains filtered or unexported fields
}

OptimizerDebugTraceRoot is for recording the optimizer debug trace. Each debug information, which is a "step" and can be any type, is placed in a "context" (baseDebugTraceContext) as an interface{}. Overall, the debug trace is a tree-like hierarchical structure of baseDebugTraceContext. This structure can reflect the function call hierarchy of each step during optimization. In the end, the entire recorded baseDebugTraceContext will be marshalled to JSON as the result.

EnterContextCommon and LeaveContextCommon can be used to maintain the context easily. Usually you just need to add the code below at the beginning of a function:

if StmtCtx.EnableOptimizerDebugTrace {
 EnterContextCommon(ds.ctx)
 defer LeaveContextCommon(ds.ctx)
}

To record debug information, AppendStepToCurrentContext and AppendStepWithNameToCurrentContext are provided as low-level methods. RecordAnyValuesWithNames handles some common logic for better usability, so it should be the most commonly used function for recording simple information. If the tracing logic is more complicated or need extra MarshalJSON logic, you should implement separate logic like in planner/core/debug_trace.go and statistics/debug_trace.go

func GetOrInitDebugTraceRoot

func GetOrInitDebugTraceRoot(sctx planctx.PlanContext) *OptimizerDebugTraceRoot

GetOrInitDebugTraceRoot returns the debug trace root. If it's not initialized, it will initialize it first.

func (*OptimizerDebugTraceRoot) AppendStepToCurrentContext

func (root *OptimizerDebugTraceRoot) AppendStepToCurrentContext(step any)

AppendStepToCurrentContext records debug information to the current context of the debug trace.

func (*OptimizerDebugTraceRoot) AppendStepWithNameToCurrentContext

func (root *OptimizerDebugTraceRoot) AppendStepWithNameToCurrentContext(step any, name string)

AppendStepWithNameToCurrentContext records debug information and a name to the current context of the debug trace.

func (*OptimizerDebugTraceRoot) MarshalJSON

func (root *OptimizerDebugTraceRoot) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON behavior and marshals the unexported traceCtx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL