Skip to content

Commit 6bd0cd6

Browse files
committed
sql: replace a few context.Background() with what we have in scope
I was looking into a timeout where we seemingly didn't respect the context cancellation and noticed a couple of places where we use `context.Backround()` that were easy to fix. Release note: None
1 parent d86d74d commit 6bd0cd6

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

pkg/sql/catalog/systemschema/system.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ type SystemTable struct {
14911491
func makeSystemTable(
14921492
createTableStmt string, tbl descpb.TableDescriptor, fns ...func(tbl *descpb.TableDescriptor),
14931493
) SystemTable {
1494-
ctx := context.Background()
14951494
{
14961495
nameInfo := descpb.NameInfo{
14971496
ParentID: tbl.ParentID,
@@ -1500,7 +1499,7 @@ func makeSystemTable(
15001499
}
15011500
privs := catprivilege.SystemSuperuserPrivileges(nameInfo)
15021501
if privs == nil {
1503-
log.Dev.Fatalf(ctx, "no superuser privileges found when building descriptor of system table %q", tbl.Name)
1502+
log.Dev.Fatalf(context.Background(), "no superuser privileges found when building descriptor of system table %q", tbl.Name)
15041503
}
15051504
tbl.Privileges = catpb.NewCustomSuperuserPrivilegeDescriptor(privs, username.NodeUserName())
15061505
}

pkg/sql/internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ func (ie *InternalExecutor) execInternal(
11701170
// TODO(andrei): Properly clone (deep copy) ie.sessionData.
11711171
sd = ie.sessionDataStack.Top().Clone()
11721172
} else {
1173-
sd = NewInternalSessionData(context.Background(), ie.s.cfg.Settings, "" /* opName */)
1173+
sd = NewInternalSessionData(ctx, ie.s.cfg.Settings, "" /* opName */)
11741174
}
11751175
if globalOverride := ieMultiOverride.Get(&ie.s.cfg.Settings.SV); globalOverride != "" {
11761176
globalOverride = strings.TrimSpace(globalOverride)

pkg/sql/opt/exec/execbuilder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (b *Builder) wrapFunctionImpl(
314314
if lookup != nil {
315315
unresolved := tree.MakeUnresolvedName(fnName)
316316
fnDef, err := lookup(
317-
context.Background(),
317+
b.ctx,
318318
tree.MakeUnresolvedFunctionName(&unresolved),
319319
&b.evalCtx.SessionData().SearchPath,
320320
)

pkg/sql/opt/norm/fold_constants_funcs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
package norm
77

88
import (
9-
"context"
10-
119
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1210
"github.com/cockroachdb/cockroach/pkg/sql/opt"
1311
"github.com/cockroachdb/cockroach/pkg/sql/opt/cat"
@@ -663,8 +661,10 @@ func (c *CustomFuncs) FoldFunction(
663661
if c.f.evalCtx != nil && c.f.catalog != nil { // Some tests leave those unset.
664662
unresolved := tree.MakeUnresolvedName(private.Name)
665663
def, err := c.f.catalog.ResolveFunction(
666-
context.Background(), tree.MakeUnresolvedFunctionName(&unresolved),
667-
&c.f.evalCtx.SessionData().SearchPath)
664+
c.f.ctx,
665+
tree.MakeUnresolvedFunctionName(&unresolved),
666+
&c.f.evalCtx.SessionData().SearchPath,
667+
)
668668
if err != nil {
669669
log.Dev.Warningf(c.f.ctx, "function %s() not defined: %v", redact.Safe(private.Name), err)
670670
return nil, false

pkg/sql/planner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ func newInternalPlanner(
395395
// asking the caller for one is hard to explain. What we need is better and
396396
// separate interfaces for planning and running plans, which could take
397397
// suitable contexts.
398+
// TODO(yuzefovich): this comment is outdated - we no longer store context
399+
// within EvalCtx. Re-evaluate the situation.
398400
ctx := logtags.AddTag(context.Background(), string(opName), "")
399401

400402
sd = sd.Clone()

0 commit comments

Comments
 (0)