github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/execinfra/flow_context.go (about) 1 // Copyright 2019 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 // This file lives here instead of sql/flowinfra to avoid an import cycle. 12 13 package execinfra 14 15 import ( 16 "github.com/cockroachdb/cockroach/pkg/base" 17 "github.com/cockroachdb/cockroach/pkg/keys" 18 "github.com/cockroachdb/cockroach/pkg/kv" 19 "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" 20 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 21 "github.com/cockroachdb/cockroach/pkg/util/log" 22 "github.com/cockroachdb/cockroach/pkg/util/stop" 23 ) 24 25 // FlowCtx encompasses the configuration parameters needed for various flow 26 // components. 27 type FlowCtx struct { 28 log.AmbientContext 29 30 Cfg *ServerConfig 31 32 // ID is a unique identifier for a remote flow. It is mainly used as a key 33 // into the flowRegistry. Since local flows do not need to exist in the flow 34 // registry (no inbound stream connections need to be performed), they are not 35 // assigned ids. This is done for performance reasons, as local flows are 36 // more likely to be dominated by setup time. 37 ID execinfrapb.FlowID 38 39 // EvalCtx is used by all the processors in the flow to evaluate expressions. 40 // Processors that intend to evaluate expressions with this EvalCtx should 41 // get a copy with NewEvalCtx instead of storing a pointer to this one 42 // directly (since some processor mutate the EvalContext they use). 43 // 44 // TODO(andrei): Get rid of this field and pass a non-shared EvalContext to 45 // cores of the processors that need it. 46 EvalCtx *tree.EvalContext 47 48 // The transaction in which kv operations performed by processors in the flow 49 // must be performed. Processors in the Flow will use this txn concurrently. 50 // This field is generally not nil, except for flows that don't run in a 51 // higher-level txn (like backfills). 52 Txn *kv.Txn 53 54 // nodeID is the ID of the node on which the processors using this FlowCtx 55 // run. 56 NodeID *base.SQLIDContainer 57 58 // TraceKV is true if KV tracing was requested by the session. 59 TraceKV bool 60 61 // Local is true if this flow is being run as part of a local-only query. 62 Local bool 63 } 64 65 // NewEvalCtx returns a modifiable copy of the FlowCtx's EvalContext. 66 // Processors should use this method any time they need to store a pointer to 67 // the EvalContext, since processors may mutate the EvalContext. Specifically, 68 // every processor that runs ProcOutputHelper.Init must pass in a modifiable 69 // EvalContext, since it stores that EvalContext in its exprHelpers and mutates 70 // them at runtime to ensure expressions are evaluated with the correct indexed 71 // var context. 72 func (ctx *FlowCtx) NewEvalCtx() *tree.EvalContext { 73 evalCopy := ctx.EvalCtx.Copy() 74 evalCopy.DistSQLTypeResolver = &execinfrapb.DistSQLTypeResolver{EvalContext: evalCopy} 75 return evalCopy 76 } 77 78 // TestingKnobs returns the distsql testing knobs for this flow context. 79 func (ctx *FlowCtx) TestingKnobs() TestingKnobs { 80 return ctx.Cfg.TestingKnobs 81 } 82 83 // Stopper returns the stopper for this flowCtx. 84 func (ctx *FlowCtx) Stopper() *stop.Stopper { 85 return ctx.Cfg.Stopper 86 } 87 88 // Codec returns the SQL codec for this flowCtx. 89 func (ctx *FlowCtx) Codec() keys.SQLCodec { 90 return ctx.EvalCtx.Codec 91 }