Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execinfra: correctly reset the eval.Context in InternalClose #89093

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/sql/execinfra/processorsbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ type ProcessorBaseNoHelper struct {
// origCtx is the context from which ctx was derived. InternalClose() resets
// ctx to this.
origCtx context.Context
// evalOrigCtx is the original context that was stored in the eval.Context.
// InternalClose() uses it to correctly reset the eval.Context.
evalOrigCtx context.Context

State procState

Expand Down Expand Up @@ -862,6 +865,7 @@ func (pb *ProcessorBaseNoHelper) StartInternal(ctx context.Context, name string)
pb.span.SetTag(execinfrapb.ProcessorIDTagKey, attribute.IntValue(int(pb.ProcessorID)))
}
}
pb.evalOrigCtx = pb.EvalCtx.Context
pb.EvalCtx.Context = pb.Ctx
return pb.Ctx
}
Expand Down Expand Up @@ -893,7 +897,7 @@ func (pb *ProcessorBaseNoHelper) InternalClose() bool {
// Reset the context so that any incidental uses after this point do not
// access the finished span.
pb.Ctx = pb.origCtx
pb.EvalCtx.Context = pb.origCtx
pb.EvalCtx.Context = pb.evalOrigCtx
return true
}

Expand Down
11 changes: 0 additions & 11 deletions pkg/sql/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,18 +710,7 @@ func (ih *instrumentationHelper) SetIndexRecommendations(
isInternal,
) {
f := opc.optimizer.Factory()
// EvalContext() has the context with the already closed span, so we
// need to update with the current context.
// The replacement of the context here isn't ideal, but the current
// implementation of contexts would need to change
// significantly to accommodate this case.
evalCtx := opc.p.EvalContext()
oldCtx := evalCtx.Context
evalCtx.Context = ctx
defer func() {
evalCtx.Context = oldCtx
}()

f.Init(evalCtx, &opc.catalog)
f.FoldingControl().AllowStableFolds()
bld := optbuilder.New(ctx, &opc.p.semaCtx, evalCtx, &opc.catalog, f, opc.p.stmt.AST)
Expand Down