Skip to content

Commit

Permalink
add moar tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
shanth96 committed Aug 7, 2024
1 parent 7c76d4b commit 9b157b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,18 @@ func (e *Executor) buildStatement(
reservedVars *sqlparser.ReservedVars,
bindVarNeeds *sqlparser.BindVarNeeds,
) (*engine.Plan, error) {
buildSpan, ctx := trace.NewSpan(ctx, "buildStatement.build")
plan, err := planbuilder.BuildFromStmt(ctx, query, stmt, reservedVars, vcursor, bindVarNeeds, enableOnlineDDL, enableDirectDDL)
if err != nil {
return nil, err
}
buildSpan.Finish()

plan.Warnings = vcursor.warnings
vcursor.warnings = nil

validSpan, _ := trace.NewSpan(ctx, "buildStatement.valid")
defer validSpan.Finish()
err = e.checkThatPlanIsValid(stmt, plan)
return plan, err
}
Expand Down
6 changes: 6 additions & 0 deletions go/vt/vtgate/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/vschemawrapper"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/key"
querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -158,10 +159,15 @@ func buildRoutePlan(stmt sqlparser.Statement, reservedVars *sqlparser.ReservedVa
func createInstructionFor(ctx context.Context, query string, stmt sqlparser.Statement, reservedVars *sqlparser.ReservedVars, vschema plancontext.VSchema, enableOnlineDDL, enableDirectDDL bool) (*planResult, error) {
switch stmt := stmt.(type) {
case *sqlparser.Select, *sqlparser.Insert, *sqlparser.Update, *sqlparser.Delete:
getSpan, ctx := trace.NewSpan(ctx, "createInstruction.getPlanner")
configuredPlanner, err := getConfiguredPlanner(vschema, stmt, query)
if err != nil {
return nil, err
}
getSpan.Finish()

buildRouteSpan, _ := trace.NewSpan(ctx, "createInstruction.buildRoutePlan")
defer buildRouteSpan.Finish()
return buildRoutePlan(stmt, reservedVars, vschema, configuredPlanner)
case *sqlparser.Union:
configuredPlanner, err := getConfiguredPlanner(vschema, stmt, query)
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vttablet/tabletserver/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,13 @@ func (qe *QueryEngine) GetPlan(ctx context.Context, logStats *tabletenv.LogStats
var plan *TabletPlan
var err error

schemaSpan, ctx := trace.NewSpan(ctx, "GetPlan.schemaLoad")
curSchema := qe.schema.Load()
schemaSpan.Finish()

if skipQueryPlanCache {
getPlanSpan, _ := trace.NewSpan(ctx, "GetPlan.getPlan")
defer getPlanSpan.Finish()
plan, err = qe.getPlan(curSchema, sql)
} else {
plan, logStats.CachedPlan, err = qe.plans.GetOrLoad(PlanCacheKey(sql), curSchema.epoch, func() (*TabletPlan, error) {
Expand Down

0 comments on commit 9b157b7

Please sign in to comment.