MCPcopy
hub / github.com/pingcap/tidb / Preprocess

Function Preprocess

pkg/planner/core/preprocess.go:127–155  ·  view source on GitHub ↗

Preprocess resolves table names of the node, and checks some statements' validation. preprocessReturn used to extract the infoschema for the tableName and the timestamp from the asof clause.

(ctx context.Context, sctx sessionctx.Context, node *resolve.NodeW, preprocessOpt ...PreprocessOpt)

Source from the content-addressed store, hash-verified

125// Preprocess resolves table names of the node, and checks some statements' validation.
126// preprocessReturn used to extract the infoschema for the tableName and the timestamp from the asof clause.
127func Preprocess(ctx context.Context, sctx sessionctx.Context, node *resolve.NodeW, preprocessOpt ...PreprocessOpt) error {
128 defer tracing.StartRegion(ctx, "planner.Preprocess").End()
129 v := preprocessor{
130 ctx: ctx,
131 sctx: sctx,
132 tableAliasInJoin: make([]map[string]any, 0),
133 preprocessWith: &preprocessWith{cteCanUsed: make([]string, 0), cteBeforeOffset: make([]int, 0)},
134 lockSelectCtxStack: make([]lockSelectCtx, 0),
135 staleReadProcessor: staleread.NewStaleReadProcessor(ctx, sctx),
136 varsMutable: make(map[string]struct{}),
137 varsReadonly: make(map[string]struct{}),
138 resolveCtx: node.GetResolveContext(),
139 }
140 for _, optFn := range preprocessOpt {
141 optFn(&v)
142 }
143 // PreprocessorReturn must be non-nil before preprocessing
144 if v.PreprocessorReturn == nil {
145 v.PreprocessorReturn = &PreprocessorReturn{}
146 }
147 node.Node.Accept(&v)
148 // InfoSchema must be non-nil after preprocessing
149 v.ensureInfoSchema()
150 sctx.GetPlanCtx().SetReadonlyUserVarMap(v.varsReadonly)
151 if len(v.varsReadonly) > 0 {
152 sctx.GetSessionVars().StmtCtx.SetSkipPlanCache("read-only variables are used")
153 }
154 return errors.Trace(v.err)
155}
156
157type preprocessorFlag uint64
158

Callers 15

TestPointGetIdFunction · 0.92
runSQLFunction · 0.92
TestPreprocessCTEFunction · 0.92
BenchmarkOptimizeFunction · 0.92
TestAnalyzeBuildSuccFunction · 0.92
TestAnalyzeSetRateFunction · 0.92
getTableStatsFunction · 0.92

Calls 10

ensureInfoSchemaMethod · 0.95
StartRegionFunction · 0.92
NewStaleReadProcessorFunction · 0.92
GetResolveContextMethod · 0.80
EndMethod · 0.65
AcceptMethod · 0.65
SetReadonlyUserVarMapMethod · 0.65
GetPlanCtxMethod · 0.65
SetSkipPlanCacheMethod · 0.65
GetSessionVarsMethod · 0.65

Tested by 15

TestPointGetIdFunction · 0.74
runSQLFunction · 0.74
TestPreprocessCTEFunction · 0.74
BenchmarkOptimizeFunction · 0.74
TestAnalyzeBuildSuccFunction · 0.74
TestAnalyzeSetRateFunction · 0.74
getTableStatsFunction · 0.74