diff --git a/pkg/ddl/BUILD.bazel b/pkg/ddl/BUILD.bazel index b31ff04a0e137..69d0b6069fc60 100644 --- a/pkg/ddl/BUILD.bazel +++ b/pkg/ddl/BUILD.bazel @@ -96,8 +96,8 @@ go_library( "//pkg/domain/infosync", "//pkg/errctx", "//pkg/expression", - "//pkg/expression/context", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/exprstatic", "//pkg/infoschema", "//pkg/kv", "//pkg/lightning/backend", @@ -133,8 +133,8 @@ go_library( "//pkg/store/driver/txn", "//pkg/store/helper", "//pkg/table", - "//pkg/table/context", "//pkg/table/tables", + "//pkg/table/tblctx", "//pkg/tablecodec", "//pkg/tidb-binlog/pump_client", "//pkg/ttl/cache", @@ -293,7 +293,7 @@ go_test( "//pkg/errno", "//pkg/executor", "//pkg/expression", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/infoschema", "//pkg/keyspace", "//pkg/kv", diff --git a/pkg/ddl/add_column.go b/pkg/ddl/add_column.go index f1428f3621445..79e4170f0097e 100644 --- a/pkg/ddl/add_column.go +++ b/pkg/ddl/add_column.go @@ -28,7 +28,7 @@ import ( "github.com/pingcap/tidb/pkg/ddl/notifier" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/meta" "github.com/pingcap/tidb/pkg/meta/autoid" diff --git a/pkg/ddl/backfilling.go b/pkg/ddl/backfilling.go index 54d1597e253dd..c04402dda0151 100644 --- a/pkg/ddl/backfilling.go +++ b/pkg/ddl/backfilling.go @@ -32,8 +32,8 @@ import ( ddlutil "github.com/pingcap/tidb/pkg/ddl/util" "github.com/pingcap/tidb/pkg/disttask/operator" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/metrics" @@ -183,10 +183,10 @@ func newBackfillCtx(id int, rInfo *reorgInfo, // See: https://github.com/pingcap/tidb/pull/25728 for more details. hasStrictMode := rInfo.ReorgMeta.SQLMode.HasStrictMode() tc := exprCtx.GetStaticEvalCtx().TypeCtx() - evalCtx := exprCtx.GetStaticEvalCtx().Apply(contextstatic.WithTypeFlags( + evalCtx := exprCtx.GetStaticEvalCtx().Apply(exprstatic.WithTypeFlags( tc.Flags().WithIgnoreZeroDateErr(!hasStrictMode), )) - exprCtx = exprCtx.Apply(contextstatic.WithEvalCtx(evalCtx)) + exprCtx = exprCtx.Apply(exprstatic.WithEvalCtx(evalCtx)) } tblCtx := newReorgTableMutateContext(exprCtx) diff --git a/pkg/ddl/backfilling_test.go b/pkg/ddl/backfilling_test.go index 109e9d9d7b434..ae689ce663271 100644 --- a/pkg/ddl/backfilling_test.go +++ b/pkg/ddl/backfilling_test.go @@ -22,7 +22,7 @@ import ( "github.com/pingcap/tidb/pkg/ddl/ingest" distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -96,21 +96,21 @@ func TestPickBackfillType(t *testing.T) { require.Equal(t, tp, model.ReorgTypeLitMerge) } -func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx *contextstatic.StaticExprContext, warnHandler contextutil.WarnHandler) { +func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx *exprstatic.ExprContext, warnHandler contextutil.WarnHandler) { exprCtxManualCheckFields := []struct { field string - check func(*contextstatic.StaticExprContext) + check func(*exprstatic.ExprContext) }{ { field: "evalCtx", - check: func(ctx *contextstatic.StaticExprContext) { + check: func(ctx *exprstatic.ExprContext) { require.NotZero(t, ctx.GetEvalCtx().CtxID()) require.NotEqual(t, sctx.GetExprCtx().GetEvalCtx().CtxID(), ctx.GetEvalCtx().CtxID()) }, }, { field: "blockEncryptionMode", - check: func(context *contextstatic.StaticExprContext) { + check: func(context *exprstatic.ExprContext) { m := sctx.GetExprCtx().GetBlockEncryptionMode() if m == "" { // Empty string is not a valid encryption mode, so we expect the exprCtx.GetBlockEncryptionMode() @@ -123,13 +123,13 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx }, { field: "rng", - check: func(ctx *contextstatic.StaticExprContext) { + check: func(ctx *exprstatic.ExprContext) { require.NotNil(t, ctx.Rng()) }, }, { field: "planCacheTracker", - check: func(ctx *contextstatic.StaticExprContext) { + check: func(ctx *exprstatic.ExprContext) { require.Equal(t, sctx.GetExprCtx().IsUseCache(), ctx.IsUseCache()) ctx.SetSkipPlanCache("test reason") require.False(t, ctx.IsUseCache()) @@ -139,24 +139,24 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx evalCtxManualCheckFields := []struct { field string - check func(*contextstatic.StaticEvalContext) + check func(*exprstatic.EvalContext) }{ { field: "warnHandler", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { require.Same(t, warnHandler, ctx.GetWarnHandler()) }, }, { field: "typeCtx.warnHandler", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { ec := ctx.ErrCtx() require.Equal(t, errctx.NewContextWithLevels(ec.LevelMap(), ctx), ec) }, }, { field: "typeCtx.loc", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { tc := ctx.TypeCtx() require.Same(t, tc.Location(), ctx.Location()) require.Equal(t, sctx.GetSessionVars().Location().String(), tc.Location().String()) @@ -165,14 +165,14 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx }, { field: "errCtx.warnHandler", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { tc := ctx.TypeCtx() require.Equal(t, types.NewContext(tc.Flags(), tc.Location(), ctx), tc) }, }, { field: "currentTime", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { tm1, err := sctx.GetExprCtx().GetEvalCtx().CurrentTime() require.NoError(t, err) @@ -184,7 +184,7 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx }, { field: "requestVerificationFn", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { // RequestVerification should allow all privileges // that is the same with input session context (GetPrivilegeManager returns nil). require.Nil(t, privilege.GetPrivilegeManager(sctx)) @@ -194,7 +194,7 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx }, { field: "requestDynamicVerificationFn", - check: func(ctx *contextstatic.StaticEvalContext) { + check: func(ctx *exprstatic.EvalContext) { // RequestDynamicVerification should allow all privileges // that is the same with input session context (GetPrivilegeManager returns nil). require.Nil(t, privilege.GetPrivilegeManager(sctx)) @@ -204,21 +204,21 @@ func assertStaticExprContextEqual(t *testing.T, sctx sessionctx.Context, exprCtx }, } - // check StaticExprContext except StaticEvalContext + // check ExprContext except EvalContext expected := sctx.GetExprCtx().(*mock.Context).IntoStatic() ignoreFields := make([]string, 0, len(exprCtxManualCheckFields)) for _, f := range exprCtxManualCheckFields { f.check(exprCtx) - ignoreFields = append(ignoreFields, "$.staticExprCtxState."+f.field) + ignoreFields = append(ignoreFields, "$.exprCtxState."+f.field) } deeptest.AssertDeepClonedEqual(t, expected, exprCtx, deeptest.WithIgnorePath(ignoreFields)) - // check StaticEvalContext + // check EvalContext ignoreFields = make([]string, 0, len(evalCtxManualCheckFields)) ignoreFields = append(ignoreFields, "$.id") for _, f := range evalCtxManualCheckFields { f.check(exprCtx.GetStaticEvalCtx()) - ignoreFields = append(ignoreFields, "$.staticEvalCtxState."+f.field) + ignoreFields = append(ignoreFields, "$.evalCtxState."+f.field) } deeptest.AssertDeepClonedEqual( t, @@ -298,7 +298,7 @@ func TestReorgTableMutateContext(t *testing.T) { originalRowFmt := variable.GetDDLReorgRowFormat() defer variable.SetDDLReorgRowFormat(originalRowFmt) - exprCtx := contextstatic.NewStaticExprContext() + exprCtx := exprstatic.NewExprContext() assertTblCtxMatchSessionCtx := func(ctx table.MutateContext, sctx sessionctx.Context) { sctxTblCtx := sctx.GetTableCtx() diff --git a/pkg/ddl/copr/BUILD.bazel b/pkg/ddl/copr/BUILD.bazel index de29cc1539250..71f40bcb9ded6 100644 --- a/pkg/ddl/copr/BUILD.bazel +++ b/pkg/ddl/copr/BUILD.bazel @@ -8,7 +8,7 @@ go_library( deps = [ "//pkg/distsql/context", "//pkg/expression", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema", "//pkg/meta/model", "//pkg/parser/model", @@ -27,7 +27,7 @@ go_test( shard_count = 3, deps = [ "//pkg/expression", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/meta/model", "//pkg/parser/model", "//pkg/parser/mysql", diff --git a/pkg/ddl/copr/copr_ctx.go b/pkg/ddl/copr/copr_ctx.go index b4471f1b35cb3..e4736ffa78c41 100644 --- a/pkg/ddl/copr/copr_ctx.go +++ b/pkg/ddl/copr/copr_ctx.go @@ -18,7 +18,7 @@ import ( "github.com/pingcap/errors" distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" // make sure mock.MockInfoschema is initialized to make sure the test pass _ "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/meta/model" diff --git a/pkg/ddl/copr/copr_ctx_test.go b/pkg/ddl/copr/copr_ctx_test.go index 5dd6e5f9eb79b..34cde816a0738 100644 --- a/pkg/ddl/copr/copr_ctx_test.go +++ b/pkg/ddl/copr/copr_ctx_test.go @@ -19,7 +19,7 @@ import ( "testing" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/meta/model" pmodel "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -202,7 +202,7 @@ func TestCollectVirtualColumnOffsetsAndTypes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() gotOffsets, gotFt := collectVirtualColumnOffsetsAndTypes(ctx, tt.cols) require.Equal(t, gotOffsets, tt.offsets) require.Equal(t, len(gotFt), len(tt.fieldTp)) diff --git a/pkg/ddl/index_cop.go b/pkg/ddl/index_cop.go index 25ce530bff4d8..0293853b14a87 100644 --- a/pkg/ddl/index_cop.go +++ b/pkg/ddl/index_cop.go @@ -25,7 +25,7 @@ import ( distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/table" diff --git a/pkg/ddl/modify_column.go b/pkg/ddl/modify_column.go index feba8ce322a3d..36cbd022a7192 100644 --- a/pkg/ddl/modify_column.go +++ b/pkg/ddl/modify_column.go @@ -27,7 +27,7 @@ import ( sess "github.com/pingcap/tidb/pkg/ddl/session" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta" diff --git a/pkg/ddl/reorg.go b/pkg/ddl/reorg.go index affad43013ccd..2c392c806df98 100644 --- a/pkg/ddl/reorg.go +++ b/pkg/ddl/reorg.go @@ -33,8 +33,8 @@ import ( "github.com/pingcap/tidb/pkg/distsql" distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta" "github.com/pingcap/tidb/pkg/meta/autoid" @@ -47,8 +47,8 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/statistics" "github.com/pingcap/tidb/pkg/table" - tbctx "github.com/pingcap/tidb/pkg/table/context" "github.com/pingcap/tidb/pkg/table/tables" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/tablecodec" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" @@ -93,22 +93,22 @@ type reorgFnResult struct { err error } -func newReorgExprCtx() *contextstatic.StaticExprContext { - evalCtx := contextstatic.NewStaticEvalContext( - contextstatic.WithSQLMode(mysql.ModeNone), - contextstatic.WithTypeFlags(types.DefaultStmtFlags), - contextstatic.WithErrLevelMap(stmtctx.DefaultStmtErrLevels), +func newReorgExprCtx() *exprstatic.ExprContext { + evalCtx := exprstatic.NewEvalContext( + exprstatic.WithSQLMode(mysql.ModeNone), + exprstatic.WithTypeFlags(types.DefaultStmtFlags), + exprstatic.WithErrLevelMap(stmtctx.DefaultStmtErrLevels), ) planCacheTracker := contextutil.NewPlanCacheTracker(contextutil.IgnoreWarn) - return contextstatic.NewStaticExprContext( - contextstatic.WithEvalCtx(evalCtx), - contextstatic.WithPlanCacheTracker(&planCacheTracker), + return exprstatic.NewExprContext( + exprstatic.WithEvalCtx(evalCtx), + exprstatic.WithPlanCacheTracker(&planCacheTracker), ) } -func newReorgExprCtxWithReorgMeta(reorgMeta *model.DDLReorgMeta, warnHandler contextutil.WarnHandler) (*contextstatic.StaticExprContext, error) { +func newReorgExprCtxWithReorgMeta(reorgMeta *model.DDLReorgMeta, warnHandler contextutil.WarnHandler) (*exprstatic.ExprContext, error) { intest.AssertNotNil(reorgMeta) intest.AssertNotNil(warnHandler) loc, err := reorgTimeZoneWithTzLoc(reorgMeta.Location) @@ -118,20 +118,20 @@ func newReorgExprCtxWithReorgMeta(reorgMeta *model.DDLReorgMeta, warnHandler con ctx := newReorgExprCtx() evalCtx := ctx.GetStaticEvalCtx().Apply( - contextstatic.WithSQLMode(reorgMeta.SQLMode), - contextstatic.WithLocation(loc), - contextstatic.WithTypeFlags(reorgTypeFlagsWithSQLMode(reorgMeta.SQLMode)), - contextstatic.WithErrLevelMap(reorgErrLevelsWithSQLMode(reorgMeta.SQLMode)), - contextstatic.WithWarnHandler(warnHandler), + exprstatic.WithSQLMode(reorgMeta.SQLMode), + exprstatic.WithLocation(loc), + exprstatic.WithTypeFlags(reorgTypeFlagsWithSQLMode(reorgMeta.SQLMode)), + exprstatic.WithErrLevelMap(reorgErrLevelsWithSQLMode(reorgMeta.SQLMode)), + exprstatic.WithWarnHandler(warnHandler), ) - return ctx.Apply(contextstatic.WithEvalCtx(evalCtx)), nil + return ctx.Apply(exprstatic.WithEvalCtx(evalCtx)), nil } // reorgTableMutateContext implements table.MutateContext for reorganization. type reorgTableMutateContext struct { exprCtx exprctx.ExprContext - encodingConfig tbctx.RowEncodingConfig - mutateBuffers *tbctx.MutateBuffers + encodingConfig tblctx.RowEncodingConfig + mutateBuffers *tblctx.MutateBuffers shardID *variable.RowIDShardGenerator reservedRowIDAlloc stmtctx.ReservedRowIDAlloc } @@ -173,12 +173,12 @@ func (*reorgTableMutateContext) EnableMutationChecker() bool { } // GetRowEncodingConfig implements table.MutateContext.GetRowEncodingConfig. -func (ctx *reorgTableMutateContext) GetRowEncodingConfig() tbctx.RowEncodingConfig { +func (ctx *reorgTableMutateContext) GetRowEncodingConfig() tblctx.RowEncodingConfig { return ctx.encodingConfig } // GetMutateBuffers implements table.MutateContext.GetMutateBuffers. -func (ctx *reorgTableMutateContext) GetMutateBuffers() *tbctx.MutateBuffers { +func (ctx *reorgTableMutateContext) GetMutateBuffers() *tblctx.MutateBuffers { return ctx.mutateBuffers } @@ -193,7 +193,7 @@ func (ctx *reorgTableMutateContext) GetReservedRowIDAlloc() (*stmtctx.ReservedRo } // GetBinlogSupport implements table.MutateContext.GetBinlogSupport. -func (*reorgTableMutateContext) GetBinlogSupport() (tbctx.BinlogSupport, bool) { +func (*reorgTableMutateContext) GetBinlogSupport() (tblctx.BinlogSupport, bool) { // We can just return `(nil, false)` because: // - Only `index.Create` and `index.Delete` are invoked in reorganization which does not use this method. // - Data change in DDL reorganization should not write binlog. @@ -201,7 +201,7 @@ func (*reorgTableMutateContext) GetBinlogSupport() (tbctx.BinlogSupport, bool) { } // GetStatisticsSupport implements table.MutateContext.GetStatisticsSupport. -func (*reorgTableMutateContext) GetStatisticsSupport() (tbctx.StatisticsSupport, bool) { +func (*reorgTableMutateContext) GetStatisticsSupport() (tblctx.StatisticsSupport, bool) { // We can just return `(nil, false)` because: // - Only `index.Create` and `index.Delete` are invoked in reorganization which does not use this method. // - DDL reorg do need to collect statistics in this way. @@ -209,7 +209,7 @@ func (*reorgTableMutateContext) GetStatisticsSupport() (tbctx.StatisticsSupport, } // GetCachedTableSupport implements table.MutateContext.GetCachedTableSupport. -func (*reorgTableMutateContext) GetCachedTableSupport() (tbctx.CachedTableSupport, bool) { +func (*reorgTableMutateContext) GetCachedTableSupport() (tblctx.CachedTableSupport, bool) { // We can just return `(nil, false)` because: // - Only `index.Create` and `index.Delete` are invoked in reorganization which does not use this method. // - It is not allowed to execute DDL on a cached table. @@ -217,7 +217,7 @@ func (*reorgTableMutateContext) GetCachedTableSupport() (tbctx.CachedTableSuppor } // GetTemporaryTableSupport implements table.MutateContext.GetTemporaryTableSupport. -func (*reorgTableMutateContext) GetTemporaryTableSupport() (tbctx.TemporaryTableSupport, bool) { +func (*reorgTableMutateContext) GetTemporaryTableSupport() (tblctx.TemporaryTableSupport, bool) { // We can just return `(nil, false)` because: // - Only `index.Create` and `index.Delete` are invoked in reorganization which does not use this method. // - Temporary tables do not have any data in TiKV. @@ -225,7 +225,7 @@ func (*reorgTableMutateContext) GetTemporaryTableSupport() (tbctx.TemporaryTable } // GetExchangePartitionDMLSupport implements table.MutateContext.GetExchangePartitionDMLSupport. -func (*reorgTableMutateContext) GetExchangePartitionDMLSupport() (tbctx.ExchangePartitionDMLSupport, bool) { +func (*reorgTableMutateContext) GetExchangePartitionDMLSupport() (tblctx.ExchangePartitionDMLSupport, bool) { // We can just return `(nil, false)` because: // - Only `index.Create` and `index.Delete` are invoked in reorganization which does not use this method. return nil, false @@ -237,7 +237,7 @@ func newReorgTableMutateContext(exprCtx exprctx.ExprContext) table.MutateContext Enable: variable.GetDDLReorgRowFormat() != variable.DefTiDBRowFormatV1, } - encodingConfig := tbctx.RowEncodingConfig{ + encodingConfig := tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: rowEncoder.Enable, RowEncoder: rowEncoder, } @@ -245,7 +245,7 @@ func newReorgTableMutateContext(exprCtx exprctx.ExprContext) table.MutateContext return &reorgTableMutateContext{ exprCtx: exprCtx, encodingConfig: encodingConfig, - mutateBuffers: tbctx.NewMutateBuffers(&variable.WriteStmtBufs{}), + mutateBuffers: tblctx.NewMutateBuffers(&variable.WriteStmtBufs{}), // Though currently, `RowIDShardGenerator` is not required in DDL reorg, // we still provide a valid one to keep the context complete and to avoid panic if it is used in the future. shardID: variable.NewRowIDShardGenerator( diff --git a/pkg/executor/BUILD.bazel b/pkg/executor/BUILD.bazel index 72840d7b5ccd6..caa0920ceefd1 100644 --- a/pkg/executor/BUILD.bazel +++ b/pkg/executor/BUILD.bazel @@ -125,8 +125,8 @@ go_library( "//pkg/executor/unionexec", "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/context", - "//pkg/expression/contextsession", + "//pkg/expression/exprctx", + "//pkg/expression/sessionexpr", "//pkg/extension", "//pkg/infoschema", "//pkg/infoschema/context", @@ -152,12 +152,12 @@ go_library( "//pkg/parser/types", "//pkg/planner", "//pkg/planner/cardinality", - "//pkg/planner/context", "//pkg/planner/core", "//pkg/planner/core/base", "//pkg/planner/core/operator/logicalop", "//pkg/planner/core/resolve", "//pkg/planner/indexadvisor", + "//pkg/planner/planctx", "//pkg/planner/util", "//pkg/planner/util/coreusage", "//pkg/planner/util/fixcontrol", @@ -399,7 +399,7 @@ go_test( "//pkg/executor/sortexec", "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/extension", "//pkg/infoschema", "//pkg/kv", diff --git a/pkg/executor/aggfuncs/BUILD.bazel b/pkg/executor/aggfuncs/BUILD.bazel index c3c7a70767b84..e2733d08c409e 100644 --- a/pkg/executor/aggfuncs/BUILD.bazel +++ b/pkg/executor/aggfuncs/BUILD.bazel @@ -35,7 +35,7 @@ go_library( deps = [ "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/parser/ast", "//pkg/parser/charset", "//pkg/parser/mysql", diff --git a/pkg/executor/aggfuncs/aggfuncs.go b/pkg/executor/aggfuncs/aggfuncs.go index bf3bbfc8e56fd..0f46bcf1dbf5e 100644 --- a/pkg/executor/aggfuncs/aggfuncs.go +++ b/pkg/executor/aggfuncs/aggfuncs.go @@ -18,7 +18,7 @@ import ( "unsafe" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" ) diff --git a/pkg/executor/aggfuncs/builder.go b/pkg/executor/aggfuncs/builder.go index 901ad0e469e74..033343a8512cc 100644 --- a/pkg/executor/aggfuncs/builder.go +++ b/pkg/executor/aggfuncs/builder.go @@ -19,7 +19,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/expression/aggregation" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" diff --git a/pkg/executor/detach.go b/pkg/executor/detach.go index 727503c60e24a..2f64ab934dba6 100644 --- a/pkg/executor/detach.go +++ b/pkg/executor/detach.go @@ -17,7 +17,7 @@ package executor import ( "github.com/pingcap/tidb/pkg/executor/internal/exec" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" ) // Detach detaches the current executor from the session context. After detaching, the session context @@ -51,7 +51,7 @@ func Detach(originalExecutor exec.Executor) (exec.Executor, bool) { func (treCtx tableReaderExecutorContext) Detach() tableReaderExecutorContext { newCtx := treCtx - if ctx, ok := treCtx.ectx.(*contextsession.SessionExprContext); ok { + if ctx, ok := treCtx.ectx.(*sessionexpr.ExprContext); ok { staticExprCtx := ctx.IntoStatic() newCtx.dctx = newCtx.dctx.Detach() @@ -67,7 +67,7 @@ func (treCtx tableReaderExecutorContext) Detach() tableReaderExecutorContext { func (ireCtx indexReaderExecutorContext) Detach() indexReaderExecutorContext { newCtx := ireCtx - if ctx, ok := ireCtx.ectx.(*contextsession.SessionExprContext); ok { + if ctx, ok := ireCtx.ectx.(*sessionexpr.ExprContext); ok { staticExprCtx := ctx.IntoStatic() newCtx.dctx = newCtx.dctx.Detach() @@ -89,7 +89,7 @@ func (iluCtx indexLookUpExecutorContext) Detach() indexLookUpExecutorContext { func (pCtx projectionExecutorContext) Detach() projectionExecutorContext { newCtx := pCtx - if ctx, ok := pCtx.evalCtx.(*contextsession.SessionEvalContext); ok { + if ctx, ok := pCtx.evalCtx.(*sessionexpr.EvalContext); ok { newCtx.evalCtx = ctx.IntoStatic() } @@ -98,7 +98,7 @@ func (pCtx projectionExecutorContext) Detach() projectionExecutorContext { func (sCtx selectionExecutorContext) Detach() selectionExecutorContext { newCtx := sCtx - if ctx, ok := sCtx.evalCtx.(*contextsession.SessionEvalContext); ok { + if ctx, ok := sCtx.evalCtx.(*sessionexpr.EvalContext); ok { newCtx.evalCtx = ctx.IntoStatic() } diff --git a/pkg/executor/detach_test.go b/pkg/executor/detach_test.go index 7f46f5479e7f8..5a9e87aa81cae 100644 --- a/pkg/executor/detach_test.go +++ b/pkg/executor/detach_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/pingcap/tidb/pkg/executor/internal/exec" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/util/mock" "github.com/stretchr/testify/require" ) @@ -35,7 +35,7 @@ func TestDetachExecutor(t *testing.T) { // call `Detach` on a TableReaderExecutor will succeed oldExec := &TableReaderExecutor{ tableReaderExecutorContext: tableReaderExecutorContext{ - ectx: contextstatic.NewStaticExprContext(), + ectx: exprstatic.NewExprContext(), }, } newExec, ok := Detach(oldExec) @@ -46,7 +46,7 @@ func TestDetachExecutor(t *testing.T) { sess := mock.NewContext() oldExec = &TableReaderExecutor{ tableReaderExecutorContext: tableReaderExecutorContext{ - ectx: contextstatic.NewStaticExprContext(), + ectx: exprstatic.NewExprContext(), }, BaseExecutorV2: exec.NewBaseExecutorV2(sess.GetSessionVars(), nil, 0, &mockSimpleExecutor{}), } @@ -56,12 +56,12 @@ func TestDetachExecutor(t *testing.T) { // call `Detach` on a `TableReaderExecutor` with another `TableReaderExecutor` as child will succeed child := &TableReaderExecutor{ tableReaderExecutorContext: tableReaderExecutorContext{ - ectx: contextstatic.NewStaticExprContext(), + ectx: exprstatic.NewExprContext(), }, } parent := &TableReaderExecutor{ tableReaderExecutorContext: tableReaderExecutorContext{ - ectx: contextstatic.NewStaticExprContext(), + ectx: exprstatic.NewExprContext(), }, BaseExecutorV2: exec.NewBaseExecutorV2(sess.GetSessionVars(), nil, 0, child), } diff --git a/pkg/executor/distsql.go b/pkg/executor/distsql.go index 56f26628db7b6..f3aaf6f306fba 100644 --- a/pkg/executor/distsql.go +++ b/pkg/executor/distsql.go @@ -39,9 +39,9 @@ import ( "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" plannerutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/table" diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 4334422b26bf9..636ca91a6a07c 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -53,11 +53,11 @@ import ( "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/core/operator/logicalop" "github.com/pingcap/tidb/pkg/planner/indexadvisor" + "github.com/pingcap/tidb/pkg/planner/planctx" plannerutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/planner/util/fixcontrol" "github.com/pingcap/tidb/pkg/privilege" diff --git a/pkg/executor/importer/BUILD.bazel b/pkg/executor/importer/BUILD.bazel index 4fb84570ca2e3..d317c1176f0ff 100644 --- a/pkg/executor/importer/BUILD.bazel +++ b/pkg/executor/importer/BUILD.bazel @@ -44,8 +44,8 @@ go_library( "//pkg/parser/format", "//pkg/parser/mysql", "//pkg/parser/terror", - "//pkg/planner/context", "//pkg/planner/core", + "//pkg/planner/planctx", "//pkg/planner/util", "//pkg/sessionctx", "//pkg/sessionctx/variable", diff --git a/pkg/executor/importer/import.go b/pkg/executor/importer/import.go index 3a98aeef5cc98..c4556b39f4790 100644 --- a/pkg/executor/importer/import.go +++ b/pkg/executor/importer/import.go @@ -45,8 +45,8 @@ import ( pformat "github.com/pingcap/tidb/pkg/parser/format" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" + "github.com/pingcap/tidb/pkg/planner/planctx" plannerutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" diff --git a/pkg/executor/insert_test.go b/pkg/executor/insert_test.go index 7cafb355a0deb..fe4532456058e 100644 --- a/pkg/executor/insert_test.go +++ b/pkg/executor/insert_test.go @@ -33,8 +33,8 @@ import ( func TestInsertOnDuplicateKeyWithBinlog(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - failpoint.Enable("github.com/pingcap/tidb/pkg/table/contextimpl/forceWriteBinlog", "return") - defer failpoint.Disable("github.com/pingcap/tidb/pkg/table/contextimpl/forceWriteBinlog") + failpoint.Enable("github.com/pingcap/tidb/pkg/table/tblsession/forceWriteBinlog", "return") + defer failpoint.Disable("github.com/pingcap/tidb/pkg/table/tblsession/forceWriteBinlog") testInsertOnDuplicateKey(t, tk) } diff --git a/pkg/executor/internal/builder/BUILD.bazel b/pkg/executor/internal/builder/BUILD.bazel index 071fbc2c3f697..a27321acc7309 100644 --- a/pkg/executor/internal/builder/BUILD.bazel +++ b/pkg/executor/internal/builder/BUILD.bazel @@ -8,8 +8,8 @@ go_library( deps = [ "//pkg/distsql", "//pkg/kv", - "//pkg/planner/context", "//pkg/planner/core/base", + "//pkg/planner/planctx", "//pkg/sessionctx", "//pkg/sessionctx/variable", "//pkg/util/timeutil", diff --git a/pkg/executor/internal/builder/builder_utils.go b/pkg/executor/internal/builder/builder_utils.go index 8178a6b8d67c6..eb7adaa2943a2 100644 --- a/pkg/executor/internal/builder/builder_utils.go +++ b/pkg/executor/internal/builder/builder_utils.go @@ -17,8 +17,8 @@ package builder import ( "github.com/pingcap/tidb/pkg/distsql" "github.com/pingcap/tidb/pkg/kv" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/util/timeutil" diff --git a/pkg/executor/sortexec/BUILD.bazel b/pkg/executor/sortexec/BUILD.bazel index e8c7dbc6a142c..8ef5871d71335 100644 --- a/pkg/executor/sortexec/BUILD.bazel +++ b/pkg/executor/sortexec/BUILD.bazel @@ -73,7 +73,7 @@ go_test( "//pkg/executor/internal/exec", "//pkg/executor/internal/testutil", "//pkg/expression", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/parser/mysql", "//pkg/planner/core", "//pkg/planner/util", diff --git a/pkg/executor/sortexec/sort_spill_test.go b/pkg/executor/sortexec/sort_spill_test.go index b72a777a444d7..a32c183590f5c 100644 --- a/pkg/executor/sortexec/sort_spill_test.go +++ b/pkg/executor/sortexec/sort_spill_test.go @@ -25,7 +25,7 @@ import ( "github.com/pingcap/tidb/pkg/executor/internal/testutil" "github.com/pingcap/tidb/pkg/executor/sortexec" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" plannerutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" @@ -100,7 +100,7 @@ func (r *resultChecker) initRowPtrs() { } func (r *resultChecker) check(resultChunks []*chunk.Chunk, offset int64, count int64) bool { - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() if r.rowPtrs == nil { r.initRowPtrs() diff --git a/pkg/executor/table_reader.go b/pkg/executor/table_reader.go index 349efdb6394c6..2386b8843f74a 100644 --- a/pkg/executor/table_reader.go +++ b/pkg/executor/table_reader.go @@ -32,14 +32,14 @@ import ( "github.com/pingcap/tidb/pkg/executor/internal/exec" internalutil "github.com/pingcap/tidb/pkg/executor/internal/util" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/infoschema" isctx "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/table" diff --git a/pkg/expression/BUILD.bazel b/pkg/expression/BUILD.bazel index 503c4f9839503..f837ef9240d94 100644 --- a/pkg/expression/BUILD.bazel +++ b/pkg/expression/BUILD.bazel @@ -75,8 +75,8 @@ go_library( "//pkg/config", "//pkg/errctx", "//pkg/errno", - "//pkg/expression/context", - "//pkg/expression/contextopt", + "//pkg/expression/exprctx", + "//pkg/expression/expropt", "//pkg/extension", "//pkg/infoschema/context", "//pkg/kv", @@ -209,8 +209,8 @@ go_test( "//pkg/config", "//pkg/errctx", "//pkg/errno", - "//pkg/expression/context", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/exprstatic", "//pkg/kv", "//pkg/meta/model", "//pkg/parser", diff --git a/pkg/expression/aggregation/BUILD.bazel b/pkg/expression/aggregation/BUILD.bazel index d4d35efd5700a..a71c89f11565c 100644 --- a/pkg/expression/aggregation/BUILD.bazel +++ b/pkg/expression/aggregation/BUILD.bazel @@ -34,7 +34,7 @@ go_library( ], deps = [ "//pkg/expression", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/kv", "//pkg/parser/ast", "//pkg/parser/charset", diff --git a/pkg/expression/aggregation/util.go b/pkg/expression/aggregation/util.go index 637967ce5fcb8..fef4575d8bf46 100644 --- a/pkg/expression/aggregation/util.go +++ b/pkg/expression/aggregation/util.go @@ -16,7 +16,7 @@ package aggregation import ( "github.com/pingcap/errors" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/codec" "github.com/pingcap/tidb/pkg/util/mvmap" diff --git a/pkg/expression/builtin.go b/pkg/expression/builtin.go index 3c874b808c66f..4ddba2d8d9654 100644 --- a/pkg/expression/builtin.go +++ b/pkg/expression/builtin.go @@ -33,7 +33,7 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -528,7 +528,7 @@ type vecBuiltinFunc interface { // builtinFunc stands for a particular function signature. type builtinFunc interface { - contextopt.RequireOptionalEvalProps + expropt.RequireOptionalEvalProps vecBuiltinFunc // evalInt evaluates int result of builtinFunc by given row. diff --git a/pkg/expression/builtin_arithmetic_test.go b/pkg/expression/builtin_arithmetic_test.go index a8c541dc912e0..90631286e8bdc 100644 --- a/pkg/expression/builtin_arithmetic_test.go +++ b/pkg/expression/builtin_arithmetic_test.go @@ -19,7 +19,7 @@ import ( "testing" "time" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/testkit/testutil" @@ -30,7 +30,7 @@ import ( ) func TestSetFlenDecimal4RealOrDecimal(t *testing.T) { - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() ret := &types.FieldType{} a := &types.FieldType{} a.SetDecimal(1) diff --git a/pkg/expression/builtin_encryption.go b/pkg/expression/builtin_encryption.go index 2b57e4d85c963..4143092935688 100644 --- a/pkg/expression/builtin_encryption.go +++ b/pkg/expression/builtin_encryption.go @@ -31,8 +31,8 @@ import ( "strings" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/variable" @@ -1031,8 +1031,8 @@ func (c *validatePasswordStrengthFunctionClass) getFunction(ctx BuildContext, ar type builtinValidatePasswordStrengthSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader - contextopt.CurrentUserPropReader + expropt.SessionVarsPropReader + expropt.CurrentUserPropReader } func (b *builtinValidatePasswordStrengthSig) Clone() builtinFunc { @@ -1042,7 +1042,7 @@ func (b *builtinValidatePasswordStrengthSig) Clone() builtinFunc { } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (b *builtinValidatePasswordStrengthSig) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { +func (b *builtinValidatePasswordStrengthSig) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { return b.SessionVarsPropReader.RequiredOptionalEvalProps() | b.CurrentUserPropReader.RequiredOptionalEvalProps() } diff --git a/pkg/expression/builtin_info.go b/pkg/expression/builtin_info.go index 176c342339026..2b7a7ef51d9a7 100644 --- a/pkg/expression/builtin_info.go +++ b/pkg/expression/builtin_info.go @@ -28,7 +28,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/ast" @@ -151,7 +151,7 @@ func (c *foundRowsFunctionClass) getFunction(ctx BuildContext, args []Expression type builtinFoundRowsSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinFoundRowsSig) Clone() builtinFunc { @@ -197,7 +197,7 @@ func (c *currentUserFunctionClass) getFunction(ctx BuildContext, args []Expressi type builtinCurrentUserSig struct { baseBuiltinFunc - contextopt.CurrentUserPropReader + expropt.CurrentUserPropReader } func (b *builtinCurrentUserSig) Clone() builtinFunc { @@ -243,7 +243,7 @@ func (c *currentRoleFunctionClass) getFunction(ctx BuildContext, args []Expressi type builtinCurrentRoleSig struct { baseBuiltinFunc - contextopt.CurrentUserPropReader + expropt.CurrentUserPropReader } func (b *builtinCurrentRoleSig) Clone() builtinFunc { @@ -303,7 +303,7 @@ func (c *currentResourceGroupFunctionClass) getFunction(ctx BuildContext, args [ type builtinCurrentResourceGroupSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinCurrentResourceGroupSig) Clone() builtinFunc { @@ -359,7 +359,7 @@ func (c *userFunctionClass) getFunction(ctx BuildContext, args []Expression) (bu type builtinUserSig struct { baseBuiltinFunc - contextopt.CurrentUserPropReader + expropt.CurrentUserPropReader } func (b *builtinUserSig) Clone() builtinFunc { @@ -405,7 +405,7 @@ func (c *connectionIDFunctionClass) getFunction(ctx BuildContext, args []Express type builtinConnectionIDSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinConnectionIDSig) Clone() builtinFunc { @@ -461,7 +461,7 @@ func (c *lastInsertIDFunctionClass) getFunction(ctx BuildContext, args []Express type builtinLastInsertIDSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinLastInsertIDSig) Clone() builtinFunc { @@ -487,7 +487,7 @@ func (b *builtinLastInsertIDSig) evalInt(ctx EvalContext, row chunk.Row) (res in type builtinLastInsertIDWithIDSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinLastInsertIDWithIDSig) Clone() builtinFunc { @@ -601,7 +601,7 @@ func (c *tidbIsDDLOwnerFunctionClass) getFunction(ctx BuildContext, args []Expre type builtinTiDBIsDDLOwnerSig struct { baseBuiltinFunc - contextopt.DDLOwnerPropReader + expropt.DDLOwnerPropReader } func (b *builtinTiDBIsDDLOwnerSig) Clone() builtinFunc { @@ -879,7 +879,7 @@ func (c *rowCountFunctionClass) getFunction(ctx BuildContext, args []Expression) type builtinRowCountSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinRowCountSig) Clone() builtinFunc { @@ -918,7 +918,7 @@ func (c *tidbMVCCInfoFunctionClass) getFunction(ctx BuildContext, args []Express type builtinTiDBMVCCInfoSig struct { baseBuiltinFunc - contextopt.KVStorePropReader + expropt.KVStorePropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -1004,8 +1004,8 @@ func (c *tidbEncodeRecordKeyClass) getFunction(ctx BuildContext, args []Expressi type builtinTiDBEncodeRecordKeySig struct { baseBuiltinFunc - contextopt.InfoSchemaPropReader - contextopt.SessionVarsPropReader + expropt.InfoSchemaPropReader + expropt.SessionVarsPropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -1070,8 +1070,8 @@ func (c *tidbEncodeIndexKeyClass) getFunction(ctx BuildContext, args []Expressio type builtinTiDBEncodeIndexKeySig struct { baseBuiltinFunc - contextopt.InfoSchemaPropReader - contextopt.SessionVarsPropReader + expropt.InfoSchemaPropReader + expropt.SessionVarsPropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -1140,7 +1140,7 @@ var EncodeIndexKeyFromRow func(ctx EvalContext, is infoschema.MetaOnlyInfoSchema type builtinTiDBDecodeKeySig struct { baseBuiltinFunc - contextopt.InfoSchemaPropReader + expropt.InfoSchemaPropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -1200,8 +1200,8 @@ func (c *tidbDecodeSQLDigestsFunctionClass) getFunction(ctx BuildContext, args [ type builtinTiDBDecodeSQLDigestsSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader - contextopt.SQLExecutorPropReader + expropt.SessionVarsPropReader + expropt.SQLExecutorPropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -1441,8 +1441,8 @@ func (c *nextValFunctionClass) getFunction(ctx BuildContext, args []Expression) type builtinNextValSig struct { baseBuiltinFunc - contextopt.SequenceOperatorPropReader - contextopt.SessionVarsPropReader + expropt.SequenceOperatorPropReader + expropt.SessionVarsPropReader } func (b *builtinNextValSig) RequiredOptionalEvalProps() OptionalEvalPropKeySet { @@ -1508,8 +1508,8 @@ func (c *lastValFunctionClass) getFunction(ctx BuildContext, args []Expression) type builtinLastValSig struct { baseBuiltinFunc - contextopt.SequenceOperatorPropReader - contextopt.SessionVarsPropReader + expropt.SequenceOperatorPropReader + expropt.SessionVarsPropReader } func (b *builtinLastValSig) RequiredOptionalEvalProps() OptionalEvalPropKeySet { @@ -1569,8 +1569,8 @@ func (c *setValFunctionClass) getFunction(ctx BuildContext, args []Expression) ( type builtinSetValSig struct { baseBuiltinFunc - contextopt.SequenceOperatorPropReader - contextopt.SessionVarsPropReader + expropt.SequenceOperatorPropReader + expropt.SessionVarsPropReader } func (b *builtinSetValSig) RequiredOptionalEvalProps() OptionalEvalPropKeySet { diff --git a/pkg/expression/builtin_miscellaneous.go b/pkg/expression/builtin_miscellaneous.go index 859932f3ea8b7..5274c79c904d0 100644 --- a/pkg/expression/builtin_miscellaneous.go +++ b/pkg/expression/builtin_miscellaneous.go @@ -27,7 +27,7 @@ import ( "github.com/google/uuid" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" "github.com/pingcap/tidb/pkg/sessionctx/variable" @@ -124,7 +124,7 @@ func (c *sleepFunctionClass) getFunction(ctx BuildContext, args []Expression) (b type builtinSleepSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSleepSig) Clone() builtinFunc { @@ -190,7 +190,7 @@ func (c *lockFunctionClass) getFunction(ctx BuildContext, args []Expression) (bu type builtinLockSig struct { baseBuiltinFunc - contextopt.AdvisoryLockPropReader + expropt.AdvisoryLockPropReader } func (b *builtinLockSig) Clone() builtinFunc { @@ -284,7 +284,7 @@ func (c *releaseLockFunctionClass) getFunction(ctx BuildContext, args []Expressi type builtinReleaseLockSig struct { baseBuiltinFunc - contextopt.AdvisoryLockPropReader + expropt.AdvisoryLockPropReader } func (b *builtinReleaseLockSig) Clone() builtinFunc { @@ -791,7 +791,7 @@ func (c *isFreeLockFunctionClass) getFunction(ctx BuildContext, args []Expressio type builtinFreeLockSig struct { baseBuiltinFunc - contextopt.AdvisoryLockPropReader + expropt.AdvisoryLockPropReader } func (b *builtinFreeLockSig) Clone() builtinFunc { @@ -1063,7 +1063,7 @@ func (c *isUsedLockFunctionClass) getFunction(ctx BuildContext, args []Expressio type builtinUsedLockSig struct { baseBuiltinFunc - contextopt.AdvisoryLockPropReader + expropt.AdvisoryLockPropReader } func (b *builtinUsedLockSig) Clone() builtinFunc { @@ -1328,7 +1328,7 @@ func (c *releaseAllLocksFunctionClass) getFunction(ctx BuildContext, args []Expr type builtinReleaseAllLocksSig struct { baseBuiltinFunc - contextopt.AdvisoryLockPropReader + expropt.AdvisoryLockPropReader } func (b *builtinReleaseAllLocksSig) Clone() builtinFunc { diff --git a/pkg/expression/builtin_other.go b/pkg/expression/builtin_other.go index 564aa90d0ae90..6a166b3984639 100644 --- a/pkg/expression/builtin_other.go +++ b/pkg/expression/builtin_other.go @@ -20,7 +20,7 @@ import ( "time" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -791,7 +791,7 @@ func (c *setVarFunctionClass) getFunction(ctx BuildContext, args []Expression) ( type builtinSetStringVarSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSetStringVarSig) Clone() builtinFunc { @@ -829,7 +829,7 @@ func (b *builtinSetStringVarSig) evalString(ctx EvalContext, row chunk.Row) (res type builtinSetRealVarSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSetRealVarSig) Clone() builtinFunc { @@ -865,7 +865,7 @@ func (b *builtinSetRealVarSig) evalReal(ctx EvalContext, row chunk.Row) (res flo type builtinSetDecimalVarSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSetDecimalVarSig) Clone() builtinFunc { @@ -900,7 +900,7 @@ func (b *builtinSetDecimalVarSig) evalDecimal(ctx EvalContext, row chunk.Row) (* type builtinSetIntVarSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSetIntVarSig) Clone() builtinFunc { @@ -935,7 +935,7 @@ func (b *builtinSetIntVarSig) evalInt(ctx EvalContext, row chunk.Row) (int64, bo type builtinSetTimeVarSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinSetTimeVarSig) Clone() builtinFunc { @@ -1269,7 +1269,7 @@ func (c *valuesFunctionClass) getFunction(ctx BuildContext, args []Expression) ( type builtinValuesIntSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1319,7 +1319,7 @@ func (b *builtinValuesIntSig) evalInt(ctx EvalContext, _ chunk.Row) (int64, bool type builtinValuesRealSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1359,7 +1359,7 @@ func (b *builtinValuesRealSig) evalReal(ctx EvalContext, _ chunk.Row) (float64, type builtinValuesDecimalSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1396,7 +1396,7 @@ func (b *builtinValuesDecimalSig) evalDecimal(ctx EvalContext, _ chunk.Row) (*ty type builtinValuesStringSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1442,7 +1442,7 @@ func (b *builtinValuesStringSig) evalString(ctx EvalContext, _ chunk.Row) (strin type builtinValuesTimeSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1479,7 +1479,7 @@ func (b *builtinValuesTimeSig) evalTime(ctx EvalContext, _ chunk.Row) (types.Tim type builtinValuesDurationSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1517,7 +1517,7 @@ func (b *builtinValuesDurationSig) evalDuration(ctx EvalContext, _ chunk.Row) (t type builtinValuesJSONSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } @@ -1554,7 +1554,7 @@ func (b *builtinValuesJSONSig) evalJSON(ctx EvalContext, _ chunk.Row) (types.Bin type builtinValuesVectorFloat32Sig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader offset int } diff --git a/pkg/expression/builtin_other_test.go b/pkg/expression/builtin_other_test.go index 4b3528dc01351..78d25212e597a 100644 --- a/pkg/expression/builtin_other_test.go +++ b/pkg/expression/builtin_other_test.go @@ -19,7 +19,7 @@ import ( "testing" "time" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" diff --git a/pkg/expression/builtin_other_vec_test.go b/pkg/expression/builtin_other_vec_test.go index 9e817b0e028b6..a6506e68b0bb1 100644 --- a/pkg/expression/builtin_other_vec_test.go +++ b/pkg/expression/builtin_other_vec_test.go @@ -19,7 +19,7 @@ import ( "math/rand" "testing" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" diff --git a/pkg/expression/builtin_time.go b/pkg/expression/builtin_time.go index d044b554fa2b7..fc4a4eab331e1 100644 --- a/pkg/expression/builtin_time.go +++ b/pkg/expression/builtin_time.go @@ -31,7 +31,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/pkg/config" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -6655,8 +6655,8 @@ func (c *tidbBoundedStalenessFunctionClass) getFunction(ctx BuildContext, args [ type builtinTiDBBoundedStalenessSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader - contextopt.KVStorePropReader + expropt.SessionVarsPropReader + expropt.KVStorePropReader } // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. @@ -6807,7 +6807,7 @@ func (c *tidbCurrentTsoFunctionClass) getFunction(ctx BuildContext, args []Expre type builtinTiDBCurrentTsoSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader } func (b *builtinTiDBCurrentTsoSig) Clone() builtinFunc { diff --git a/pkg/expression/column.go b/pkg/expression/column.go index b9d883bc61388..399ecac8746b0 100644 --- a/pkg/expression/column.go +++ b/pkg/expression/column.go @@ -22,7 +22,7 @@ import ( "unsafe" "github.com/pingcap/errors" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/charset" diff --git a/pkg/expression/constant_propagation.go b/pkg/expression/constant_propagation.go index 2db05ec13ad15..6a395166d059a 100644 --- a/pkg/expression/constant_propagation.go +++ b/pkg/expression/constant_propagation.go @@ -15,7 +15,7 @@ package expression import ( - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" diff --git a/pkg/expression/constant_test.go b/pkg/expression/constant_test.go index b338d6238c1a2..890f98827a3d2 100644 --- a/pkg/expression/constant_test.go +++ b/pkg/expression/constant_test.go @@ -22,7 +22,7 @@ import ( "time" "github.com/pingcap/errors" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/planner/cascades/base" diff --git a/pkg/expression/context.go b/pkg/expression/context.go index 862d43469dcf8..8a7c0dc5f2ea7 100644 --- a/pkg/expression/context.go +++ b/pkg/expression/context.go @@ -18,7 +18,7 @@ import ( "time" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" contextutil "github.com/pingcap/tidb/pkg/util/context" @@ -26,28 +26,28 @@ import ( ) // ParamValues is used to store the values of params in context -type ParamValues = context.ParamValues +type ParamValues = exprctx.ParamValues // EvalContext is used to evaluate an expression -type EvalContext = context.EvalContext +type EvalContext = exprctx.EvalContext // BuildContext is used to build an expression -type BuildContext = context.BuildContext +type BuildContext = exprctx.BuildContext // AggFuncBuildContext is used to build an aggregation expression -type AggFuncBuildContext = context.ExprContext +type AggFuncBuildContext = exprctx.ExprContext // OptionalEvalPropKey is an alias of context.OptionalEvalPropKey -type OptionalEvalPropKey = context.OptionalEvalPropKey +type OptionalEvalPropKey = exprctx.OptionalEvalPropKey // OptionalEvalPropProvider is an alias of context.OptionalEvalPropProvider -type OptionalEvalPropProvider = context.OptionalEvalPropProvider +type OptionalEvalPropProvider = exprctx.OptionalEvalPropProvider // OptionalEvalPropKeySet is an alias of context.OptionalEvalPropKeySet -type OptionalEvalPropKeySet = context.OptionalEvalPropKeySet +type OptionalEvalPropKeySet = exprctx.OptionalEvalPropKeySet // OptionalEvalPropDesc is an alias of context.OptionalEvalPropDesc -type OptionalEvalPropDesc = context.OptionalEvalPropDesc +type OptionalEvalPropDesc = exprctx.OptionalEvalPropDesc func sqlMode(ctx EvalContext) mysql.SQLMode { return ctx.SQLMode() diff --git a/pkg/expression/evaluator.go b/pkg/expression/evaluator.go index 62bcb634e7913..a82bfb14f5a3f 100644 --- a/pkg/expression/evaluator.go +++ b/pkg/expression/evaluator.go @@ -17,7 +17,7 @@ package expression import ( "sync/atomic" - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/disjointset" "github.com/pingcap/tidb/pkg/util/intest" @@ -173,8 +173,8 @@ func (e *defaultEvaluator) run(ctx EvalContext, vecEnabled bool, input, output * } // RequiredOptionalEvalProps exposes all optional evaluation properties that this evaluator requires. -func (e *defaultEvaluator) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - props := context.OptionalEvalPropKeySet(0) +func (e *defaultEvaluator) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + props := exprctx.OptionalEvalPropKeySet(0) for _, expr := range e.exprs { props = props | GetOptionalEvalPropsForExpr(expr) } @@ -183,7 +183,7 @@ func (e *defaultEvaluator) RequiredOptionalEvalProps() context.OptionalEvalPropK } // GetOptionalEvalPropsForExpr gets all optional evaluation properties that this expression requires. -func GetOptionalEvalPropsForExpr(expr Expression) context.OptionalEvalPropKeySet { +func GetOptionalEvalPropsForExpr(expr Expression) exprctx.OptionalEvalPropKeySet { switch e := expr.(type) { case *ScalarFunction: props := e.Function.RequiredOptionalEvalProps() @@ -257,7 +257,7 @@ func (e *EvaluatorSuite) Run(ctx EvalContext, vecEnabled bool, input, output *ch } // RequiredOptionalEvalProps exposes all optional evaluation properties that this evaluator requires. -func (e *EvaluatorSuite) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { +func (e *EvaluatorSuite) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { if e.defaultEvaluator != nil { return e.defaultEvaluator.RequiredOptionalEvalProps() } diff --git a/pkg/expression/evaluator_test.go b/pkg/expression/evaluator_test.go index 00c47c13b1d80..0d7f79d9ca365 100644 --- a/pkg/expression/evaluator_test.go +++ b/pkg/expression/evaluator_test.go @@ -20,7 +20,7 @@ import ( "time" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/model" @@ -648,16 +648,16 @@ func TestOptionalProp(t *testing.T) { RetType: f2.getRetTp(), } - require.Equal(t, context.OptionalEvalPropKeySet(0), f.RequiredOptionalEvalProps()) - require.Equal(t, context.OptPropCurrentUser.AsPropKeySet()|context.OptPropDDLOwnerInfo.AsPropKeySet(), + require.Equal(t, exprctx.OptionalEvalPropKeySet(0), f.RequiredOptionalEvalProps()) + require.Equal(t, exprctx.OptPropCurrentUser.AsPropKeySet()|exprctx.OptPropDDLOwnerInfo.AsPropKeySet(), GetOptionalEvalPropsForExpr(fe)) - require.Equal(t, context.OptPropCurrentUser.AsPropKeySet()|context.OptPropDDLOwnerInfo.AsPropKeySet()| - context.OptPropAdvisoryLock.AsPropKeySet(), + require.Equal(t, exprctx.OptPropCurrentUser.AsPropKeySet()|exprctx.OptPropDDLOwnerInfo.AsPropKeySet()| + exprctx.OptPropAdvisoryLock.AsPropKeySet(), GetOptionalEvalPropsForExpr(fe)|GetOptionalEvalPropsForExpr(fe2)) evalSuit := NewEvaluatorSuite([]Expression{fe, fe2}, false) - require.Equal(t, context.OptPropCurrentUser.AsPropKeySet()|context.OptPropDDLOwnerInfo.AsPropKeySet()| - context.OptPropAdvisoryLock.AsPropKeySet(), evalSuit.RequiredOptionalEvalProps()) + require.Equal(t, exprctx.OptPropCurrentUser.AsPropKeySet()|exprctx.OptPropDDLOwnerInfo.AsPropKeySet()| + exprctx.OptPropAdvisoryLock.AsPropKeySet(), evalSuit.RequiredOptionalEvalProps()) } func TestMergeInputIdxToOutputIdxes(t *testing.T) { diff --git a/pkg/expression/context/BUILD.bazel b/pkg/expression/exprctx/BUILD.bazel similarity index 80% rename from pkg/expression/context/BUILD.bazel rename to pkg/expression/exprctx/BUILD.bazel index 3ddbfcb176cff..29691d44bfd7c 100644 --- a/pkg/expression/context/BUILD.bazel +++ b/pkg/expression/exprctx/BUILD.bazel @@ -1,13 +1,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "context", + name = "exprctx", srcs = [ "context.go", "optional.go", "param.go", ], - importpath = "github.com/pingcap/tidb/pkg/expression/context", + importpath = "github.com/pingcap/tidb/pkg/expression/exprctx", visibility = ["//visibility:public"], deps = [ "//pkg/errctx", @@ -22,18 +22,18 @@ go_library( ) go_test( - name = "context_test", + name = "exprctx_test", timeout = "short", srcs = [ "context_override_test.go", "optional_test.go", ], - embed = [":context"], + embed = [":exprctx"], flaky = True, shard_count = 4, deps = [ "//pkg/errctx", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/types", "@com_github_stretchr_testify//require", ], diff --git a/pkg/expression/context/context.go b/pkg/expression/exprctx/context.go similarity index 99% rename from pkg/expression/context/context.go rename to pkg/expression/exprctx/context.go index 9ef01b6f4a406..1f3bf38c9d3bb 100644 --- a/pkg/expression/context/context.go +++ b/pkg/expression/exprctx/context.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package exprctx import ( "sync/atomic" diff --git a/pkg/expression/context/context_override_test.go b/pkg/expression/exprctx/context_override_test.go similarity index 80% rename from pkg/expression/context/context_override_test.go rename to pkg/expression/exprctx/context_override_test.go index dc608c08a0eb0..ab50918f20322 100644 --- a/pkg/expression/context/context_override_test.go +++ b/pkg/expression/exprctx/context_override_test.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context_test +package exprctx_test import ( "testing" "time" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/types" "github.com/stretchr/testify/require" ) @@ -47,20 +47,20 @@ func TestCtxWithHandleTruncateErrLevel(t *testing.T) { require.FailNow(t, "unexpected level") } - evalCtx := contextstatic.NewStaticEvalContext( - contextstatic.WithTypeFlags(originalFlags), - contextstatic.WithLocation(originalLoc), - contextstatic.WithErrLevelMap(errctx.LevelMap{errctx.ErrGroupTruncate: level}), + evalCtx := exprstatic.NewEvalContext( + exprstatic.WithTypeFlags(originalFlags), + exprstatic.WithLocation(originalLoc), + exprstatic.WithErrLevelMap(errctx.LevelMap{errctx.ErrGroupTruncate: level}), ) tc, ec := evalCtx.TypeCtx(), evalCtx.ErrCtx() - ctx := contextstatic.NewStaticExprContext( - contextstatic.WithEvalCtx(evalCtx), - contextstatic.WithConnectionID(1234), + ctx := exprstatic.NewExprContext( + exprstatic.WithEvalCtx(evalCtx), + exprstatic.WithConnectionID(1234), ) // override should take effect - newCtx := context.CtxWithHandleTruncateErrLevel(ctx, level) + newCtx := exprctx.CtxWithHandleTruncateErrLevel(ctx, level) newEvalCtx := newCtx.GetEvalCtx() newTypeCtx, newErrCtx := newEvalCtx.TypeCtx(), newEvalCtx.ErrCtx() require.Equal(t, expectedFlags, newTypeCtx.Flags()) @@ -79,7 +79,7 @@ func TestCtxWithHandleTruncateErrLevel(t *testing.T) { require.Equal(t, uint64(1234), ctx.ConnectionID()) // not create new ctx case - newCtx2 := context.CtxWithHandleTruncateErrLevel(newCtx, level) + newCtx2 := exprctx.CtxWithHandleTruncateErrLevel(newCtx, level) require.Same(t, newCtx, newCtx2) } } diff --git a/pkg/expression/context/optional.go b/pkg/expression/exprctx/optional.go similarity index 99% rename from pkg/expression/context/optional.go rename to pkg/expression/exprctx/optional.go index f7e08dc84cca8..c7e443ae2d90b 100644 --- a/pkg/expression/context/optional.go +++ b/pkg/expression/exprctx/optional.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package exprctx import ( "fmt" diff --git a/pkg/expression/context/optional_test.go b/pkg/expression/exprctx/optional_test.go similarity index 99% rename from pkg/expression/context/optional_test.go rename to pkg/expression/exprctx/optional_test.go index 770168635b9df..8454a44997865 100644 --- a/pkg/expression/context/optional_test.go +++ b/pkg/expression/exprctx/optional_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package exprctx import ( "math" diff --git a/pkg/expression/context/param.go b/pkg/expression/exprctx/param.go similarity index 98% rename from pkg/expression/context/param.go rename to pkg/expression/exprctx/param.go index b26a7c4172418..24e119e71e885 100644 --- a/pkg/expression/context/param.go +++ b/pkg/expression/exprctx/param.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package exprctx import ( "github.com/pingcap/errors" diff --git a/pkg/expression/expression.go b/pkg/expression/expression.go index 799dd58da850c..59827f3a7a57e 100644 --- a/pkg/expression/expression.go +++ b/pkg/expression/expression.go @@ -20,7 +20,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" pmodel "github.com/pingcap/tidb/pkg/parser/model" diff --git a/pkg/expression/expression_test.go b/pkg/expression/expression_test.go index 0f09e7ca2b298..914c61639dd24 100644 --- a/pkg/expression/expression_test.go +++ b/pkg/expression/expression_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" pmodel "github.com/pingcap/tidb/pkg/parser/model" @@ -135,7 +135,7 @@ func TestIsBinaryLiteral(t *testing.T) { func TestConstLevel(t *testing.T) { ctxConst := NewZero() ctxConst.DeferredExpr = newFunctionWithMockCtx(ast.UnixTimestamp) - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() for _, c := range []struct { exp Expression level ConstLevel diff --git a/pkg/expression/contextopt/BUILD.bazel b/pkg/expression/expropt/BUILD.bazel similarity index 81% rename from pkg/expression/contextopt/BUILD.bazel rename to pkg/expression/expropt/BUILD.bazel index ac7a6457a01c1..c301cf1ea989b 100644 --- a/pkg/expression/contextopt/BUILD.bazel +++ b/pkg/expression/expropt/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "contextopt", + name = "expropt", srcs = [ "advisory_lock.go", "current_user.go", @@ -13,10 +13,10 @@ go_library( "sessionvars.go", "sqlexec.go", ], - importpath = "github.com/pingcap/tidb/pkg/expression/contextopt", + importpath = "github.com/pingcap/tidb/pkg/expression/expropt", visibility = ["//visibility:public"], deps = [ - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema/context", "//pkg/kv", "//pkg/parser/auth", @@ -30,13 +30,13 @@ go_library( ) go_test( - name = "contextopt_test", + name = "expropt_test", timeout = "short", srcs = ["optional_test.go"], - embed = [":contextopt"], + embed = [":expropt"], flaky = True, deps = [ - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema/context", "//pkg/kv", "//pkg/parser/auth", diff --git a/pkg/expression/contextopt/advisory_lock.go b/pkg/expression/expropt/advisory_lock.go similarity index 79% rename from pkg/expression/contextopt/advisory_lock.go rename to pkg/expression/expropt/advisory_lock.go index ee0c4a295c2ce..55bb4585b0932 100644 --- a/pkg/expression/contextopt/advisory_lock.go +++ b/pkg/expression/expropt/advisory_lock.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/util/intest" ) @@ -31,7 +31,7 @@ type AdvisoryLockContext interface { ReleaseAllAdvisoryLocks() int } -var _ context.OptionalEvalPropProvider = CurrentUserPropProvider(nil) +var _ exprctx.OptionalEvalPropProvider = CurrentUserPropProvider(nil) var _ RequireOptionalEvalProps = CurrentUserPropReader{} // AdvisoryLockPropProvider is a provider to provide AdvisoryLockContext. @@ -48,19 +48,19 @@ func NewAdvisoryLockPropProvider(ctx AdvisoryLockContext) *AdvisoryLockPropProvi } // Desc returns the description for the property key. -func (p *AdvisoryLockPropProvider) Desc() *context.OptionalEvalPropDesc { - return context.OptPropAdvisoryLock.Desc() +func (p *AdvisoryLockPropProvider) Desc() *exprctx.OptionalEvalPropDesc { + return exprctx.OptPropAdvisoryLock.Desc() } // AdvisoryLockPropReader is used by expression to operate advisory lock type AdvisoryLockPropReader struct{} // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (r AdvisoryLockPropReader) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - return context.OptPropAdvisoryLock.AsPropKeySet() +func (r AdvisoryLockPropReader) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + return exprctx.OptPropAdvisoryLock.AsPropKeySet() } // AdvisoryLockCtx returns the AdvisoryLockContext from the context -func (r AdvisoryLockPropReader) AdvisoryLockCtx(ctx context.EvalContext) (AdvisoryLockContext, error) { - return getPropProvider[*AdvisoryLockPropProvider](ctx, context.OptPropAdvisoryLock) +func (r AdvisoryLockPropReader) AdvisoryLockCtx(ctx exprctx.EvalContext) (AdvisoryLockContext, error) { + return getPropProvider[*AdvisoryLockPropProvider](ctx, exprctx.OptPropAdvisoryLock) } diff --git a/pkg/expression/contextopt/current_user.go b/pkg/expression/expropt/current_user.go similarity index 70% rename from pkg/expression/contextopt/current_user.go rename to pkg/expression/expropt/current_user.go index ecefc2b47d750..7f4c684279fb8 100644 --- a/pkg/expression/contextopt/current_user.go +++ b/pkg/expression/expropt/current_user.go @@ -12,34 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/auth" ) -var _ context.OptionalEvalPropProvider = CurrentUserPropProvider(nil) +var _ exprctx.OptionalEvalPropProvider = CurrentUserPropProvider(nil) var _ RequireOptionalEvalProps = CurrentUserPropReader{} // CurrentUserPropProvider is a provider to get the current user type CurrentUserPropProvider func() (*auth.UserIdentity, []*auth.RoleIdentity) // Desc returns the description for the property key. -func (p CurrentUserPropProvider) Desc() *context.OptionalEvalPropDesc { - return context.OptPropCurrentUser.Desc() +func (p CurrentUserPropProvider) Desc() *exprctx.OptionalEvalPropDesc { + return exprctx.OptPropCurrentUser.Desc() } // CurrentUserPropReader is used by expression to read property context.OptPropCurrentUser type CurrentUserPropReader struct{} // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (r CurrentUserPropReader) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - return context.OptPropCurrentUser.AsPropKeySet() +func (r CurrentUserPropReader) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + return exprctx.OptPropCurrentUser.AsPropKeySet() } // CurrentUser returns the current user -func (r CurrentUserPropReader) CurrentUser(ctx context.EvalContext) (*auth.UserIdentity, error) { +func (r CurrentUserPropReader) CurrentUser(ctx exprctx.EvalContext) (*auth.UserIdentity, error) { p, err := r.getProvider(ctx) if err != nil { return nil, err @@ -49,7 +49,7 @@ func (r CurrentUserPropReader) CurrentUser(ctx context.EvalContext) (*auth.UserI } // ActiveRoles returns the active roles -func (r CurrentUserPropReader) ActiveRoles(ctx context.EvalContext) ([]*auth.RoleIdentity, error) { +func (r CurrentUserPropReader) ActiveRoles(ctx exprctx.EvalContext) ([]*auth.RoleIdentity, error) { p, err := r.getProvider(ctx) if err != nil { return nil, err @@ -58,6 +58,6 @@ func (r CurrentUserPropReader) ActiveRoles(ctx context.EvalContext) ([]*auth.Rol return roles, nil } -func (r CurrentUserPropReader) getProvider(ctx context.EvalContext) (CurrentUserPropProvider, error) { - return getPropProvider[CurrentUserPropProvider](ctx, context.OptPropCurrentUser) +func (r CurrentUserPropReader) getProvider(ctx exprctx.EvalContext) (CurrentUserPropProvider, error) { + return getPropProvider[CurrentUserPropProvider](ctx, exprctx.OptPropCurrentUser) } diff --git a/pkg/expression/contextopt/ddlowner.go b/pkg/expression/expropt/ddlowner.go similarity index 72% rename from pkg/expression/contextopt/ddlowner.go rename to pkg/expression/expropt/ddlowner.go index f7edd1b43acb5..05508ec30f1e9 100644 --- a/pkg/expression/contextopt/ddlowner.go +++ b/pkg/expression/expropt/ddlowner.go @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" ) -var _ context.OptionalEvalPropProvider = DDLOwnerInfoProvider(nil) +var _ exprctx.OptionalEvalPropProvider = DDLOwnerInfoProvider(nil) var _ RequireOptionalEvalProps = DDLOwnerPropReader{} // DDLOwnerInfoProvider is used to provide the DDL owner information. @@ -26,21 +26,21 @@ var _ RequireOptionalEvalProps = DDLOwnerPropReader{} type DDLOwnerInfoProvider func() bool // Desc returns the description for the property key. -func (p DDLOwnerInfoProvider) Desc() *context.OptionalEvalPropDesc { - return context.OptPropDDLOwnerInfo.Desc() +func (p DDLOwnerInfoProvider) Desc() *exprctx.OptionalEvalPropDesc { + return exprctx.OptPropDDLOwnerInfo.Desc() } // DDLOwnerPropReader is used by expression to get the DDL owner information. type DDLOwnerPropReader struct{} // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (r DDLOwnerPropReader) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - return context.OptPropDDLOwnerInfo.AsPropKeySet() +func (r DDLOwnerPropReader) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + return exprctx.OptPropDDLOwnerInfo.AsPropKeySet() } // IsDDLOwner returns whether the current node is DDL owner -func (r DDLOwnerPropReader) IsDDLOwner(ctx context.EvalContext) (bool, error) { - p, err := getPropProvider[DDLOwnerInfoProvider](ctx, context.OptPropDDLOwnerInfo) +func (r DDLOwnerPropReader) IsDDLOwner(ctx exprctx.EvalContext) (bool, error) { + p, err := getPropProvider[DDLOwnerInfoProvider](ctx, exprctx.OptPropDDLOwnerInfo) if err != nil { return false, err } diff --git a/pkg/expression/contextopt/infoschema.go b/pkg/expression/expropt/infoschema.go similarity index 72% rename from pkg/expression/contextopt/infoschema.go rename to pkg/expression/expropt/infoschema.go index 2fb6e59c8d6dc..c5e8b05733185 100644 --- a/pkg/expression/contextopt/infoschema.go +++ b/pkg/expression/expropt/infoschema.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" ) @@ -23,21 +23,21 @@ import ( type InfoSchemaPropProvider func(isDomain bool) infoschema.MetaOnlyInfoSchema // Desc returns the description for the property key. -func (InfoSchemaPropProvider) Desc() *context.OptionalEvalPropDesc { - return context.OptPropInfoSchema.Desc() +func (InfoSchemaPropProvider) Desc() *exprctx.OptionalEvalPropDesc { + return exprctx.OptPropInfoSchema.Desc() } // InfoSchemaPropReader is used to get the information schema. type InfoSchemaPropReader struct{} // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (InfoSchemaPropReader) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - return context.OptPropInfoSchema.AsPropKeySet() +func (InfoSchemaPropReader) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + return exprctx.OptPropInfoSchema.AsPropKeySet() } // GetSessionInfoSchema returns session information schema. -func (InfoSchemaPropReader) GetSessionInfoSchema(ctx context.EvalContext) (infoschema.MetaOnlyInfoSchema, error) { - p, err := getPropProvider[InfoSchemaPropProvider](ctx, context.OptPropInfoSchema) +func (InfoSchemaPropReader) GetSessionInfoSchema(ctx exprctx.EvalContext) (infoschema.MetaOnlyInfoSchema, error) { + p, err := getPropProvider[InfoSchemaPropProvider](ctx, exprctx.OptPropInfoSchema) if err != nil { return nil, err } @@ -45,8 +45,8 @@ func (InfoSchemaPropReader) GetSessionInfoSchema(ctx context.EvalContext) (infos } // GetDomainInfoSchema return domain information schema. -func (InfoSchemaPropReader) GetDomainInfoSchema(ctx context.EvalContext) (infoschema.MetaOnlyInfoSchema, error) { - p, err := getPropProvider[InfoSchemaPropProvider](ctx, context.OptPropInfoSchema) +func (InfoSchemaPropReader) GetDomainInfoSchema(ctx exprctx.EvalContext) (infoschema.MetaOnlyInfoSchema, error) { + p, err := getPropProvider[InfoSchemaPropProvider](ctx, exprctx.OptPropInfoSchema) if err != nil { return nil, err } diff --git a/pkg/expression/contextopt/kvstore.go b/pkg/expression/expropt/kvstore.go similarity index 70% rename from pkg/expression/contextopt/kvstore.go rename to pkg/expression/expropt/kvstore.go index 8d60160ec7358..18c7d3d11d1c7 100644 --- a/pkg/expression/contextopt/kvstore.go +++ b/pkg/expression/expropt/kvstore.go @@ -12,34 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/kv" ) -var _ context.OptionalEvalPropProvider = KVStorePropProvider(nil) +var _ exprctx.OptionalEvalPropProvider = KVStorePropProvider(nil) // KVStorePropProvider is used to provide kv.Storage for context type KVStorePropProvider func() kv.Storage // Desc returns the description for the property key. -func (KVStorePropProvider) Desc() *context.OptionalEvalPropDesc { - return context.OptPropKVStore.Desc() +func (KVStorePropProvider) Desc() *exprctx.OptionalEvalPropDesc { + return exprctx.OptPropKVStore.Desc() } // KVStorePropReader is used by expression to get kv.Storage. type KVStorePropReader struct{} // RequiredOptionalEvalProps implements the RequireOptionalEvalProps interface. -func (KVStorePropReader) RequiredOptionalEvalProps() context.OptionalEvalPropKeySet { - return context.OptPropKVStore.AsPropKeySet() +func (KVStorePropReader) RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet { + return exprctx.OptPropKVStore.AsPropKeySet() } // GetKVStore returns a SequenceOperator. -func (KVStorePropReader) GetKVStore(ctx context.EvalContext) (kv.Storage, error) { - p, err := getPropProvider[KVStorePropProvider](ctx, context.OptPropKVStore) +func (KVStorePropReader) GetKVStore(ctx exprctx.EvalContext) (kv.Storage, error) { + p, err := getPropProvider[KVStorePropProvider](ctx, exprctx.OptPropKVStore) if err != nil { return nil, err } diff --git a/pkg/expression/contextopt/optional.go b/pkg/expression/expropt/optional.go similarity index 74% rename from pkg/expression/contextopt/optional.go rename to pkg/expression/expropt/optional.go index b37d4fd2d829f..1a9c8b793fc9d 100644 --- a/pkg/expression/contextopt/optional.go +++ b/pkg/expression/expropt/optional.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/util/intest" ) @@ -25,20 +25,20 @@ type RequireOptionalEvalProps interface { // RequiredOptionalEvalProps returns the optional properties that this function requires. // If the returned `OptionalEvalPropKeySet` is empty, // it means this function does not require any optional properties. - RequiredOptionalEvalProps() context.OptionalEvalPropKeySet + RequiredOptionalEvalProps() exprctx.OptionalEvalPropKeySet } // OptionalEvalPropProviders contains some evaluation property providers in EvalContext. -type OptionalEvalPropProviders [context.OptPropsCnt]context.OptionalEvalPropProvider +type OptionalEvalPropProviders [exprctx.OptPropsCnt]exprctx.OptionalEvalPropProvider // Contains checks whether the provider by key exists. -func (o *OptionalEvalPropProviders) Contains(key context.OptionalEvalPropKey) bool { +func (o *OptionalEvalPropProviders) Contains(key exprctx.OptionalEvalPropKey) bool { return o[key] != nil } // Get gets the provider by key. -func (o *OptionalEvalPropProviders) Get(key context.OptionalEvalPropKey) (context.OptionalEvalPropProvider, bool) { - if key < 0 || int(key) >= context.OptPropsCnt { +func (o *OptionalEvalPropProviders) Get(key exprctx.OptionalEvalPropKey) (exprctx.OptionalEvalPropProvider, bool) { + if key < 0 || int(key) >= exprctx.OptPropsCnt { return nil, false } @@ -50,32 +50,32 @@ func (o *OptionalEvalPropProviders) Get(key context.OptionalEvalPropKey) (contex } // Add adds an optional property -func (o *OptionalEvalPropProviders) Add(val context.OptionalEvalPropProvider) { +func (o *OptionalEvalPropProviders) Add(val exprctx.OptionalEvalPropProvider) { intest.AssertFunc(func() bool { intest.AssertNotNil(val) switch val.Desc().Key() { - case context.OptPropCurrentUser: + case exprctx.OptPropCurrentUser: _, ok := val.(CurrentUserPropProvider) intest.Assert(ok) - case context.OptPropSessionVars: + case exprctx.OptPropSessionVars: _, ok := val.(*SessionVarsPropProvider) intest.Assert(ok) - case context.OptPropInfoSchema: + case exprctx.OptPropInfoSchema: _, ok := val.(InfoSchemaPropProvider) intest.Assert(ok) - case context.OptPropKVStore: + case exprctx.OptPropKVStore: _, ok := val.(KVStorePropProvider) intest.Assert(ok) - case context.OptPropSQLExecutor: + case exprctx.OptPropSQLExecutor: _, ok := val.(SQLExecutorPropProvider) intest.Assert(ok) - case context.OptPropAdvisoryLock: + case exprctx.OptPropAdvisoryLock: _, ok := val.(*AdvisoryLockPropProvider) intest.Assert(ok) - case context.OptPropDDLOwnerInfo: + case exprctx.OptPropDDLOwnerInfo: _, ok := val.(DDLOwnerInfoProvider) intest.Assert(ok) - case context.OptPropSequenceOperator: + case exprctx.OptPropSequenceOperator: _, ok := val.(SequenceOperatorProvider) intest.Assert(ok) default: @@ -87,7 +87,7 @@ func (o *OptionalEvalPropProviders) Add(val context.OptionalEvalPropProvider) { } // PropKeySet returns the set for optional evaluation properties in EvalContext. -func (o *OptionalEvalPropProviders) PropKeySet() (set context.OptionalEvalPropKeySet) { +func (o *OptionalEvalPropProviders) PropKeySet() (set exprctx.OptionalEvalPropKeySet) { for _, p := range o { if p != nil { set = set.Add(p.Desc().Key()) @@ -96,7 +96,7 @@ func (o *OptionalEvalPropProviders) PropKeySet() (set context.OptionalEvalPropKe return } -func getPropProvider[T context.OptionalEvalPropProvider](ctx context.EvalContext, key context.OptionalEvalPropKey) (p T, _ error) { +func getPropProvider[T exprctx.OptionalEvalPropProvider](ctx exprctx.EvalContext, key exprctx.OptionalEvalPropKey) (p T, _ error) { intest.AssertFunc(func() bool { var stub T intest.Assert(stub.Desc().Key() == key) diff --git a/pkg/expression/contextopt/optional_test.go b/pkg/expression/expropt/optional_test.go similarity index 79% rename from pkg/expression/contextopt/optional_test.go rename to pkg/expression/expropt/optional_test.go index 0db6ff9f74a3d..6c59a33def353 100644 --- a/pkg/expression/contextopt/optional_test.go +++ b/pkg/expression/expropt/optional_test.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextopt +package expropt import ( "testing" "time" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser/auth" @@ -36,7 +36,7 @@ func (p mockSessionVarsProvider) GetSessionVars() *variable.SessionVars { } type mockEvalCtx struct { - context.EvalContext + exprctx.EvalContext props OptionalEvalPropProviders } @@ -45,20 +45,20 @@ func (ctx *mockEvalCtx) Location() *time.Location { } func (ctx *mockEvalCtx) GetOptionalPropProvider( - key context.OptionalEvalPropKey, -) (context.OptionalEvalPropProvider, bool) { + key exprctx.OptionalEvalPropKey, +) (exprctx.OptionalEvalPropProvider, bool) { return ctx.props.Get(key) } func assertReaderFuncReturnErr[T any]( - t *testing.T, ctx context.EvalContext, fn func(ctx context.EvalContext) (T, error), + t *testing.T, ctx exprctx.EvalContext, fn func(ctx exprctx.EvalContext) (T, error), ) { _, err := fn(ctx) require.Contains(t, err.Error(), "not exists in EvalContext") } func assertReaderFuncValue[T any]( - t *testing.T, ctx context.EvalContext, fn func(ctx context.EvalContext) (T, error), + t *testing.T, ctx exprctx.EvalContext, fn func(ctx exprctx.EvalContext) (T, error), ) T { v, err := fn(ctx) require.NoError(t, err) @@ -69,25 +69,25 @@ func TestOptionalEvalPropProviders(t *testing.T) { mockCtx := &mockEvalCtx{} require.True(t, mockCtx.props.PropKeySet().IsEmpty()) - var p context.OptionalEvalPropProvider + var p exprctx.OptionalEvalPropProvider var reader RequireOptionalEvalProps - var verifyNoProvider func(ctx context.EvalContext) - var verifyProvider func(ctx context.EvalContext, val context.OptionalEvalPropProvider) + var verifyNoProvider func(ctx exprctx.EvalContext) + var verifyProvider func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) - for i := 0; i < context.OptPropsCnt; i++ { - key := context.OptionalEvalPropKey(i) + for i := 0; i < exprctx.OptPropsCnt; i++ { + key := exprctx.OptionalEvalPropKey(i) switch key { - case context.OptPropCurrentUser: + case exprctx.OptPropCurrentUser: user := &auth.UserIdentity{Username: "u1", Hostname: "h1"} roles := []*auth.RoleIdentity{{Username: "u2", Hostname: "h2"}, {Username: "u3", Hostname: "h3"}} p = CurrentUserPropProvider(func() (*auth.UserIdentity, []*auth.RoleIdentity) { return user, roles }) r := CurrentUserPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.CurrentUser) assertReaderFuncReturnErr(t, ctx, r.ActiveRoles) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { user2, roles2 := val.(CurrentUserPropProvider)() require.Equal(t, user, user2) require.Equal(t, roles, roles2) @@ -95,20 +95,20 @@ func TestOptionalEvalPropProviders(t *testing.T) { require.Equal(t, user, assertReaderFuncValue(t, ctx, r.CurrentUser)) require.Equal(t, roles, assertReaderFuncValue(t, ctx, r.ActiveRoles)) } - case context.OptPropSessionVars: + case exprctx.OptPropSessionVars: vars := variable.NewSessionVars(nil) vars.TimeZone = time.UTC vars.StmtCtx.SetTimeZone(time.UTC) p = NewSessionVarsProvider(mockSessionVarsProvider{vars: vars}) r := SessionVarsPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.GetSessionVars) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { require.Same(t, vars, assertReaderFuncValue(t, ctx, r.GetSessionVars)) } - case context.OptPropInfoSchema: + case exprctx.OptPropInfoSchema: type mockIsType struct { infoschema.MetaOnlyInfoSchema } @@ -121,11 +121,11 @@ func TestOptionalEvalPropProviders(t *testing.T) { }) r := InfoSchemaPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.GetSessionInfoSchema) assertReaderFuncReturnErr(t, ctx, r.GetDomainInfoSchema) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { is, ok := val.(InfoSchemaPropProvider)(true).(*mockIsType) require.True(t, ok) require.Same(t, &is1, is) @@ -137,7 +137,7 @@ func TestOptionalEvalPropProviders(t *testing.T) { require.Same(t, &is1, assertReaderFuncValue(t, ctx, r.GetDomainInfoSchema)) require.Same(t, &is2, assertReaderFuncValue(t, ctx, r.GetSessionInfoSchema)) } - case context.OptPropKVStore: + case exprctx.OptPropKVStore: type mockKVStoreType struct { kv.Storage } @@ -147,16 +147,16 @@ func TestOptionalEvalPropProviders(t *testing.T) { }) r := KVStorePropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.GetKVStore) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { store, ok := val.(KVStorePropProvider)().(*mockKVStoreType) require.True(t, ok) require.Same(t, mockKVStore, store) require.Same(t, mockKVStore, assertReaderFuncValue(t, ctx, r.GetKVStore)) } - case context.OptPropSQLExecutor: + case exprctx.OptPropSQLExecutor: type mockSQLExecutorType struct { SQLExecutor } @@ -170,10 +170,10 @@ func TestOptionalEvalPropProviders(t *testing.T) { }) r := SQLExecutorPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.GetSQLExecutor) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { exec, err := val.(SQLExecutorPropProvider)() require.Nil(t, err) require.Same(t, mockExecutor, exec.(*mockSQLExecutorType)) @@ -191,7 +191,7 @@ func TestOptionalEvalPropProviders(t *testing.T) { require.EqualError(t, err, "mockErr2") require.Nil(t, exec) } - case context.OptPropSequenceOperator: + case exprctx.OptPropSequenceOperator: type mockSeqOpType struct { SequenceOperator } @@ -207,12 +207,12 @@ func TestOptionalEvalPropProviders(t *testing.T) { }) r := SequenceOperatorPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { - assertReaderFuncReturnErr(t, ctx, func(ctx context.EvalContext) (SequenceOperator, error) { + verifyNoProvider = func(ctx exprctx.EvalContext) { + assertReaderFuncReturnErr(t, ctx, func(ctx exprctx.EvalContext) (SequenceOperator, error) { return r.GetSequenceOperator(ctx, "db1", "name1") }) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { op, err := val.(SequenceOperatorProvider)("db1", "name1") require.NoError(t, err) require.Same(t, mockOp, op.(*mockSeqOpType)) @@ -223,7 +223,7 @@ func TestOptionalEvalPropProviders(t *testing.T) { require.Nil(t, op) mockErr = nil - assertReaderFuncValue(t, ctx, func(ctx context.EvalContext) (SequenceOperator, error) { + assertReaderFuncValue(t, ctx, func(ctx exprctx.EvalContext) (SequenceOperator, error) { return r.GetSequenceOperator(ctx, "db1", "name1") }) @@ -232,7 +232,7 @@ func TestOptionalEvalPropProviders(t *testing.T) { require.EqualError(t, err, "mockErr2") require.Nil(t, op) } - case context.OptPropAdvisoryLock: + case exprctx.OptPropAdvisoryLock: type mockLockCtxType struct { AdvisoryLockContext } @@ -240,23 +240,23 @@ func TestOptionalEvalPropProviders(t *testing.T) { p = NewAdvisoryLockPropProvider(mockLockCtx) r := AdvisoryLockPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.AdvisoryLockCtx) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { got := val.(*AdvisoryLockPropProvider).AdvisoryLockContext require.Same(t, mockLockCtx, got) require.Same(t, p, assertReaderFuncValue(t, ctx, r.AdvisoryLockCtx)) } - case context.OptPropDDLOwnerInfo: + case exprctx.OptPropDDLOwnerInfo: var isOwner bool p = DDLOwnerInfoProvider(func() bool { return isOwner }) r := DDLOwnerPropReader{} reader = r - verifyNoProvider = func(ctx context.EvalContext) { + verifyNoProvider = func(ctx exprctx.EvalContext) { assertReaderFuncReturnErr(t, ctx, r.IsDDLOwner) } - verifyProvider = func(ctx context.EvalContext, val context.OptionalEvalPropProvider) { + verifyProvider = func(ctx exprctx.EvalContext, val exprctx.OptionalEvalPropProvider) { isOwner = true require.True(t, val.(DDLOwnerInfoProvider)()) isOwner = false @@ -273,7 +273,7 @@ func TestOptionalEvalPropProviders(t *testing.T) { // before add beforeKeySet := mockCtx.props.PropKeySet() - require.Equal(t, context.OptionalEvalPropKeySet(1<= len(ctx.paramList) { return types.Datum{}, exprctx.ErrParamIndexExceedParamCounts } return ctx.paramList[idx], nil } -var _ exprctx.StaticConvertibleEvalContext = &StaticEvalContext{} +var _ exprctx.StaticConvertibleEvalContext = &EvalContext{} // AllParamValues implements context.StaticConvertibleEvalContext. -func (ctx *StaticEvalContext) AllParamValues() []types.Datum { +func (ctx *EvalContext) AllParamValues() []types.Datum { return ctx.paramList } // GetDynamicPrivCheckFn implements context.StaticConvertibleEvalContext. -func (ctx *StaticEvalContext) GetDynamicPrivCheckFn() func(privName string, grantable bool) bool { +func (ctx *EvalContext) GetDynamicPrivCheckFn() func(privName string, grantable bool) bool { return ctx.requestDynamicVerificationFn } // GetRequestVerificationFn implements context.StaticConvertibleEvalContext. -func (ctx *StaticEvalContext) GetRequestVerificationFn() func(db string, table string, column string, priv mysql.PrivilegeType) bool { +func (ctx *EvalContext) GetRequestVerificationFn() func(db string, table string, column string, priv mysql.PrivilegeType) bool { return ctx.requestVerificationFn } // GetWarnHandler implements context.StaticConvertibleEvalContext. -func (ctx *StaticEvalContext) GetWarnHandler() contextutil.WarnHandler { +func (ctx *EvalContext) GetWarnHandler() contextutil.WarnHandler { return ctx.warnHandler } -// LoadSystemVars loads system variables and returns a new `StaticEvalContext` with system variables loaded. -func (ctx *StaticEvalContext) LoadSystemVars(sysVars map[string]string) (*StaticEvalContext, error) { +// LoadSystemVars loads system variables and returns a new `EvalContext` with system variables loaded. +func (ctx *EvalContext) LoadSystemVars(sysVars map[string]string) (*EvalContext, error) { sessionVars, err := newSessionVarsWithSystemVariables(sysVars) if err != nil { return nil, err @@ -446,10 +446,10 @@ func (ctx *StaticEvalContext) LoadSystemVars(sysVars map[string]string) (*Static return ctx.loadSessionVarsInternal(sessionVars, sysVars), nil } -func (ctx *StaticEvalContext) loadSessionVarsInternal( +func (ctx *EvalContext) loadSessionVarsInternal( sessionVars *variable.SessionVars, sysVars map[string]string, -) *StaticEvalContext { - opts := make([]StaticEvalCtxOption, 0, 8) +) *EvalContext { + opts := make([]EvalCtxOption, 0, 8) for name, val := range sysVars { name = strings.ToLower(name) switch name { @@ -472,7 +472,7 @@ func (ctx *StaticEvalContext) loadSessionVarsInternal( return ctx.Apply(opts...) } -func (ctx *StaticEvalContext) currentTimeFuncFromStringVal(val string) func() (time.Time, error) { +func (ctx *EvalContext) currentTimeFuncFromStringVal(val string) func() (time.Time, error) { return func() (time.Time, error) { if val == variable.DefTimestamp { return time.Now(), nil @@ -497,8 +497,8 @@ func newSessionVarsWithSystemVariables(vars map[string]string) (*variable.Sessio return sessionVars, nil } -// MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `StaticEvalContext`. -func MakeEvalContextStatic(ctx exprctx.StaticConvertibleEvalContext) *StaticEvalContext { +// MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `EvalContext`. +func MakeEvalContextStatic(ctx exprctx.StaticConvertibleEvalContext) *EvalContext { typeCtx := ctx.TypeCtx() errCtx := ctx.ErrCtx() @@ -513,7 +513,7 @@ func MakeEvalContextStatic(ctx exprctx.StaticConvertibleEvalContext) *StaticEval // TODO: use a more structural way to replace the closure. // These closure makes sure the fields which may be changed in the execution of the next statement will not be embedded into them, to make // sure it's safe to call them after the session continues to execute other statements. - staticCtx := NewStaticEvalContext( + staticCtx := NewEvalContext( WithWarnHandler(ctx.GetWarnHandler()), WithSQLMode(ctx.SQLMode()), WithTypeFlags(typeCtx.Flags()), diff --git a/pkg/expression/contextstatic/evalctx_test.go b/pkg/expression/exprstatic/evalctx_test.go similarity index 84% rename from pkg/expression/contextstatic/evalctx_test.go rename to pkg/expression/exprstatic/evalctx_test.go index 209f88a706f79..cf4145e8cdab8 100644 --- a/pkg/expression/contextstatic/evalctx_test.go +++ b/pkg/expression/exprstatic/evalctx_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextstatic +package exprstatic import ( "fmt" @@ -22,8 +22,8 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -37,19 +37,19 @@ import ( func TestNewStaticEvalCtx(t *testing.T) { // default context prevID := contextutil.GenContextID() - ctx := NewStaticEvalContext() + ctx := NewEvalContext() require.Equal(t, prevID+1, ctx.CtxID()) checkDefaultStaticEvalCtx(t, ctx) // with options prevID = ctx.CtxID() options, stateForTest := getEvalCtxOptionsForTest(t) - ctx = NewStaticEvalContext(options...) + ctx = NewEvalContext(options...) require.Equal(t, prevID+1, ctx.CtxID()) checkOptionsStaticEvalCtx(t, ctx, stateForTest) } -func checkDefaultStaticEvalCtx(t *testing.T, ctx *StaticEvalContext) { +func checkDefaultStaticEvalCtx(t *testing.T, ctx *EvalContext) { mode, err := mysql.GetSQLMode(mysql.DefaultSQLMode) require.NoError(t, err) require.Equal(t, mode, ctx.SQLMode()) @@ -67,7 +67,7 @@ func checkDefaultStaticEvalCtx(t *testing.T, ctx *StaticEvalContext) { require.True(t, ctx.RequestVerification("test", "t1", "", mysql.CreatePriv)) require.True(t, ctx.RequestDynamicVerification("RESTRICTED_USER_ADMIN", true)) require.True(t, ctx.GetOptionalPropSet().IsEmpty()) - p, ok := ctx.GetOptionalPropProvider(context.OptPropAdvisoryLock) + p, ok := ctx.GetOptionalPropProvider(exprctx.OptPropAdvisoryLock) require.Nil(t, p) require.False(t, ok) @@ -91,7 +91,7 @@ type evalCtxOptionsTestState struct { privRet bool } -func getEvalCtxOptionsForTest(t *testing.T) ([]StaticEvalCtxOption, *evalCtxOptionsTestState) { +func getEvalCtxOptionsForTest(t *testing.T) ([]EvalCtxOption, *evalCtxOptionsTestState) { loc, err := time.LoadLocation("US/Eastern") require.NoError(t, err) s := &evalCtxOptionsTestState{ @@ -101,16 +101,16 @@ func getEvalCtxOptionsForTest(t *testing.T) ([]StaticEvalCtxOption, *evalCtxOpti userVars: variable.NewUserVars(), } - provider1 := contextopt.CurrentUserPropProvider(func() (*auth.UserIdentity, []*auth.RoleIdentity) { + provider1 := expropt.CurrentUserPropProvider(func() (*auth.UserIdentity, []*auth.RoleIdentity) { return &auth.UserIdentity{Username: "user1", Hostname: "host1"}, []*auth.RoleIdentity{{Username: "role1", Hostname: "host2"}} }) - provider2 := contextopt.DDLOwnerInfoProvider(func() bool { + provider2 := expropt.DDLOwnerInfoProvider(func() bool { return s.ddlOwner }) - return []StaticEvalCtxOption{ + return []EvalCtxOption{ WithWarnHandler(s.warnHandler), WithSQLMode(mysql.ModeNoZeroDate | mysql.ModeStrictTransTables), WithTypeFlags(types.FlagAllowNegativeToUnsigned | types.FlagSkipASCIICheck), @@ -141,7 +141,7 @@ func getEvalCtxOptionsForTest(t *testing.T) ([]StaticEvalCtxOption, *evalCtxOpti }, s } -func checkOptionsStaticEvalCtx(t *testing.T, ctx *StaticEvalContext, s *evalCtxOptionsTestState) { +func checkOptionsStaticEvalCtx(t *testing.T, ctx *EvalContext, s *evalCtxOptionsTestState) { require.Same(t, ctx.warnHandler, s.warnHandler) require.Equal(t, mysql.ModeNoZeroDate|mysql.ModeStrictTransTables, ctx.SQLMode()) require.Equal(t, @@ -176,21 +176,21 @@ func checkOptionsStaticEvalCtx(t *testing.T, ctx *StaticEvalContext, s *evalCtxO require.True(t, ctx.RequestDynamicVerification("RESTRICTED_TABLES_ADMIN", false)) require.Equal(t, []any{"RESTRICTED_TABLES_ADMIN", false}, s.privCheckArgs) - var optSet context.OptionalEvalPropKeySet - optSet = optSet.Add(context.OptPropCurrentUser).Add(context.OptPropDDLOwnerInfo) + var optSet exprctx.OptionalEvalPropKeySet + optSet = optSet.Add(exprctx.OptPropCurrentUser).Add(exprctx.OptPropDDLOwnerInfo) require.Equal(t, optSet, ctx.GetOptionalPropSet()) - p, ok := ctx.GetOptionalPropProvider(context.OptPropCurrentUser) + p, ok := ctx.GetOptionalPropProvider(exprctx.OptPropCurrentUser) require.True(t, ok) - user, roles := p.(contextopt.CurrentUserPropProvider)() + user, roles := p.(expropt.CurrentUserPropProvider)() require.Equal(t, &auth.UserIdentity{Username: "user1", Hostname: "host1"}, user) require.Equal(t, []*auth.RoleIdentity{{Username: "role1", Hostname: "host2"}}, roles) - p, ok = ctx.GetOptionalPropProvider(context.OptPropDDLOwnerInfo) + p, ok = ctx.GetOptionalPropProvider(exprctx.OptPropDDLOwnerInfo) s.ddlOwner = true require.True(t, ok) - require.True(t, p.(contextopt.DDLOwnerInfoProvider)()) + require.True(t, p.(expropt.DDLOwnerInfoProvider)()) s.ddlOwner = false - require.False(t, p.(contextopt.DDLOwnerInfoProvider)()) - p, ok = ctx.GetOptionalPropProvider(context.OptPropInfoSchema) + require.False(t, p.(expropt.DDLOwnerInfoProvider)()) + p, ok = ctx.GetOptionalPropProvider(exprctx.OptPropInfoSchema) require.False(t, ok) require.Nil(t, p) } @@ -217,7 +217,7 @@ func TestStaticEvalCtxCurrentTime(t *testing.T) { return time.Time{}, errors.NewNoStackError("should not reach here") } - ctx := NewStaticEvalContext(WithCurrentTime(getTime)) + ctx := NewEvalContext(WithCurrentTime(getTime)) // get time for the first two times should fail got, err := ctx.CurrentTime() @@ -245,7 +245,7 @@ func TestStaticEvalCtxCurrentTime(t *testing.T) { // CurrentTime should have the same location with `ctx.Location()` loc2, err := time.LoadLocation("Australia/Sydney") require.NoError(t, err) - ctx = NewStaticEvalContext( + ctx = NewEvalContext( WithLocation(loc2), WithCurrentTime(func() (time.Time, error) { return tm, nil @@ -294,19 +294,19 @@ func TestStaticEvalCtxCurrentTime(t *testing.T) { func TestStaticEvalCtxWarnings(t *testing.T) { // default context should have a empty StaticWarningsHandler - ctx := NewStaticEvalContext() + ctx := NewEvalContext() h, ok := ctx.warnHandler.(*contextutil.StaticWarnHandler) require.True(t, ok) require.Equal(t, 0, h.WarningCount()) // WithWarnHandler should work ignoreHandler := contextutil.IgnoreWarn - ctx = NewStaticEvalContext(WithWarnHandler(ignoreHandler)) + ctx = NewEvalContext(WithWarnHandler(ignoreHandler)) require.True(t, ctx.warnHandler == ignoreHandler) // All contexts should use the same warning handler h = contextutil.NewStaticWarnHandler(8) - ctx = NewStaticEvalContext(WithWarnHandler(h)) + ctx = NewEvalContext(WithWarnHandler(h)) tc, ec := ctx.TypeCtx(), ctx.ErrCtx() h.AppendWarning(errors.NewNoStackError("warn0")) ctx.AppendWarning(errors.NewNoStackError("warn1")) @@ -371,31 +371,31 @@ func TestStaticEvalCtxWarnings(t *testing.T) { } func TestStaticEvalContextOptionalProps(t *testing.T) { - ctx := NewStaticEvalContext() + ctx := NewEvalContext() require.True(t, ctx.GetOptionalPropSet().IsEmpty()) ctx2 := ctx.Apply(WithOptionalProperty( - contextopt.CurrentUserPropProvider(func() (u *auth.UserIdentity, r []*auth.RoleIdentity) { return }), + expropt.CurrentUserPropProvider(func() (u *auth.UserIdentity, r []*auth.RoleIdentity) { return }), )) - var emptySet context.OptionalEvalPropKeySet + var emptySet exprctx.OptionalEvalPropKeySet require.Equal(t, emptySet, ctx.GetOptionalPropSet()) - require.Equal(t, emptySet.Add(context.OptPropCurrentUser), ctx2.GetOptionalPropSet()) + require.Equal(t, emptySet.Add(exprctx.OptPropCurrentUser), ctx2.GetOptionalPropSet()) // Apply should override all optional properties ctx3 := ctx2.Apply(WithOptionalProperty( - contextopt.DDLOwnerInfoProvider(func() bool { return true }), - contextopt.InfoSchemaPropProvider(func(isDomain bool) infoschema.MetaOnlyInfoSchema { return nil }), + expropt.DDLOwnerInfoProvider(func() bool { return true }), + expropt.InfoSchemaPropProvider(func(isDomain bool) infoschema.MetaOnlyInfoSchema { return nil }), )) require.Equal(t, - emptySet.Add(context.OptPropDDLOwnerInfo).Add(context.OptPropInfoSchema), + emptySet.Add(exprctx.OptPropDDLOwnerInfo).Add(exprctx.OptPropInfoSchema), ctx3.GetOptionalPropSet(), ) require.Equal(t, emptySet, ctx.GetOptionalPropSet()) - require.Equal(t, emptySet.Add(context.OptPropCurrentUser), ctx2.GetOptionalPropSet()) + require.Equal(t, emptySet.Add(exprctx.OptPropCurrentUser), ctx2.GetOptionalPropSet()) } func TestUpdateStaticEvalContext(t *testing.T) { - oldCtx := NewStaticEvalContext() + oldCtx := NewEvalContext() ctx := oldCtx.Apply() // Should return a different instance @@ -405,17 +405,17 @@ func TestUpdateStaticEvalContext(t *testing.T) { require.Greater(t, ctx.CtxID(), oldCtx.CtxID()) // inner state should not be the same address - require.NotSame(t, &oldCtx.staticEvalCtxState, &ctx.staticEvalCtxState) + require.NotSame(t, &oldCtx.evalCtxState, &ctx.evalCtxState) // compare a state object by excluding some changed fields - excludeChangedFields := func(s *staticEvalCtxState) staticEvalCtxState { + excludeChangedFields := func(s *evalCtxState) evalCtxState { state := *s state.typeCtx = types.DefaultStmtNoWarningContext state.errCtx = errctx.StrictNoWarningContext state.currentTime = nil return state } - require.Equal(t, excludeChangedFields(&oldCtx.staticEvalCtxState), excludeChangedFields(&ctx.staticEvalCtxState)) + require.Equal(t, excludeChangedFields(&oldCtx.evalCtxState), excludeChangedFields(&ctx.evalCtxState)) // check fields checkDefaultStaticEvalCtx(t, ctx) @@ -431,7 +431,7 @@ func TestUpdateStaticEvalContext(t *testing.T) { // create with options opts, optState = getEvalCtxOptionsForTest(t) - ctx3 := NewStaticEvalContext(opts...) + ctx3 := NewEvalContext(opts...) require.Greater(t, ctx3.CtxID(), ctx2.CtxID()) checkOptionsStaticEvalCtx(t, ctx3, optState) } @@ -441,7 +441,7 @@ func TestParamList(t *testing.T) { paramList.Append(types.NewDatum(1)) paramList.Append(types.NewDatum(2)) paramList.Append(types.NewDatum(3)) - ctx := NewStaticEvalContext( + ctx := NewEvalContext( WithParamList(paramList), ) for i := 0; i < 3; i++ { @@ -462,7 +462,7 @@ func TestParamList(t *testing.T) { func TestMakeEvalContextStatic(t *testing.T) { // This test is to ensure that the `MakeEvalContextStatic` function works as expected. - // It requires the developers to create a special `StaticEvalContext`, whose every fields + // It requires the developers to create a special `EvalContext`, whose every fields // are non-empty. Then, the `MakeEvalContextStatic` function is called to create a new // clone of it. Finally, the new clone is compared with the original one to ensure that // the fields are correctly copied. @@ -473,11 +473,11 @@ func TestMakeEvalContextStatic(t *testing.T) { userVars.SetUserVarVal("a", types.NewStringDatum("v1")) userVars.SetUserVarVal("b", types.NewIntDatum(2)) - provider := contextopt.DDLOwnerInfoProvider(func() bool { + provider := expropt.DDLOwnerInfoProvider(func() bool { return true }) - obj := NewStaticEvalContext( + obj := NewEvalContext( WithWarnHandler(contextutil.NewStaticWarnHandler(16)), WithSQLMode(mysql.ModeNoZeroDate|mysql.ModeStrictTransTables), WithTypeFlags(types.FlagAllowNegativeToUnsigned|types.FlagSkipASCIICheck), @@ -504,19 +504,19 @@ func TestMakeEvalContextStatic(t *testing.T) { obj.AppendWarning(errors.New("test warning")) ignorePath := []string{ - "$.staticEvalCtxState.warnHandler.**", - "$.staticEvalCtxState.typeCtx.**", - "$.staticEvalCtxState.errCtx.**", - "$.staticEvalCtxState.currentTime.**", - "$.staticEvalCtxState.userVars.lock", - "$.staticEvalCtxState.props", + "$.evalCtxState.warnHandler.**", + "$.evalCtxState.typeCtx.**", + "$.evalCtxState.errCtx.**", + "$.evalCtxState.currentTime.**", + "$.evalCtxState.userVars.lock", + "$.evalCtxState.props", "$.id", } - deeptest.AssertRecursivelyNotEqual(t, obj, NewStaticEvalContext(), + deeptest.AssertRecursivelyNotEqual(t, obj, NewEvalContext(), deeptest.WithIgnorePath(ignorePath), deeptest.WithPointerComparePath([]string{ - "$.staticEvalCtxState.requestVerificationFn", - "$.staticEvalCtxState.requestDynamicVerificationFn", + "$.evalCtxState.requestVerificationFn", + "$.evalCtxState.requestDynamicVerificationFn", })) staticObj := MakeEvalContextStatic(obj) @@ -524,10 +524,10 @@ func TestMakeEvalContextStatic(t *testing.T) { deeptest.AssertDeepClonedEqual(t, obj, staticObj, deeptest.WithIgnorePath(ignorePath), deeptest.WithPointerComparePath([]string{ - "$.staticEvalCtxState.warnHandler", - "$.staticEvalCtxState.paramList*.b", - "$.staticEvalCtxState.requestVerificationFn", - "$.staticEvalCtxState.requestDynamicVerificationFn", + "$.evalCtxState.warnHandler", + "$.evalCtxState.paramList*.b", + "$.evalCtxState.requestVerificationFn", + "$.evalCtxState.requestDynamicVerificationFn", }), ) @@ -543,7 +543,7 @@ func TestMakeEvalContextStatic(t *testing.T) { require.NotEqual(t, obj.GetOptionalPropSet(), staticObj.GetOptionalPropSet()) // Now, it didn't copy any optional properties. - require.Equal(t, context.OptionalEvalPropKeySet(0), staticObj.GetOptionalPropSet()) + require.Equal(t, exprctx.OptionalEvalPropKeySet(0), staticObj.GetOptionalPropSet()) } func TestEvalCtxLoadSystemVars(t *testing.T) { @@ -551,13 +551,13 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name string val string field string - assert func(ctx *StaticEvalContext, vars *variable.SessionVars) + assert func(ctx *EvalContext, vars *variable.SessionVars) }{ { name: "time_zone", val: "Europe/Berlin", field: "$.typeCtx.loc", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, "Europe/Berlin", ctx.Location().String()) require.Equal(t, vars.Location().String(), ctx.Location().String()) }, @@ -566,7 +566,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: "sql_mode", val: "ALLOW_INVALID_DATES,ONLY_FULL_GROUP_BY", field: "$.sqlMode", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, mysql.ModeAllowInvalidDates|mysql.ModeOnlyFullGroupBy, ctx.SQLMode()) require.Equal(t, vars.SQLMode, ctx.SQLMode()) }, @@ -575,7 +575,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: "timestamp", val: "1234567890.123456", field: "$.currentTime", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { currentTime, err := ctx.CurrentTime() require.NoError(t, err) require.Equal(t, int64(1234567890123456), currentTime.UnixMicro()) @@ -586,7 +586,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: strings.ToUpper("max_allowed_packet"), // test for settings an upper case variable val: "524288", field: "$.maxAllowedPacket", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, uint64(524288), ctx.GetMaxAllowedPacket()) require.Equal(t, vars.MaxAllowedPacket, ctx.GetMaxAllowedPacket()) }, @@ -595,7 +595,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: strings.ToUpper("tidb_redact_log"), // test for settings an upper case variable val: "on", field: "$.enableRedactLog", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, "ON", ctx.GetTiDBRedactLog()) require.Equal(t, vars.EnableRedactLog, ctx.GetTiDBRedactLog()) }, @@ -604,7 +604,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: "default_week_format", val: "5", field: "$.defaultWeekFormatMode", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, "5", ctx.GetDefaultWeekFormatMode()) mode, ok := vars.GetSystemVar(variable.DefaultWeekFormat) require.True(t, ok) @@ -615,7 +615,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { name: "div_precision_increment", val: "12", field: "$.divPrecisionIncrement", - assert: func(ctx *StaticEvalContext, vars *variable.SessionVars) { + assert: func(ctx *EvalContext, vars *variable.SessionVars) { require.Equal(t, 12, ctx.GetDivPrecisionIncrement()) require.Equal(t, vars.DivPrecisionIncrement, ctx.GetDivPrecisionIncrement()) }, @@ -650,7 +650,7 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { require.NoError(t, sessionVars.SetSystemVar(sysVar.name, sysVar.val)) } - defaultEvalCtx := NewStaticEvalContext() + defaultEvalCtx := NewEvalContext() ctx, err := defaultEvalCtx.LoadSystemVars(varsMap) require.NoError(t, err) require.Greater(t, ctx.CtxID(), defaultEvalCtx.CtxID()) @@ -659,8 +659,8 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { // all system variables related fields are covered in the test list. deeptest.AssertRecursivelyNotEqual( t, - defaultEvalCtx.staticEvalCtxState, - ctx.staticEvalCtxState, + defaultEvalCtx.evalCtxState, + ctx.evalCtxState, deeptest.WithIgnorePath(nonVarRelatedFields), deeptest.WithPointerComparePath([]string{"$.currentTime"}), ) @@ -669,8 +669,8 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { // not inherited from the empty go value. deeptest.AssertRecursivelyNotEqual( t, - staticEvalCtxState{}, - ctx.staticEvalCtxState, + evalCtxState{}, + ctx.evalCtxState, deeptest.WithIgnorePath(nonVarRelatedFields), deeptest.WithPointerComparePath([]string{"$.currentTime"}), ) @@ -678,8 +678,8 @@ func TestEvalCtxLoadSystemVars(t *testing.T) { // Check all system vars unrelated fields are not changed after `LoadSystemVars`. deeptest.AssertDeepClonedEqual( t, - defaultEvalCtx.staticEvalCtxState, - ctx.staticEvalCtxState, + defaultEvalCtx.evalCtxState, + ctx.evalCtxState, deeptest.WithIgnorePath(append( varsRelatedFields, // Do not check warnHandler in `typeCtx` and `errCtx` because they should be changed to even if diff --git a/pkg/expression/contextstatic/exprctx.go b/pkg/expression/exprstatic/exprctx.go similarity index 60% rename from pkg/expression/contextstatic/exprctx.go rename to pkg/expression/exprstatic/exprctx.go index 630a00ca58f82..347625af5538c 100644 --- a/pkg/expression/contextstatic/exprctx.go +++ b/pkg/expression/exprstatic/exprctx.go @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextstatic +package exprstatic import ( "strings" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/variable" @@ -26,13 +26,13 @@ import ( "github.com/pingcap/tidb/pkg/util/mathutil" ) -// StaticExprContext implements the `exprctx.ExprContext` interface. -var _ exprctx.ExprContext = &StaticExprContext{} +// ExprContext implements the `exprctx.ExprContext` interface. +var _ exprctx.ExprContext = &ExprContext{} -// staticExprCtxState is the internal state for `StaticExprContext`. -// We make it as a standalone private struct here to make sure `StaticExprCtxOption` can only be called in constructor. -type staticExprCtxState struct { - evalCtx *StaticEvalContext +// exprCtxState is the internal state for `ExprContext`. +// We make it as a standalone private struct here to make sure `ExprCtxOption` can only be called in constructor. +type exprCtxState struct { + evalCtx *EvalContext charset string collation string defaultCollationForUTF8MB4 string @@ -47,113 +47,113 @@ type staticExprCtxState struct { groupConcatMaxLen uint64 } -// StaticExprCtxOption is the option to create or update the `StaticExprContext` -type StaticExprCtxOption func(*staticExprCtxState) +// ExprCtxOption is the option to create or update the `ExprContext` +type ExprCtxOption func(*exprCtxState) -// WithEvalCtx sets the `StaticEvalContext` for `StaticExprContext`. -func WithEvalCtx(ctx *StaticEvalContext) StaticExprCtxOption { +// WithEvalCtx sets the `EvalContext` for `ExprContext`. +func WithEvalCtx(ctx *EvalContext) ExprCtxOption { intest.AssertNotNil(ctx) - return func(s *staticExprCtxState) { + return func(s *exprCtxState) { s.evalCtx = ctx } } -// WithCharset sets the charset and collation for `StaticExprContext`. -func WithCharset(charset, collation string) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithCharset sets the charset and collation for `ExprContext`. +func WithCharset(charset, collation string) ExprCtxOption { + return func(s *exprCtxState) { s.charset = charset s.collation = collation } } -// WithDefaultCollationForUTF8MB4 sets the default collation for utf8mb4 for `StaticExprContext`. -func WithDefaultCollationForUTF8MB4(collation string) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithDefaultCollationForUTF8MB4 sets the default collation for utf8mb4 for `ExprContext`. +func WithDefaultCollationForUTF8MB4(collation string) ExprCtxOption { + return func(s *exprCtxState) { s.defaultCollationForUTF8MB4 = collation } } -// WithBlockEncryptionMode sets the block encryption mode for `StaticExprContext`. -func WithBlockEncryptionMode(mode string) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithBlockEncryptionMode sets the block encryption mode for `ExprContext`. +func WithBlockEncryptionMode(mode string) ExprCtxOption { + return func(s *exprCtxState) { s.blockEncryptionMode = mode } } -// WithSysDateIsNow sets the sysdate is now for `StaticExprContext`. -func WithSysDateIsNow(now bool) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithSysDateIsNow sets the sysdate is now for `ExprContext`. +func WithSysDateIsNow(now bool) ExprCtxOption { + return func(s *exprCtxState) { s.sysDateIsNow = now } } -// WithNoopFuncsMode sets the noop funcs mode for `StaticExprContext`. -func WithNoopFuncsMode(mode int) StaticExprCtxOption { +// WithNoopFuncsMode sets the noop funcs mode for `ExprContext`. +func WithNoopFuncsMode(mode int) ExprCtxOption { intest.Assert(mode == variable.OnInt || mode == variable.OffInt || mode == variable.WarnInt) - return func(s *staticExprCtxState) { + return func(s *exprCtxState) { s.noopFuncsMode = mode } } -// WithRng sets the rng for `StaticExprContext`. -func WithRng(rng *mathutil.MysqlRng) StaticExprCtxOption { +// WithRng sets the rng for `ExprContext`. +func WithRng(rng *mathutil.MysqlRng) ExprCtxOption { intest.AssertNotNil(rng) - return func(s *staticExprCtxState) { + return func(s *exprCtxState) { s.rng = rng } } -// WithPlanCacheTracker sets the plan cache tracker for `StaticExprContext`. -func WithPlanCacheTracker(tracker *contextutil.PlanCacheTracker) StaticExprCtxOption { +// WithPlanCacheTracker sets the plan cache tracker for `ExprContext`. +func WithPlanCacheTracker(tracker *contextutil.PlanCacheTracker) ExprCtxOption { intest.AssertNotNil(tracker) - return func(s *staticExprCtxState) { + return func(s *exprCtxState) { s.planCacheTracker = tracker } } -// WithColumnIDAllocator sets the column id allocator for `StaticExprContext`. -func WithColumnIDAllocator(allocator exprctx.PlanColumnIDAllocator) StaticExprCtxOption { +// WithColumnIDAllocator sets the column id allocator for `ExprContext`. +func WithColumnIDAllocator(allocator exprctx.PlanColumnIDAllocator) ExprCtxOption { intest.AssertNotNil(allocator) - return func(s *staticExprCtxState) { + return func(s *exprCtxState) { s.columnIDAllocator = allocator } } -// WithConnectionID sets the connection id for `StaticExprContext`. -func WithConnectionID(id uint64) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithConnectionID sets the connection id for `ExprContext`. +func WithConnectionID(id uint64) ExprCtxOption { + return func(s *exprCtxState) { s.connectionID = id } } -// WithWindowingUseHighPrecision sets the windowing use high precision for `StaticExprContext`. -func WithWindowingUseHighPrecision(useHighPrecision bool) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithWindowingUseHighPrecision sets the windowing use high precision for `ExprContext`. +func WithWindowingUseHighPrecision(useHighPrecision bool) ExprCtxOption { + return func(s *exprCtxState) { s.windowingUseHighPrecision = useHighPrecision } } -// WithGroupConcatMaxLen sets the group concat max len for `StaticExprContext`. -func WithGroupConcatMaxLen(maxLen uint64) StaticExprCtxOption { - return func(s *staticExprCtxState) { +// WithGroupConcatMaxLen sets the group concat max len for `ExprContext`. +func WithGroupConcatMaxLen(maxLen uint64) ExprCtxOption { + return func(s *exprCtxState) { s.groupConcatMaxLen = maxLen } } -// StaticExprContext implements the `exprctx.ExprContext` interface. -// The "static" means comparing with `SessionExprContext`, its internal state does not relay on the session or other +// ExprContext implements the `exprctx.ExprContext` interface. +// The "static" means comparing with `ExprContext`, its internal state does not relay on the session or other // complex contexts that keeps immutable for most fields. -type StaticExprContext struct { - staticExprCtxState +type ExprContext struct { + exprCtxState } -// NewStaticExprContext creates a new StaticExprContext -func NewStaticExprContext(opts ...StaticExprCtxOption) *StaticExprContext { +// NewExprContext creates a new ExprContext +func NewExprContext(opts ...ExprCtxOption) *ExprContext { cs, err := charset.GetCharsetInfo(mysql.DefaultCharset) intest.AssertNoError(err) - ctx := &StaticExprContext{ - staticExprCtxState: staticExprCtxState{ + ctx := &ExprContext{ + exprCtxState: exprCtxState{ charset: cs.Name, collation: cs.DefaultCollation, defaultCollationForUTF8MB4: mysql.DefaultCollationName, @@ -165,11 +165,11 @@ func NewStaticExprContext(opts ...StaticExprCtxOption) *StaticExprContext { }, } for _, opt := range opts { - opt(&ctx.staticExprCtxState) + opt(&ctx.exprCtxState) } if ctx.evalCtx == nil { - ctx.evalCtx = NewStaticEvalContext() + ctx.evalCtx = NewEvalContext() } if ctx.rng == nil { @@ -189,121 +189,121 @@ func NewStaticExprContext(opts ...StaticExprCtxOption) *StaticExprContext { return ctx } -// Apply returns a new `StaticExprContext` with the fields updated according to the given options. -func (ctx *StaticExprContext) Apply(opts ...StaticExprCtxOption) *StaticExprContext { - newCtx := &StaticExprContext{ - staticExprCtxState: ctx.staticExprCtxState, +// Apply returns a new `ExprContext` with the fields updated according to the given options. +func (ctx *ExprContext) Apply(opts ...ExprCtxOption) *ExprContext { + newCtx := &ExprContext{ + exprCtxState: ctx.exprCtxState, } for _, opt := range opts { - opt(&newCtx.staticExprCtxState) + opt(&newCtx.exprCtxState) } return newCtx } // GetEvalCtx implements the `ExprContext.GetEvalCtx`. -func (ctx *StaticExprContext) GetEvalCtx() exprctx.EvalContext { +func (ctx *ExprContext) GetEvalCtx() exprctx.EvalContext { return ctx.evalCtx } -// GetStaticEvalCtx returns the inner `StaticEvalContext`. -func (ctx *StaticExprContext) GetStaticEvalCtx() *StaticEvalContext { +// GetStaticEvalCtx returns the inner `EvalContext`. +func (ctx *ExprContext) GetStaticEvalCtx() *EvalContext { return ctx.evalCtx } // GetCharsetInfo implements the `ExprContext.GetCharsetInfo`. -func (ctx *StaticExprContext) GetCharsetInfo() (string, string) { +func (ctx *ExprContext) GetCharsetInfo() (string, string) { return ctx.charset, ctx.collation } // GetDefaultCollationForUTF8MB4 implements the `ExprContext.GetDefaultCollationForUTF8MB4`. -func (ctx *StaticExprContext) GetDefaultCollationForUTF8MB4() string { +func (ctx *ExprContext) GetDefaultCollationForUTF8MB4() string { return ctx.defaultCollationForUTF8MB4 } // GetBlockEncryptionMode implements the `ExprContext.GetBlockEncryptionMode`. -func (ctx *StaticExprContext) GetBlockEncryptionMode() string { +func (ctx *ExprContext) GetBlockEncryptionMode() string { return ctx.blockEncryptionMode } // GetSysdateIsNow implements the `ExprContext.GetSysdateIsNow`. -func (ctx *StaticExprContext) GetSysdateIsNow() bool { +func (ctx *ExprContext) GetSysdateIsNow() bool { return ctx.sysDateIsNow } // GetNoopFuncsMode implements the `ExprContext.GetNoopFuncsMode`. -func (ctx *StaticExprContext) GetNoopFuncsMode() int { +func (ctx *ExprContext) GetNoopFuncsMode() int { return ctx.noopFuncsMode } // Rng implements the `ExprContext.Rng`. -func (ctx *StaticExprContext) Rng() *mathutil.MysqlRng { +func (ctx *ExprContext) Rng() *mathutil.MysqlRng { return ctx.rng } // IsUseCache implements the `ExprContext.IsUseCache`. -func (ctx *StaticExprContext) IsUseCache() bool { +func (ctx *ExprContext) IsUseCache() bool { return ctx.planCacheTracker.UseCache() } // SetSkipPlanCache implements the `ExprContext.SetSkipPlanCache`. -func (ctx *StaticExprContext) SetSkipPlanCache(reason string) { +func (ctx *ExprContext) SetSkipPlanCache(reason string) { ctx.planCacheTracker.SetSkipPlanCache(reason) } // AllocPlanColumnID implements the `ExprContext.AllocPlanColumnID`. -func (ctx *StaticExprContext) AllocPlanColumnID() int64 { +func (ctx *ExprContext) AllocPlanColumnID() int64 { return ctx.columnIDAllocator.AllocPlanColumnID() } // IsInNullRejectCheck implements the `ExprContext.IsInNullRejectCheck` and should always return false. -func (ctx *StaticExprContext) IsInNullRejectCheck() bool { +func (ctx *ExprContext) IsInNullRejectCheck() bool { return false } // IsConstantPropagateCheck implements the `ExprContext.IsConstantPropagateCheck` and should always return false. -func (ctx *StaticExprContext) IsConstantPropagateCheck() bool { +func (ctx *ExprContext) IsConstantPropagateCheck() bool { return false } // ConnectionID implements the `ExprContext.ConnectionID`. -func (ctx *StaticExprContext) ConnectionID() uint64 { +func (ctx *ExprContext) ConnectionID() uint64 { return ctx.connectionID } // GetWindowingUseHighPrecision implements the `ExprContext.GetWindowingUseHighPrecision`. -func (ctx *StaticExprContext) GetWindowingUseHighPrecision() bool { +func (ctx *ExprContext) GetWindowingUseHighPrecision() bool { return ctx.windowingUseHighPrecision } // GetGroupConcatMaxLen implements the `ExprContext.GetGroupConcatMaxLen`. -func (ctx *StaticExprContext) GetGroupConcatMaxLen() uint64 { +func (ctx *ExprContext) GetGroupConcatMaxLen() uint64 { return ctx.groupConcatMaxLen } -var _ exprctx.StaticConvertibleExprContext = &StaticExprContext{} +var _ exprctx.StaticConvertibleExprContext = &ExprContext{} // GetLastPlanColumnID implements context.StaticConvertibleExprContext. -func (ctx *StaticExprContext) GetLastPlanColumnID() int64 { +func (ctx *ExprContext) GetLastPlanColumnID() int64 { return ctx.columnIDAllocator.GetLastPlanColumnID() } // GetPlanCacheTracker implements context.StaticConvertibleExprContext. -func (ctx *StaticExprContext) GetPlanCacheTracker() *contextutil.PlanCacheTracker { +func (ctx *ExprContext) GetPlanCacheTracker() *contextutil.PlanCacheTracker { return ctx.planCacheTracker } // GetStaticConvertibleEvalContext implements context.StaticConvertibleExprContext. -func (ctx *StaticExprContext) GetStaticConvertibleEvalContext() exprctx.StaticConvertibleEvalContext { +func (ctx *ExprContext) GetStaticConvertibleEvalContext() exprctx.StaticConvertibleEvalContext { return ctx.evalCtx } -// MakeExprContextStatic converts the `exprctx.StaticConvertibleExprContext` to `StaticExprContext`. -func MakeExprContextStatic(ctx exprctx.StaticConvertibleExprContext) *StaticExprContext { +// MakeExprContextStatic converts the `exprctx.StaticConvertibleExprContext` to `ExprContext`. +func MakeExprContextStatic(ctx exprctx.StaticConvertibleExprContext) *ExprContext { staticEvalContext := MakeEvalContextStatic(ctx.GetStaticConvertibleEvalContext()) - return NewStaticExprContext( + return NewExprContext( WithEvalCtx(staticEvalContext), WithCharset(ctx.GetCharsetInfo()), WithDefaultCollationForUTF8MB4(ctx.GetDefaultCollationForUTF8MB4()), @@ -320,8 +320,8 @@ func MakeExprContextStatic(ctx exprctx.StaticConvertibleExprContext) *StaticExpr ) } -// LoadSystemVars loads system variables and returns a new `StaticEvalContext` with system variables loaded. -func (ctx *StaticExprContext) LoadSystemVars(sysVars map[string]string) (*StaticExprContext, error) { +// LoadSystemVars loads system variables and returns a new `EvalContext` with system variables loaded. +func (ctx *ExprContext) LoadSystemVars(sysVars map[string]string) (*ExprContext, error) { sessionVars, err := newSessionVarsWithSystemVariables(sysVars) if err != nil { return nil, err @@ -329,10 +329,10 @@ func (ctx *StaticExprContext) LoadSystemVars(sysVars map[string]string) (*Static return ctx.loadSessionVarsInternal(sessionVars, sysVars), nil } -func (ctx *StaticExprContext) loadSessionVarsInternal( +func (ctx *ExprContext) loadSessionVarsInternal( sessionVars *variable.SessionVars, sysVars map[string]string, -) *StaticExprContext { - opts := make([]StaticExprCtxOption, 0, 8) +) *ExprContext { + opts := make([]ExprCtxOption, 0, 8) opts = append(opts, WithEvalCtx(ctx.evalCtx.loadSessionVarsInternal(sessionVars, sysVars))) for name := range sysVars { name = strings.ToLower(name) diff --git a/pkg/expression/contextstatic/exprctx_test.go b/pkg/expression/exprstatic/exprctx_test.go similarity index 85% rename from pkg/expression/contextstatic/exprctx_test.go rename to pkg/expression/exprstatic/exprctx_test.go index 2f8df2da49c16..0e1f97c7f8ba0 100644 --- a/pkg/expression/contextstatic/exprctx_test.go +++ b/pkg/expression/exprstatic/exprctx_test.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextstatic +package exprstatic import ( "strings" "testing" "time" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/variable" @@ -31,17 +31,17 @@ import ( func TestNewStaticExprCtx(t *testing.T) { prevID := contextutil.GenContextID() - ctx := NewStaticExprContext() + ctx := NewExprContext() require.Equal(t, ctx.GetEvalCtx().CtxID(), prevID+1) checkDefaultStaticExprCtx(t, ctx) opts, s := getExprCtxOptionsForTest() - ctx = NewStaticExprContext(opts...) + ctx = NewExprContext(opts...) checkOptionsStaticExprCtx(t, ctx, s) } func TestStaticExprCtxApplyOptions(t *testing.T) { - ctx := NewStaticExprContext() + ctx := NewExprContext() oldEvalCtx := ctx.evalCtx oldColumnIDAllocator := ctx.columnIDAllocator @@ -59,8 +59,8 @@ func TestStaticExprCtxApplyOptions(t *testing.T) { checkOptionsStaticExprCtx(t, ctx3, s) } -func checkDefaultStaticExprCtx(t *testing.T, ctx *StaticExprContext) { - checkDefaultStaticEvalCtx(t, ctx.GetEvalCtx().(*StaticEvalContext)) +func checkDefaultStaticExprCtx(t *testing.T, ctx *ExprContext) { + checkDefaultStaticEvalCtx(t, ctx.GetEvalCtx().(*EvalContext)) charsetName, collation := ctx.GetCharsetInfo() require.Equal(t, mysql.DefaultCharset, charsetName) cs, err := charset.GetCharsetInfo(charsetName) @@ -82,21 +82,21 @@ func checkDefaultStaticExprCtx(t *testing.T, ctx *StaticExprContext) { } type exprCtxOptionsTestState struct { - evalCtx *StaticEvalContext + evalCtx *EvalContext colIDAlloc exprctx.PlanColumnIDAllocator rng *mathutil.MysqlRng skipCacheArgs []any } -func getExprCtxOptionsForTest() ([]StaticExprCtxOption, *exprCtxOptionsTestState) { +func getExprCtxOptionsForTest() ([]ExprCtxOption, *exprCtxOptionsTestState) { s := &exprCtxOptionsTestState{ - evalCtx: NewStaticEvalContext(WithLocation(time.FixedZone("UTC+11", 11*3600))), + evalCtx: NewEvalContext(WithLocation(time.FixedZone("UTC+11", 11*3600))), colIDAlloc: exprctx.NewSimplePlanColumnIDAllocator(1024), rng: mathutil.NewWithSeed(12345678), } planCacheTracker := contextutil.NewPlanCacheTracker(s.evalCtx) - return []StaticExprCtxOption{ + return []ExprCtxOption{ WithEvalCtx(s.evalCtx), WithCharset("gbk", "gbk_bin"), WithDefaultCollationForUTF8MB4("utf8mb4_0900_ai_ci"), @@ -112,7 +112,7 @@ func getExprCtxOptionsForTest() ([]StaticExprCtxOption, *exprCtxOptionsTestState }, s } -func checkOptionsStaticExprCtx(t *testing.T, ctx *StaticExprContext, s *exprCtxOptionsTestState) { +func checkOptionsStaticExprCtx(t *testing.T, ctx *ExprContext, s *exprCtxOptionsTestState) { require.Same(t, s.evalCtx, ctx.GetEvalCtx()) cs, collation := ctx.GetCharsetInfo() require.Equal(t, "gbk", cs) @@ -133,7 +133,7 @@ func checkOptionsStaticExprCtx(t *testing.T, ctx *StaticExprContext, s *exprCtxO func TestExprCtxColumnIDAllocator(t *testing.T) { // default - ctx := NewStaticExprContext() + ctx := NewExprContext() alloc := ctx.columnIDAllocator require.NotNil(t, alloc) _, ok := ctx.columnIDAllocator.(*exprctx.SimplePlanColumnIDAllocator) @@ -156,15 +156,15 @@ func TestExprCtxColumnIDAllocator(t *testing.T) { // New context with allocator alloc = exprctx.NewSimplePlanColumnIDAllocator(2048) - ctx4 := NewStaticExprContext(WithColumnIDAllocator(alloc)) + ctx4 := NewExprContext(WithColumnIDAllocator(alloc)) require.Same(t, alloc, ctx4.columnIDAllocator) require.Equal(t, int64(2049), ctx4.AllocPlanColumnID()) } func TestMakeExprContextStatic(t *testing.T) { - evalCtx := NewStaticEvalContext() + evalCtx := NewEvalContext() planCacheTracker := contextutil.NewPlanCacheTracker(evalCtx.warnHandler) - obj := NewStaticExprContext( + obj := NewExprContext( WithEvalCtx(evalCtx), WithCharset("a", "b"), WithDefaultCollationForUTF8MB4("c"), @@ -180,13 +180,13 @@ func TestMakeExprContextStatic(t *testing.T) { ) ignorePath := []string{ - "$.staticExprCtxState.evalCtx**", + "$.exprCtxState.evalCtx**", } - deeptest.AssertRecursivelyNotEqual(t, obj, NewStaticExprContext(), + deeptest.AssertRecursivelyNotEqual(t, obj, NewExprContext(), deeptest.WithIgnorePath(ignorePath), deeptest.WithPointerComparePath([]string{ - "$.staticExprCtxState.rng", - "$.staticExprCtxState.planCacheTracker", + "$.exprCtxState.rng", + "$.exprCtxState.planCacheTracker", }), ) @@ -194,8 +194,8 @@ func TestMakeExprContextStatic(t *testing.T) { deeptest.AssertDeepClonedEqual(t, obj, staticObj, deeptest.WithIgnorePath(ignorePath), deeptest.WithPointerComparePath([]string{ - "$.staticExprCtxState.rng", - "$.staticExprCtxState.planCacheTracker", + "$.exprCtxState.rng", + "$.exprCtxState.planCacheTracker", })) require.NotSame(t, obj.GetEvalCtx(), staticObj.GetEvalCtx()) @@ -206,13 +206,13 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name string val string field string - assert func(ctx *StaticExprContext, vars *variable.SessionVars) + assert func(ctx *ExprContext, vars *variable.SessionVars) }{ { name: "character_set_connection", val: "gbk", field: "$.charset", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { cs, _ := ctx.GetCharsetInfo() require.Equal(t, "gbk", cs) cs2, _ := vars.GetCharsetInfo() @@ -223,7 +223,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "collation_connection", val: "gbk_chinese_ci", field: "$.collation", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { _, coll := ctx.GetCharsetInfo() require.Equal(t, "gbk_chinese_ci", coll) _, coll2 := vars.GetCharsetInfo() @@ -234,7 +234,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "default_collation_for_utf8mb4", val: "utf8mb4_general_ci", field: "$.defaultCollationForUTF8MB4", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.Equal(t, "utf8mb4_general_ci", ctx.GetDefaultCollationForUTF8MB4()) require.Equal(t, vars.DefaultCollationForUTF8MB4, ctx.GetDefaultCollationForUTF8MB4()) }, @@ -243,7 +243,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: strings.ToUpper("tidb_sysdate_is_now"), // test for settings an upper case variable val: "1", field: "$.sysDateIsNow", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.True(t, ctx.GetSysdateIsNow()) require.Equal(t, vars.SysdateIsNow, ctx.GetSysdateIsNow()) }, @@ -252,7 +252,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "tidb_enable_noop_functions", val: "warn", field: "$.noopFuncsMode", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.Equal(t, variable.WarnInt, ctx.GetNoopFuncsMode()) require.Equal(t, vars.NoopFuncsMode, ctx.GetNoopFuncsMode()) }, @@ -261,7 +261,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "block_encryption_mode", val: "aes-256-cbc", field: "$.blockEncryptionMode", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.Equal(t, "aes-256-cbc", ctx.GetBlockEncryptionMode()) blockMode, _ := vars.GetSystemVar(variable.BlockEncryptionMode) require.Equal(t, blockMode, ctx.GetBlockEncryptionMode()) @@ -271,7 +271,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "group_concat_max_len", val: "123456", field: "$.groupConcatMaxLen", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.Equal(t, uint64(123456), ctx.GetGroupConcatMaxLen()) require.Equal(t, vars.GroupConcatMaxLen, ctx.GetGroupConcatMaxLen()) }, @@ -280,7 +280,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { name: "windowing_use_high_precision", val: "0", field: "$.windowingUseHighPrecision", - assert: func(ctx *StaticExprContext, vars *variable.SessionVars) { + assert: func(ctx *ExprContext, vars *variable.SessionVars) { require.False(t, ctx.GetWindowingUseHighPrecision()) require.Equal(t, vars.WindowingUseHighPrecision, ctx.GetWindowingUseHighPrecision()) }, @@ -309,7 +309,7 @@ func TestExprCtxLoadSystemVars(t *testing.T) { require.NoError(t, sessionVars.SetSystemVar(sysVar.name, sysVar.val)) } - defaultCtx := NewStaticExprContext() + defaultCtx := NewExprContext() ctx, err := defaultCtx.LoadSystemVars(varsMap) require.NoError(t, err) @@ -317,8 +317,8 @@ func TestExprCtxLoadSystemVars(t *testing.T) { // all system variables related fields are covered in the test list. deeptest.AssertRecursivelyNotEqual( t, - defaultCtx.staticExprCtxState, - ctx.staticExprCtxState, + defaultCtx.exprCtxState, + ctx.exprCtxState, // ignore `evalCtx` because we'll test it standalone. deeptest.WithIgnorePath(append(nonVarRelatedFields, "$.evalCtx")), ) @@ -327,8 +327,8 @@ func TestExprCtxLoadSystemVars(t *testing.T) { // not inherited from the empty go value. deeptest.AssertRecursivelyNotEqual( t, - staticExprCtxState{}, - ctx.staticExprCtxState, + exprCtxState{}, + ctx.exprCtxState, // ignore `windowingUseHighPrecision` because we set it to `false` in test case. deeptest.WithIgnorePath(append(nonVarRelatedFields, "$.evalCtx", "$.windowingUseHighPrecision")), ) @@ -336,8 +336,8 @@ func TestExprCtxLoadSystemVars(t *testing.T) { // Check all system vars unrelated fields are not changed after `LoadSystemVars`. deeptest.AssertDeepClonedEqual( t, - defaultCtx.staticExprCtxState, - ctx.staticExprCtxState, + defaultCtx.exprCtxState, + ctx.exprCtxState, deeptest.WithIgnorePath(append(varsRelatedFields, "$.evalCtx")), // LoadSystemVars only does shallow copy for `EvalContext` so we just need to compare the pointers. deeptest.WithPointerComparePath(nonVarRelatedFields), diff --git a/pkg/expression/extension.go b/pkg/expression/extension.go index 206ebf9e89b2c..4fc0f5ea0f074 100644 --- a/pkg/expression/extension.go +++ b/pkg/expression/extension.go @@ -20,7 +20,7 @@ import ( "sync" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/extension" "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -146,7 +146,7 @@ var _ extension.FunctionContext = extensionFnContext{} type extensionFuncSig struct { baseBuiltinFunc - contextopt.SessionVarsPropReader + expropt.SessionVarsPropReader extension.FunctionDef } diff --git a/pkg/expression/grouping_sets_test.go b/pkg/expression/grouping_sets_test.go index 8ccec290559a4..0b76990b7e91e 100644 --- a/pkg/expression/grouping_sets_test.go +++ b/pkg/expression/grouping_sets_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" @@ -312,7 +312,7 @@ func TestGroupingSetsMergeUnitTest(t *testing.T) { func TestDistinctGroupingSets(t *testing.T) { defer view.Stop() - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() // premise: every grouping item in grouping sets should be a col. a := &Column{ diff --git a/pkg/expression/scalar_function.go b/pkg/expression/scalar_function.go index c0918e878ad11..fb032fe849c9c 100644 --- a/pkg/expression/scalar_function.go +++ b/pkg/expression/scalar_function.go @@ -21,7 +21,7 @@ import ( "unsafe" "github.com/pingcap/errors" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" diff --git a/pkg/expression/contextsession/BUILD.bazel b/pkg/expression/sessionexpr/BUILD.bazel similarity index 77% rename from pkg/expression/contextsession/BUILD.bazel rename to pkg/expression/sessionexpr/BUILD.bazel index e333ef78b8d3b..dab3390872cb0 100644 --- a/pkg/expression/contextsession/BUILD.bazel +++ b/pkg/expression/sessionexpr/BUILD.bazel @@ -1,15 +1,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "contextsession", + name = "sessionexpr", srcs = ["sessionctx.go"], - importpath = "github.com/pingcap/tidb/pkg/expression/contextsession", + importpath = "github.com/pingcap/tidb/pkg/expression/sessionexpr", visibility = ["//visibility:public"], deps = [ "//pkg/errctx", - "//pkg/expression/context", - "//pkg/expression/contextopt", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/expropt", + "//pkg/expression/exprstatic", "//pkg/infoschema/context", "//pkg/parser/auth", "//pkg/parser/model", @@ -29,16 +29,16 @@ go_library( ) go_test( - name = "contextsession_test", + name = "sessionexpr_test", timeout = "short", srcs = ["sessionctx_test.go"], flaky = True, shard_count = 5, deps = [ - ":contextsession", + ":sessionexpr", "//pkg/errctx", - "//pkg/expression/context", - "//pkg/expression/contextopt", + "//pkg/expression/exprctx", + "//pkg/expression/expropt", "//pkg/parser/auth", "//pkg/parser/mysql", "//pkg/privilege", diff --git a/pkg/expression/contextsession/sessionctx.go b/pkg/expression/sessionexpr/sessionctx.go similarity index 65% rename from pkg/expression/contextsession/sessionctx.go rename to pkg/expression/sessionexpr/sessionctx.go index 84c766636dc9a..d75f9ff8661c6 100644 --- a/pkg/expression/contextsession/sessionctx.go +++ b/pkg/expression/sessionexpr/sessionctx.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextsession +package sessionexpr import ( "context" @@ -20,9 +20,9 @@ import ( "time" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" + "github.com/pingcap/tidb/pkg/expression/exprstatic" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/model" @@ -40,132 +40,132 @@ import ( "go.uber.org/zap" ) -// SessionExprContext should implement the `ExprContext` interface. -var _ exprctx.ExprContext = &SessionExprContext{} +// ExprContext should implement the `ExprContext` interface. +var _ exprctx.ExprContext = &ExprContext{} -// SessionExprContext implements `ExprContext` -type SessionExprContext struct { +// ExprContext implements `ExprContext` +type ExprContext struct { sctx sessionctx.Context - *SessionEvalContext + *EvalContext } -// NewSessionExprContext creates a new SessionExprContext. -func NewSessionExprContext(sctx sessionctx.Context) *SessionExprContext { - return &SessionExprContext{ - sctx: sctx, - SessionEvalContext: NewSessionEvalContext(sctx), +// NewExprContext creates a new ExprContext. +func NewExprContext(sctx sessionctx.Context) *ExprContext { + return &ExprContext{ + sctx: sctx, + EvalContext: NewEvalContext(sctx), } } // GetEvalCtx returns the EvalContext. -func (ctx *SessionExprContext) GetEvalCtx() exprctx.EvalContext { - return ctx.SessionEvalContext +func (ctx *ExprContext) GetEvalCtx() exprctx.EvalContext { + return ctx.EvalContext } // GetCharsetInfo gets charset and collation for current context. -func (ctx *SessionExprContext) GetCharsetInfo() (string, string) { +func (ctx *ExprContext) GetCharsetInfo() (string, string) { return ctx.sctx.GetSessionVars().GetCharsetInfo() } // GetDefaultCollationForUTF8MB4 returns the default collation of UTF8MB4. -func (ctx *SessionExprContext) GetDefaultCollationForUTF8MB4() string { +func (ctx *ExprContext) GetDefaultCollationForUTF8MB4() string { return ctx.sctx.GetSessionVars().DefaultCollationForUTF8MB4 } // GetBlockEncryptionMode returns the variable block_encryption_mode -func (ctx *SessionExprContext) GetBlockEncryptionMode() string { +func (ctx *ExprContext) GetBlockEncryptionMode() string { blockMode, _ := ctx.sctx.GetSessionVars().GetSystemVar(variable.BlockEncryptionMode) return blockMode } // GetSysdateIsNow returns a bool to determine whether Sysdate is an alias of Now function. // It is the value of variable `tidb_sysdate_is_now`. -func (ctx *SessionExprContext) GetSysdateIsNow() bool { +func (ctx *ExprContext) GetSysdateIsNow() bool { return ctx.sctx.GetSessionVars().SysdateIsNow } // GetNoopFuncsMode returns the noop function mode: OFF/ON/WARN values as 0/1/2. -func (ctx *SessionExprContext) GetNoopFuncsMode() int { +func (ctx *ExprContext) GetNoopFuncsMode() int { return ctx.sctx.GetSessionVars().NoopFuncsMode } // Rng is used to generate random values. -func (ctx *SessionExprContext) Rng() *mathutil.MysqlRng { +func (ctx *ExprContext) Rng() *mathutil.MysqlRng { return ctx.sctx.GetSessionVars().Rng } // IsUseCache indicates whether to cache the build expression in plan cache. // If SetSkipPlanCache is invoked, it should return false. -func (ctx *SessionExprContext) IsUseCache() bool { +func (ctx *ExprContext) IsUseCache() bool { return ctx.sctx.GetSessionVars().StmtCtx.UseCache() } // SetSkipPlanCache sets to skip the plan cache and records the reason. -func (ctx *SessionExprContext) SetSkipPlanCache(reason string) { +func (ctx *ExprContext) SetSkipPlanCache(reason string) { ctx.sctx.GetSessionVars().StmtCtx.SetSkipPlanCache(reason) } // AllocPlanColumnID allocates column id for plan. -func (ctx *SessionExprContext) AllocPlanColumnID() int64 { +func (ctx *ExprContext) AllocPlanColumnID() int64 { return ctx.sctx.GetSessionVars().AllocPlanColumnID() } // IsInNullRejectCheck returns whether the expression is in null reject check. -func (ctx *SessionExprContext) IsInNullRejectCheck() bool { +func (ctx *ExprContext) IsInNullRejectCheck() bool { return false } // IsConstantPropagateCheck returns whether the ctx is in constant propagate check. -func (ctx *SessionExprContext) IsConstantPropagateCheck() bool { +func (ctx *ExprContext) IsConstantPropagateCheck() bool { return false } // GetWindowingUseHighPrecision determines whether to compute window operations without loss of precision. // see https://dev.mysql.com/doc/refman/8.0/en/window-function-optimization.html for more details. -func (ctx *SessionExprContext) GetWindowingUseHighPrecision() bool { +func (ctx *ExprContext) GetWindowingUseHighPrecision() bool { return ctx.sctx.GetSessionVars().WindowingUseHighPrecision } // GetGroupConcatMaxLen returns the value of the 'group_concat_max_len' system variable. -func (ctx *SessionExprContext) GetGroupConcatMaxLen() uint64 { +func (ctx *ExprContext) GetGroupConcatMaxLen() uint64 { return ctx.sctx.GetSessionVars().GroupConcatMaxLen } // ConnectionID indicates the connection ID of the current session. // If the context is not in a session, it should return 0. -func (ctx *SessionExprContext) ConnectionID() uint64 { +func (ctx *ExprContext) ConnectionID() uint64 { return ctx.sctx.GetSessionVars().ConnectionID } -// IntoStatic turns the SessionExprContext into a StaticExprContext. -func (ctx *SessionExprContext) IntoStatic() *contextstatic.StaticExprContext { - return contextstatic.MakeExprContextStatic(ctx) +// IntoStatic turns the ExprContext into a ExprContext. +func (ctx *ExprContext) IntoStatic() *exprstatic.ExprContext { + return exprstatic.MakeExprContextStatic(ctx) } -// SessionEvalContext implements the `expression.EvalContext` interface to provide evaluation context in session. -type SessionEvalContext struct { +// EvalContext implements the `expression.EvalContext` interface to provide evaluation context in session. +type EvalContext struct { sctx sessionctx.Context - props contextopt.OptionalEvalPropProviders + props expropt.OptionalEvalPropProviders } -// NewSessionEvalContext creates a new SessionEvalContext. -func NewSessionEvalContext(sctx sessionctx.Context) *SessionEvalContext { - ctx := &SessionEvalContext{sctx: sctx} +// NewEvalContext creates a new EvalContext. +func NewEvalContext(sctx sessionctx.Context) *EvalContext { + ctx := &EvalContext{sctx: sctx} // set all optional properties ctx.setOptionalProp(currentUserProp(sctx)) - ctx.setOptionalProp(contextopt.NewSessionVarsProvider(sctx)) + ctx.setOptionalProp(expropt.NewSessionVarsProvider(sctx)) ctx.setOptionalProp(infoSchemaProp(sctx)) - ctx.setOptionalProp(contextopt.KVStorePropProvider(sctx.GetStore)) + ctx.setOptionalProp(expropt.KVStorePropProvider(sctx.GetStore)) ctx.setOptionalProp(sqlExecutorProp(sctx)) ctx.setOptionalProp(sequenceOperatorProp(sctx)) - ctx.setOptionalProp(contextopt.NewAdvisoryLockPropProvider(sctx)) - ctx.setOptionalProp(contextopt.DDLOwnerInfoProvider(sctx.IsDDLOwner)) + ctx.setOptionalProp(expropt.NewAdvisoryLockPropProvider(sctx)) + ctx.setOptionalProp(expropt.DDLOwnerInfoProvider(sctx.IsDDLOwner)) // When EvalContext is created from a session, it should contain all the optional properties. intest.Assert(ctx.props.PropKeySet().IsFull()) return ctx } -func (ctx *SessionEvalContext) setOptionalProp(prop exprctx.OptionalEvalPropProvider) { +func (ctx *EvalContext) setOptionalProp(prop exprctx.OptionalEvalPropProvider) { intest.AssertFunc(func() bool { return !ctx.props.Contains(prop.Desc().Key()) }) @@ -173,22 +173,22 @@ func (ctx *SessionEvalContext) setOptionalProp(prop exprctx.OptionalEvalPropProv } // Sctx returns the innert session context -func (ctx *SessionEvalContext) Sctx() sessionctx.Context { +func (ctx *EvalContext) Sctx() sessionctx.Context { return ctx.sctx } // CtxID returns the context id. -func (ctx *SessionEvalContext) CtxID() uint64 { +func (ctx *EvalContext) CtxID() uint64 { return ctx.sctx.GetSessionVars().StmtCtx.CtxID() } // SQLMode returns the sql mode -func (ctx *SessionEvalContext) SQLMode() mysql.SQLMode { +func (ctx *EvalContext) SQLMode() mysql.SQLMode { return ctx.sctx.GetSessionVars().SQLMode } // TypeCtx returns the types.Context -func (ctx *SessionEvalContext) TypeCtx() (tc types.Context) { +func (ctx *EvalContext) TypeCtx() (tc types.Context) { tc = ctx.sctx.GetSessionVars().StmtCtx.TypeCtx() if intest.InTest { exprctx.AssertLocationWithSessionVars(tc.Location(), ctx.sctx.GetSessionVars()) @@ -197,58 +197,58 @@ func (ctx *SessionEvalContext) TypeCtx() (tc types.Context) { } // ErrCtx returns the errctx.Context -func (ctx *SessionEvalContext) ErrCtx() errctx.Context { +func (ctx *EvalContext) ErrCtx() errctx.Context { return ctx.sctx.GetSessionVars().StmtCtx.ErrCtx() } // Location returns the timezone info -func (ctx *SessionEvalContext) Location() *time.Location { +func (ctx *EvalContext) Location() *time.Location { tc := ctx.TypeCtx() return tc.Location() } // AppendWarning append warnings to the context. -func (ctx *SessionEvalContext) AppendWarning(err error) { +func (ctx *EvalContext) AppendWarning(err error) { ctx.sctx.GetSessionVars().StmtCtx.AppendWarning(err) } // WarningCount gets warning count. -func (ctx *SessionEvalContext) WarningCount() int { +func (ctx *EvalContext) WarningCount() int { return int(ctx.sctx.GetSessionVars().StmtCtx.WarningCount()) } // TruncateWarnings truncates warnings begin from start and returns the truncated warnings. -func (ctx *SessionEvalContext) TruncateWarnings(start int) []contextutil.SQLWarn { +func (ctx *EvalContext) TruncateWarnings(start int) []contextutil.SQLWarn { return ctx.sctx.GetSessionVars().StmtCtx.TruncateWarnings(start) } // CopyWarnings copies the warnings to dst -func (ctx *SessionEvalContext) CopyWarnings(dst []contextutil.SQLWarn) []contextutil.SQLWarn { +func (ctx *EvalContext) CopyWarnings(dst []contextutil.SQLWarn) []contextutil.SQLWarn { return ctx.sctx.GetSessionVars().StmtCtx.CopyWarnings(dst) } // CurrentDB returns the current database name -func (ctx *SessionEvalContext) CurrentDB() string { +func (ctx *EvalContext) CurrentDB() string { return ctx.sctx.GetSessionVars().CurrentDB } // CurrentTime returns the current time -func (ctx *SessionEvalContext) CurrentTime() (time.Time, error) { +func (ctx *EvalContext) CurrentTime() (time.Time, error) { return getStmtTimestamp(ctx.sctx) } // GetMaxAllowedPacket returns the value of the 'max_allowed_packet' system variable. -func (ctx *SessionEvalContext) GetMaxAllowedPacket() uint64 { +func (ctx *EvalContext) GetMaxAllowedPacket() uint64 { return ctx.sctx.GetSessionVars().MaxAllowedPacket } // GetTiDBRedactLog returns the value of the 'tidb_redact_log' system variable. -func (ctx *SessionEvalContext) GetTiDBRedactLog() string { +func (ctx *EvalContext) GetTiDBRedactLog() string { return ctx.sctx.GetSessionVars().EnableRedactLog } // GetDefaultWeekFormatMode returns the value of the 'default_week_format' system variable. -func (ctx *SessionEvalContext) GetDefaultWeekFormatMode() string { +func (ctx *EvalContext) GetDefaultWeekFormatMode() string { mode, ok := ctx.sctx.GetSessionVars().GetSystemVar(variable.DefaultWeekFormat) if !ok || mode == "" { return "0" @@ -257,22 +257,22 @@ func (ctx *SessionEvalContext) GetDefaultWeekFormatMode() string { } // GetDivPrecisionIncrement returns the specified value of DivPrecisionIncrement. -func (ctx *SessionEvalContext) GetDivPrecisionIncrement() int { +func (ctx *EvalContext) GetDivPrecisionIncrement() int { return ctx.sctx.GetSessionVars().GetDivPrecisionIncrement() } // GetOptionalPropSet gets the optional property set from context -func (ctx *SessionEvalContext) GetOptionalPropSet() exprctx.OptionalEvalPropKeySet { +func (ctx *EvalContext) GetOptionalPropSet() exprctx.OptionalEvalPropKeySet { return ctx.props.PropKeySet() } // GetOptionalPropProvider gets the optional property provider by key -func (ctx *SessionEvalContext) GetOptionalPropProvider(key exprctx.OptionalEvalPropKey) (exprctx.OptionalEvalPropProvider, bool) { +func (ctx *EvalContext) GetOptionalPropProvider(key exprctx.OptionalEvalPropKey) (exprctx.OptionalEvalPropProvider, bool) { return ctx.props.Get(key) } // RequestVerification verifies user privilege -func (ctx *SessionEvalContext) RequestVerification(db, table, column string, priv mysql.PrivilegeType) bool { +func (ctx *EvalContext) RequestVerification(db, table, column string, priv mysql.PrivilegeType) bool { checker := privilege.GetPrivilegeManager(ctx.sctx) if checker == nil { return true @@ -281,7 +281,7 @@ func (ctx *SessionEvalContext) RequestVerification(db, table, column string, pri } // RequestDynamicVerification verifies user privilege for a DYNAMIC privilege. -func (ctx *SessionEvalContext) RequestDynamicVerification(privName string, grantable bool) bool { +func (ctx *EvalContext) RequestDynamicVerification(privName string, grantable bool) bool { checker := privilege.GetPrivilegeManager(ctx.sctx) if checker == nil { return true @@ -290,7 +290,7 @@ func (ctx *SessionEvalContext) RequestDynamicVerification(privName string, grant } // GetParamValue returns the value of the parameter by index. -func (ctx *SessionEvalContext) GetParamValue(idx int) (types.Datum, error) { +func (ctx *EvalContext) GetParamValue(idx int) (types.Datum, error) { params := ctx.sctx.GetSessionVars().PlanCacheParams.AllParamValues() if idx >= len(params) { return types.Datum{}, exprctx.ErrParamIndexExceedParamCounts @@ -299,13 +299,13 @@ func (ctx *SessionEvalContext) GetParamValue(idx int) (types.Datum, error) { } // GetUserVarsReader returns the user variables. -func (ctx *SessionEvalContext) GetUserVarsReader() variable.UserVarsReader { +func (ctx *EvalContext) GetUserVarsReader() variable.UserVarsReader { return ctx.sctx.GetSessionVars().UserVars } -// IntoStatic turns the SessionEvalContext into a StaticEvalContext. -func (ctx *SessionEvalContext) IntoStatic() *contextstatic.StaticEvalContext { - return contextstatic.MakeEvalContextStatic(ctx) +// IntoStatic turns the EvalContext into a EvalContext. +func (ctx *EvalContext) IntoStatic() *exprstatic.EvalContext { + return exprstatic.MakeEvalContextStatic(ctx) } func getStmtTimestamp(ctx sessionctx.Context) (time.Time, error) { @@ -339,13 +339,13 @@ func getStmtTimestamp(ctx sessionctx.Context) (time.Time, error) { } func currentUserProp(sctx sessionctx.Context) exprctx.OptionalEvalPropProvider { - return contextopt.CurrentUserPropProvider(func() (*auth.UserIdentity, []*auth.RoleIdentity) { + return expropt.CurrentUserPropProvider(func() (*auth.UserIdentity, []*auth.RoleIdentity) { vars := sctx.GetSessionVars() return vars.User, vars.ActiveRoles }) } -func infoSchemaProp(sctx sessionctx.Context) contextopt.InfoSchemaPropProvider { +func infoSchemaProp(sctx sessionctx.Context) expropt.InfoSchemaPropProvider { return func(isDomain bool) infoschema.MetaOnlyInfoSchema { if isDomain { return sctx.GetDomainInfoSchema() @@ -354,8 +354,8 @@ func infoSchemaProp(sctx sessionctx.Context) contextopt.InfoSchemaPropProvider { } } -func sqlExecutorProp(sctx sessionctx.Context) contextopt.SQLExecutorPropProvider { - return func() (contextopt.SQLExecutor, error) { +func sqlExecutorProp(sctx sessionctx.Context) expropt.SQLExecutorPropProvider { + return func() (expropt.SQLExecutor, error) { return sctx.GetRestrictedSQLExecutor(), nil } } @@ -379,8 +379,8 @@ func (s *sequenceOperator) SetSequenceVal(newVal int64) (int64, bool, error) { return s.tbl.SetSequenceVal(s.sctx, newVal, s.db, s.name) } -func sequenceOperatorProp(sctx sessionctx.Context) contextopt.SequenceOperatorProvider { - return func(db, name string) (contextopt.SequenceOperator, error) { +func sequenceOperatorProp(sctx sessionctx.Context) expropt.SequenceOperatorProvider { + return func(db, name string) (expropt.SequenceOperator, error) { sequence, err := util.GetSequenceByName(sctx.GetInfoSchema(), model.NewCIStr(db), model.NewCIStr(name)) if err != nil { return nil, err @@ -389,32 +389,32 @@ func sequenceOperatorProp(sctx sessionctx.Context) contextopt.SequenceOperatorPr } } -var _ exprctx.StaticConvertibleExprContext = &SessionExprContext{} +var _ exprctx.StaticConvertibleExprContext = &ExprContext{} // GetStaticConvertibleEvalContext implements context.StaticConvertibleExprContext. -func (ctx *SessionExprContext) GetStaticConvertibleEvalContext() exprctx.StaticConvertibleEvalContext { - return ctx.SessionEvalContext +func (ctx *ExprContext) GetStaticConvertibleEvalContext() exprctx.StaticConvertibleEvalContext { + return ctx.EvalContext } // GetPlanCacheTracker implements context.StaticConvertibleExprContext. -func (ctx *SessionExprContext) GetPlanCacheTracker() *contextutil.PlanCacheTracker { +func (ctx *ExprContext) GetPlanCacheTracker() *contextutil.PlanCacheTracker { return &ctx.sctx.GetSessionVars().StmtCtx.PlanCacheTracker } // GetLastPlanColumnID implements context.StaticConvertibleExprContext. -func (ctx *SessionExprContext) GetLastPlanColumnID() int64 { +func (ctx *ExprContext) GetLastPlanColumnID() int64 { return ctx.sctx.GetSessionVars().PlanColumnID.Load() } -var _ exprctx.StaticConvertibleEvalContext = &SessionEvalContext{} +var _ exprctx.StaticConvertibleEvalContext = &EvalContext{} // AllParamValues implements context.StaticConvertibleEvalContext. -func (ctx *SessionEvalContext) AllParamValues() []types.Datum { +func (ctx *EvalContext) AllParamValues() []types.Datum { return ctx.sctx.GetSessionVars().PlanCacheParams.AllParamValues() } // GetDynamicPrivCheckFn implements context.StaticConvertibleEvalContext. -func (ctx *SessionEvalContext) GetDynamicPrivCheckFn() func(privName string, grantable bool) bool { +func (ctx *EvalContext) GetDynamicPrivCheckFn() func(privName string, grantable bool) bool { checker := privilege.GetPrivilegeManager(ctx.sctx) activeRoles := make([]*auth.RoleIdentity, len(ctx.sctx.GetSessionVars().ActiveRoles)) copy(activeRoles, ctx.sctx.GetSessionVars().ActiveRoles) @@ -429,7 +429,7 @@ func (ctx *SessionEvalContext) GetDynamicPrivCheckFn() func(privName string, gra } // GetRequestVerificationFn implements context.StaticConvertibleEvalContext. -func (ctx *SessionEvalContext) GetRequestVerificationFn() func(db string, table string, column string, priv mysql.PrivilegeType) bool { +func (ctx *EvalContext) GetRequestVerificationFn() func(db string, table string, column string, priv mysql.PrivilegeType) bool { checker := privilege.GetPrivilegeManager(ctx.sctx) activeRoles := make([]*auth.RoleIdentity, len(ctx.sctx.GetSessionVars().ActiveRoles)) copy(activeRoles, ctx.sctx.GetSessionVars().ActiveRoles) @@ -444,6 +444,6 @@ func (ctx *SessionEvalContext) GetRequestVerificationFn() func(db string, table } // GetWarnHandler implements context.StaticConvertibleEvalContext. -func (ctx *SessionEvalContext) GetWarnHandler() contextutil.WarnHandler { +func (ctx *EvalContext) GetWarnHandler() contextutil.WarnHandler { return ctx.sctx.GetSessionVars().StmtCtx.WarnHandler } diff --git a/pkg/expression/contextsession/sessionctx_test.go b/pkg/expression/sessionexpr/sessionctx_test.go similarity index 88% rename from pkg/expression/contextsession/sessionctx_test.go rename to pkg/expression/sessionexpr/sessionctx_test.go index 009a4b2386614..a316115f78e69 100644 --- a/pkg/expression/contextsession/sessionctx_test.go +++ b/pkg/expression/sessionexpr/sessionctx_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextsession_test +package sessionexpr_test import ( "sync/atomic" @@ -21,9 +21,9 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" - "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" "github.com/pingcap/tidb/pkg/parser/auth" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/privilege" @@ -40,15 +40,15 @@ func TestSessionEvalContextBasic(t *testing.T) { ctx := mock.NewContext() vars := ctx.GetSessionVars() sc := vars.StmtCtx - impl := contextsession.NewSessionEvalContext(ctx) + impl := sessionexpr.NewEvalContext(ctx) require.True(t, impl.GetOptionalPropSet().IsFull()) // should contain all the optional properties - for i := 0; i < context.OptPropsCnt; i++ { - provider, ok := impl.GetOptionalPropProvider(context.OptionalEvalPropKey(i)) + for i := 0; i < exprctx.OptPropsCnt; i++ { + provider, ok := impl.GetOptionalPropProvider(exprctx.OptionalEvalPropKey(i)) require.True(t, ok) require.NotNil(t, provider) - require.Same(t, context.OptionalEvalPropKey(i).Desc(), provider.Desc()) + require.Same(t, exprctx.OptionalEvalPropKey(i).Desc(), provider.Desc()) } ctx.ResetSessionAndStmtTimeZone(time.FixedZone("UTC+11", 11*3600)) @@ -115,7 +115,7 @@ func TestSessionEvalContextCurrentTime(t *testing.T) { ctx := mock.NewContext() vars := ctx.GetSessionVars() sc := vars.StmtCtx - impl := contextsession.NewSessionEvalContext(ctx) + impl := sessionexpr.NewEvalContext(ctx) var now atomic.Pointer[time.Time] sc.SetStaleTSOProvider(func() (uint64, error) { @@ -182,7 +182,7 @@ func (m *mockPrivManager) RequestDynamicVerification( func TestSessionEvalContextPrivilegeCheck(t *testing.T) { ctx := mock.NewContext() - impl := contextsession.NewSessionEvalContext(ctx) + impl := sessionexpr.NewEvalContext(ctx) activeRoles := []*auth.RoleIdentity{ {Username: "role1", Hostname: "host1"}, {Username: "role2", Hostname: "host2"}, @@ -217,10 +217,10 @@ func TestSessionEvalContextPrivilegeCheck(t *testing.T) { require.False(t, impl.RequestDynamicVerification("RESTRICTED_CONNECTION_ADMIN", true)) } -func getProvider[T context.OptionalEvalPropProvider]( +func getProvider[T exprctx.OptionalEvalPropProvider]( t *testing.T, - impl *contextsession.SessionEvalContext, - key context.OptionalEvalPropKey, + impl *sessionexpr.EvalContext, + key exprctx.OptionalEvalPropKey, ) T { val, ok := impl.GetOptionalPropProvider(key) require.True(t, ok) @@ -232,7 +232,7 @@ func getProvider[T context.OptionalEvalPropProvider]( func TestSessionEvalContextOptProps(t *testing.T) { ctx := mock.NewContext() - impl := contextsession.NewSessionEvalContext(ctx) + impl := sessionexpr.NewEvalContext(ctx) // test for OptPropCurrentUser ctx.GetSessionVars().User = &auth.UserIdentity{Username: "user1", Hostname: "host1"} @@ -240,25 +240,25 @@ func TestSessionEvalContextOptProps(t *testing.T) { {Username: "role1", Hostname: "host1"}, {Username: "role2", Hostname: "host2"}, } - user, roles := getProvider[contextopt.CurrentUserPropProvider](t, impl, context.OptPropCurrentUser)() + user, roles := getProvider[expropt.CurrentUserPropProvider](t, impl, exprctx.OptPropCurrentUser)() require.Equal(t, ctx.GetSessionVars().User, user) require.Equal(t, ctx.GetSessionVars().ActiveRoles, roles) // test for OptPropSessionVars - sessVarsProvider := getProvider[*contextopt.SessionVarsPropProvider](t, impl, context.OptPropSessionVars) + sessVarsProvider := getProvider[*expropt.SessionVarsPropProvider](t, impl, exprctx.OptPropSessionVars) require.NotNil(t, sessVarsProvider) - gotVars, err := contextopt.SessionVarsPropReader{}.GetSessionVars(impl) + gotVars, err := expropt.SessionVarsPropReader{}.GetSessionVars(impl) require.NoError(t, err) require.Same(t, ctx.GetSessionVars(), gotVars) // test for OptPropAdvisoryLock - lockProvider := getProvider[*contextopt.AdvisoryLockPropProvider](t, impl, context.OptPropAdvisoryLock) + lockProvider := getProvider[*expropt.AdvisoryLockPropProvider](t, impl, exprctx.OptPropAdvisoryLock) gotCtx, ok := lockProvider.AdvisoryLockContext.(*mock.Context) require.True(t, ok) require.Same(t, ctx, gotCtx) // test for OptPropDDLOwnerInfo - ddlInfoProvider := getProvider[contextopt.DDLOwnerInfoProvider](t, impl, context.OptPropDDLOwnerInfo) + ddlInfoProvider := getProvider[expropt.DDLOwnerInfoProvider](t, impl, exprctx.OptPropDDLOwnerInfo) require.False(t, ddlInfoProvider()) ctx.SetIsDDLOwner(true) require.True(t, ddlInfoProvider()) @@ -266,10 +266,10 @@ func TestSessionEvalContextOptProps(t *testing.T) { func TestSessionBuildContext(t *testing.T) { ctx := mock.NewContext() - impl := contextsession.NewSessionExprContext(ctx) - evalCtx, ok := impl.GetEvalCtx().(*contextsession.SessionEvalContext) + impl := sessionexpr.NewExprContext(ctx) + evalCtx, ok := impl.GetEvalCtx().(*sessionexpr.EvalContext) require.True(t, ok) - require.Same(t, evalCtx, impl.SessionEvalContext) + require.Same(t, evalCtx, impl.EvalContext) require.True(t, evalCtx.GetOptionalPropSet().IsFull()) require.Same(t, ctx, evalCtx.Sctx()) diff --git a/pkg/expression/util.go b/pkg/expression/util.go index 4e39f8f24da66..73136f3a4af9e 100644 --- a/pkg/expression/util.go +++ b/pkg/expression/util.go @@ -27,7 +27,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/param" "github.com/pingcap/tidb/pkg/parser/ast" @@ -1741,7 +1741,7 @@ func (r *SQLDigestTextRetriever) runMockQuery(data map[string]string, inValues [ // of the given SQL digests, if `inValues` is given, or all these mappings otherwise. If `queryGlobal` is false, it // queries information_schema.statements_summary and information_schema.statements_summary_history; otherwise, it // queries the cluster version of these two tables. -func (r *SQLDigestTextRetriever) runFetchDigestQuery(ctx context.Context, exec contextopt.SQLExecutor, queryGlobal bool, inValues []any) (map[string]string, error) { +func (r *SQLDigestTextRetriever) runFetchDigestQuery(ctx context.Context, exec expropt.SQLExecutor, queryGlobal bool, inValues []any) (map[string]string, error) { ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnOthers) // If mock data is set, query the mock data instead of the real statements_summary tables. if !queryGlobal && r.mockLocalData != nil { @@ -1789,7 +1789,7 @@ func (r *SQLDigestTextRetriever) updateDigestInfo(queryResult map[string]string) } // RetrieveLocal tries to retrieve the SQL text of the SQL digests from local information. -func (r *SQLDigestTextRetriever) RetrieveLocal(ctx context.Context, exec contextopt.SQLExecutor) error { +func (r *SQLDigestTextRetriever) RetrieveLocal(ctx context.Context, exec expropt.SQLExecutor) error { if len(r.SQLDigestsMap) == 0 { return nil } @@ -1823,7 +1823,7 @@ func (r *SQLDigestTextRetriever) RetrieveLocal(ctx context.Context, exec context } // RetrieveGlobal tries to retrieve the SQL text of the SQL digests from the information of the whole cluster. -func (r *SQLDigestTextRetriever) RetrieveGlobal(ctx context.Context, exec contextopt.SQLExecutor) error { +func (r *SQLDigestTextRetriever) RetrieveGlobal(ctx context.Context, exec expropt.SQLExecutor) error { err := r.RetrieveLocal(ctx, exec) if err != nil { return errors.Trace(err) diff --git a/pkg/lightning/backend/kv/BUILD.bazel b/pkg/lightning/backend/kv/BUILD.bazel index 7adcaae908e76..b28c0b1339fab 100644 --- a/pkg/lightning/backend/kv/BUILD.bazel +++ b/pkg/lightning/backend/kv/BUILD.bazel @@ -16,9 +16,9 @@ go_library( "//br/pkg/logutil", "//pkg/errctx", "//pkg/expression", - "//pkg/expression/context", - "//pkg/expression/contextsession", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/exprstatic", + "//pkg/expression/sessionexpr", "//pkg/infoschema/context", "//pkg/kv", "//pkg/lightning/backend/encode", @@ -30,14 +30,14 @@ go_library( "//pkg/meta/autoid", "//pkg/meta/model", "//pkg/parser/mysql", - "//pkg/planner/context", + "//pkg/planner/planctx", "//pkg/sessionctx", "//pkg/sessionctx/stmtctx", "//pkg/sessionctx/variable", "//pkg/table", - "//pkg/table/context", - "//pkg/table/contextimpl", "//pkg/table/tables", + "//pkg/table/tblctx", + "//pkg/table/tblsession", "//pkg/tablecodec", "//pkg/types", "//pkg/util/chunk", @@ -73,8 +73,8 @@ go_test( deps = [ "//pkg/ddl", "//pkg/errctx", - "//pkg/expression/context", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/exprstatic", "//pkg/kv", "//pkg/lightning/backend/encode", "//pkg/lightning/common", @@ -90,8 +90,8 @@ go_test( "//pkg/sessionctx/stmtctx", "//pkg/sessionctx/variable", "//pkg/table", - "//pkg/table/context", "//pkg/table/tables", + "//pkg/table/tblctx", "//pkg/tablecodec", "//pkg/types", "//pkg/util/context", diff --git a/pkg/lightning/backend/kv/context.go b/pkg/lightning/backend/kv/context.go index 42f82a8f27157..1b904acd20e7e 100644 --- a/pkg/lightning/backend/kv/context.go +++ b/pkg/lightning/backend/kv/context.go @@ -21,15 +21,15 @@ import ( "time" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/meta/autoid" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/table" - tbctx "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/types" contextutil "github.com/pingcap/tidb/pkg/util/context" "github.com/pingcap/tidb/pkg/util/intest" @@ -42,11 +42,11 @@ var _ exprctx.ExprContext = &litExprContext{} // It provides the context to build and evaluate expressions, furthermore, it allows to set user variables // for `IMPORT INTO ...` statements. type litExprContext struct { - *contextstatic.StaticExprContext + *exprstatic.ExprContext userVars *variable.UserVars } -// NewExpressionContext creates a new `*StaticExprContext` for lightning import. +// NewExpressionContext creates a new `*ExprContext` for lightning import. func newLitExprContext(sqlMode mysql.SQLMode, sysVars map[string]string, timestamp int64) (*litExprContext, error) { flags := types.DefaultStmtFlags. WithTruncateAsWarning(!sqlMode.HasStrictMode()). @@ -61,20 +61,20 @@ func newLitExprContext(sqlMode mysql.SQLMode, sysVars map[string]string, timesta errctx.ResolveErrLevel(!sqlMode.HasErrorForDivisionByZeroMode(), !sqlMode.HasStrictMode()) userVars := variable.NewUserVars() - evalCtx := contextstatic.NewStaticEvalContext( - contextstatic.WithSQLMode(sqlMode), - contextstatic.WithTypeFlags(flags), - contextstatic.WithLocation(timeutil.SystemLocation()), - contextstatic.WithErrLevelMap(errLevels), - contextstatic.WithUserVarsReader(userVars), + evalCtx := exprstatic.NewEvalContext( + exprstatic.WithSQLMode(sqlMode), + exprstatic.WithTypeFlags(flags), + exprstatic.WithLocation(timeutil.SystemLocation()), + exprstatic.WithErrLevelMap(errLevels), + exprstatic.WithUserVarsReader(userVars), ) // no need to build as plan cache. planCacheTracker := contextutil.NewPlanCacheTracker(contextutil.IgnoreWarn) intest.Assert(!planCacheTracker.UseCache()) - ctx := contextstatic.NewStaticExprContext( - contextstatic.WithEvalCtx(evalCtx), - contextstatic.WithPlanCacheTracker(&planCacheTracker), + ctx := exprstatic.NewExprContext( + exprstatic.WithEvalCtx(evalCtx), + exprstatic.WithPlanCacheTracker(&planCacheTracker), ) if len(sysVars) > 0 { @@ -91,12 +91,12 @@ func newLitExprContext(sqlMode mysql.SQLMode, sysVars map[string]string, timesta currentTime = func() (time.Time, error) { return time.Unix(timestamp, 0), nil } } - evalCtx = evalCtx.Apply(contextstatic.WithCurrentTime(currentTime)) - ctx = ctx.Apply(contextstatic.WithEvalCtx(evalCtx)) + evalCtx = evalCtx.Apply(exprstatic.WithCurrentTime(currentTime)) + ctx = ctx.Apply(exprstatic.WithEvalCtx(evalCtx)) return &litExprContext{ - StaticExprContext: ctx, - userVars: userVars, + ExprContext: ctx, + userVars: userVars, }, nil } @@ -115,8 +115,8 @@ var _ table.MutateContext = &litTableMutateContext{} // litTableMutateContext implements the `table.MutateContext` interface for lightning import. type litTableMutateContext struct { exprCtx *litExprContext - encodingConfig tbctx.RowEncodingConfig - mutateBuffers *tbctx.MutateBuffers + encodingConfig tblctx.RowEncodingConfig + mutateBuffers *tblctx.MutateBuffers shardID *variable.RowIDShardGenerator reservedRowIDAlloc stmtctx.ReservedRowIDAlloc enableMutationChecker bool @@ -162,12 +162,12 @@ func (ctx *litTableMutateContext) EnableMutationChecker() bool { } // GetRowEncodingConfig implements the `table.MutateContext` interface. -func (ctx *litTableMutateContext) GetRowEncodingConfig() tbctx.RowEncodingConfig { +func (ctx *litTableMutateContext) GetRowEncodingConfig() tblctx.RowEncodingConfig { return ctx.encodingConfig } // GetMutateBuffers implements the `table.MutateContext` interface. -func (ctx *litTableMutateContext) GetMutateBuffers() *tbctx.MutateBuffers { +func (ctx *litTableMutateContext) GetMutateBuffers() *tblctx.MutateBuffers { return ctx.mutateBuffers } @@ -182,13 +182,13 @@ func (ctx *litTableMutateContext) GetReservedRowIDAlloc() (*stmtctx.ReservedRowI } // GetBinlogSupport implements the `table.MutateContext` interface. -func (*litTableMutateContext) GetBinlogSupport() (tbctx.BinlogSupport, bool) { +func (*litTableMutateContext) GetBinlogSupport() (tblctx.BinlogSupport, bool) { // lightning import does not support binlog. return nil, false } // GetStatisticsSupport implements the `table.MutateContext` interface. -func (ctx *litTableMutateContext) GetStatisticsSupport() (tbctx.StatisticsSupport, bool) { +func (ctx *litTableMutateContext) GetStatisticsSupport() (tblctx.StatisticsSupport, bool) { return ctx, true } @@ -215,17 +215,17 @@ func (ctx *litTableMutateContext) GetColumnSize(tblID int64) (ret map[int64]int6 } // GetCachedTableSupport implements the `table.MutateContext` interface. -func (*litTableMutateContext) GetCachedTableSupport() (tbctx.CachedTableSupport, bool) { +func (*litTableMutateContext) GetCachedTableSupport() (tblctx.CachedTableSupport, bool) { // lightning import does not support cached table. return nil, false } -func (*litTableMutateContext) GetTemporaryTableSupport() (tbctx.TemporaryTableSupport, bool) { +func (*litTableMutateContext) GetTemporaryTableSupport() (tblctx.TemporaryTableSupport, bool) { // lightning import does not support temporary table. return nil, false } -func (*litTableMutateContext) GetExchangePartitionDMLSupport() (tbctx.ExchangePartitionDMLSupport, bool) { +func (*litTableMutateContext) GetExchangePartitionDMLSupport() (tblctx.ExchangePartitionDMLSupport, bool) { // lightning import is not in a DML query, we do not need to support it. return nil, false } @@ -242,11 +242,11 @@ func newLitTableMutateContext(exprCtx *litExprContext, sysVars map[string]string return &litTableMutateContext{ exprCtx: exprCtx, - encodingConfig: tbctx.RowEncodingConfig{ + encodingConfig: tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: sessVars.IsRowLevelChecksumEnabled(), RowEncoder: &sessVars.RowEncoder, }, - mutateBuffers: tbctx.NewMutateBuffers(sessVars.GetWriteStmtBufs()), + mutateBuffers: tblctx.NewMutateBuffers(sessVars.GetWriteStmtBufs()), // Though the row ID is generated by lightning itself, and `GetRowIDShardGenerator` is useless, // still return a valid object to make the context complete and avoid some potential panic // if there are some changes in the future. diff --git a/pkg/lightning/backend/kv/context_test.go b/pkg/lightning/backend/kv/context_test.go index 4f26782dc97db..8941bb82fa222 100644 --- a/pkg/lightning/backend/kv/context_test.go +++ b/pkg/lightning/backend/kv/context_test.go @@ -22,15 +22,15 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/lightning/backend/encode" "github.com/pingcap/tidb/pkg/lightning/log" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" - tbctx "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/types" contextutil "github.com/pingcap/tidb/pkg/util/context" "github.com/pingcap/tidb/pkg/util/deeptest" @@ -146,18 +146,18 @@ func TestLitExprContext(t *testing.T) { opts.SysVars["block_encryption_mode"] = variable.DefBlockEncryptionMode } se := newSession(opts, log.L()) - seCtx := contextstatic.MakeExprContextStatic(se.exprCtx.SessionExprContext) - deeptest.AssertDeepClonedEqual(t, seCtx, ctx.StaticExprContext, deeptest.WithIgnorePath([]string{ - "$.staticExprCtxState.evalCtx.id", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.typeCtx.loc", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.warnHandler", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.typeCtx.warnHandler", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.errCtx.warnHandler", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.currentTime", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.requestVerificationFn", - "$.staticExprCtxState.evalCtx.staticEvalCtxState.requestDynamicVerificationFn", - "$.staticExprCtxState.rng", - "$.staticExprCtxState.planCacheTracker", + seCtx := exprstatic.MakeExprContextStatic(se.exprCtx.ExprContext) + deeptest.AssertDeepClonedEqual(t, seCtx, ctx.ExprContext, deeptest.WithIgnorePath([]string{ + "$.exprCtxState.evalCtx.id", + "$.exprCtxState.evalCtx.evalCtxState.typeCtx.loc", + "$.exprCtxState.evalCtx.evalCtxState.warnHandler", + "$.exprCtxState.evalCtx.evalCtxState.typeCtx.warnHandler", + "$.exprCtxState.evalCtx.evalCtxState.errCtx.warnHandler", + "$.exprCtxState.evalCtx.evalCtxState.currentTime", + "$.exprCtxState.evalCtx.evalCtxState.requestVerificationFn", + "$.exprCtxState.evalCtx.evalCtxState.requestDynamicVerificationFn", + "$.exprCtxState.rng", + "$.exprCtxState.planCacheTracker", })) currentTime, err := seCtx.GetEvalCtx().CurrentTime() require.NoError(t, err) @@ -348,7 +348,7 @@ func TestLitTableMutateContext(t *testing.T) { require.Equal(t, variable.AssertionLevelOff, tblCtx.TxnAssertionLevel()) require.Equal(t, variable.DefTiDBEnableMutationChecker, tblCtx.EnableMutationChecker()) require.False(t, tblCtx.EnableMutationChecker()) - require.Equal(t, tbctx.RowEncodingConfig{ + require.Equal(t, tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: false, RowEncoder: &rowcodec.Encoder{Enable: false}, }, tblCtx.GetRowEncodingConfig()) @@ -369,7 +369,7 @@ func TestLitTableMutateContext(t *testing.T) { checkCommon(t, tblCtx) require.Equal(t, variable.AssertionLevelStrict, tblCtx.TxnAssertionLevel()) require.True(t, tblCtx.EnableMutationChecker()) - require.Equal(t, tbctx.RowEncodingConfig{ + require.Equal(t, tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: false, RowEncoder: &rowcodec.Encoder{Enable: true}, }, tblCtx.GetRowEncodingConfig()) @@ -388,7 +388,7 @@ func TestLitTableMutateContext(t *testing.T) { } tblCtx, err = newLitTableMutateContext(exprCtx, sysVars) require.NoError(t, err) - require.Equal(t, tbctx.RowEncodingConfig{ + require.Equal(t, tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: true, RowEncoder: &rowcodec.Encoder{Enable: true}, }, tblCtx.GetRowEncodingConfig()) diff --git a/pkg/lightning/backend/kv/session.go b/pkg/lightning/backend/kv/session.go index 6d263f5661bc0..e13667a55f197 100644 --- a/pkg/lightning/backend/kv/session.go +++ b/pkg/lightning/backend/kv/session.go @@ -25,8 +25,8 @@ import ( "github.com/docker/go-units" "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - exprctximpl "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/lightning/backend/encode" @@ -34,11 +34,11 @@ import ( "github.com/pingcap/tidb/pkg/lightning/log" "github.com/pingcap/tidb/pkg/lightning/manual" "github.com/pingcap/tidb/pkg/meta/model" - planctx "github.com/pingcap/tidb/pkg/planner/context" + planctx "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" - tbctx "github.com/pingcap/tidb/pkg/table/context" - tbctximpl "github.com/pingcap/tidb/pkg/table/contextimpl" + "github.com/pingcap/tidb/pkg/table/tblctx" + "github.com/pingcap/tidb/pkg/table/tblsession" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/topsql/stmtstats" @@ -285,7 +285,7 @@ func (*transaction) MayFlush() error { // sessExprContext implements the ExprContext interface // It embedded an `ExprContext` and a `sessEvalContext` to provide no optional properties. type sessExprContext struct { - *exprctximpl.SessionExprContext + *sessionexpr.ExprContext evalCtx *sessEvalContext } @@ -322,7 +322,7 @@ type session struct { txn transaction Vars *variable.SessionVars exprCtx *sessExprContext - tblctx *tbctximpl.TableContextImpl + tblctx *tblsession.MutateContext // currently, we only set `CommonAddRecordCtx` values map[fmt.Stringer]any } @@ -378,16 +378,16 @@ func newSession(options *encode.SessionOptions, logger log.Logger) *session { } vars.TxnCtx = nil s.Vars = vars - exprCtx := exprctximpl.NewSessionExprContext(s) + exprCtx := sessionexpr.NewExprContext(s) // The exprCtx should be an expression context providing no optional properties in `EvalContext`. // That is to make sure it only allows expressions that require basic context. s.exprCtx = &sessExprContext{ - SessionExprContext: exprCtx, + ExprContext: exprCtx, evalCtx: &sessEvalContext{ EvalContext: exprCtx.GetEvalCtx(), }, } - s.tblctx = tbctximpl.NewTableContextImpl(s) + s.tblctx = tblsession.NewMutateContext(s) s.txn.kvPairs = &Pairs{} return s @@ -409,7 +409,7 @@ func (se *session) GetExprCtx() exprctx.ExprContext { } // GetTableCtx returns the table.MutateContext -func (se *session) GetTableCtx() tbctx.MutateContext { +func (se *session) GetTableCtx() tblctx.MutateContext { return se.tblctx } @@ -500,7 +500,7 @@ func (s *Session) Txn() kv.Transaction { } // GetTableCtx returns the table MutateContext. -func (s *Session) GetTableCtx() tbctx.MutateContext { +func (s *Session) GetTableCtx() tblctx.MutateContext { return s.tblCtx } diff --git a/pkg/planner/BUILD.bazel b/pkg/planner/BUILD.bazel index 3d6398176dc79..7e651e8949d02 100644 --- a/pkg/planner/BUILD.bazel +++ b/pkg/planner/BUILD.bazel @@ -14,11 +14,11 @@ go_library( "//pkg/parser/ast", "//pkg/parser/model", "//pkg/planner/cascades", - "//pkg/planner/context", "//pkg/planner/core", "//pkg/planner/core/base", "//pkg/planner/core/resolve", "//pkg/planner/indexadvisor", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/planner/util/debugtrace", "//pkg/planner/util/optimizetrace", diff --git a/pkg/planner/cardinality/BUILD.bazel b/pkg/planner/cardinality/BUILD.bazel index b308d5479ae28..0c5f0dc481ea8 100644 --- a/pkg/planner/cardinality/BUILD.bazel +++ b/pkg/planner/cardinality/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//pkg/parser/ast", "//pkg/parser/format", "//pkg/parser/mysql", - "//pkg/planner/context", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/planner/util", "//pkg/planner/util/debugtrace", diff --git a/pkg/planner/cardinality/cross_estimation.go b/pkg/planner/cardinality/cross_estimation.go index 04775bbef5e1a..d249a47502855 100644 --- a/pkg/planner/cardinality/cross_estimation.go +++ b/pkg/planner/cardinality/cross_estimation.go @@ -18,7 +18,7 @@ import ( "math" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/statistics" @@ -33,7 +33,7 @@ const SelectionFactor = 0.8 // AdjustRowCountForTableScanByLimit will adjust the row count for table scan by limit. // For a query like `select pk from t using index(primary) where pk > 10 limit 1`, the row count of the table scan // should be adjusted by the limit number 1, because only one row is returned. -func AdjustRowCountForTableScanByLimit(sctx context.PlanContext, +func AdjustRowCountForTableScanByLimit(sctx planctx.PlanContext, dsStatsInfo, dsTableStats *property.StatsInfo, dsStatisticTable *statistics.Table, path *util.AccessPath, expectedCnt float64, desc bool) float64 { rowCount := path.CountAfterAccess @@ -67,7 +67,7 @@ func AdjustRowCountForTableScanByLimit(sctx context.PlanContext, // `select * from tbl where a = 1 order by pk limit 1` // if order of column `a` is strictly correlated with column `pk`, the row count of table scan should be: // `1 + row_count(a < 1 or a is null)` -func crossEstimateTableRowCount(sctx context.PlanContext, +func crossEstimateTableRowCount(sctx planctx.PlanContext, dsStatsInfo, dsTableStats *property.StatsInfo, dsStatisticTable *statistics.Table, path *util.AccessPath, expectedCnt float64, desc bool) (float64, bool, float64) { if dsStatisticTable.Pseudo || len(path.TableFilters) == 0 || !sctx.GetSessionVars().EnableCorrelationAdjustment { @@ -80,7 +80,7 @@ func crossEstimateTableRowCount(sctx context.PlanContext, // AdjustRowCountForIndexScanByLimit will adjust the row count for table scan by limit. // For a query like `select k from t using index(k) where k > 10 limit 1`, the row count of the index scan // should be adjusted by the limit number 1, because only one row is returned. -func AdjustRowCountForIndexScanByLimit(sctx context.PlanContext, +func AdjustRowCountForIndexScanByLimit(sctx planctx.PlanContext, dsStatsInfo, dsTableStats *property.StatsInfo, dsStatisticTable *statistics.Table, path *util.AccessPath, expectedCnt float64, desc bool) float64 { rowCount := path.CountAfterAccess @@ -114,7 +114,7 @@ func AdjustRowCountForIndexScanByLimit(sctx context.PlanContext, // `select * from tbl where a = 1 order by b limit 1` // if order of column `a` is strictly correlated with column `b`, the row count of IndexScan(b) should be: // `1 + row_count(a < 1 or a is null)` -func crossEstimateIndexRowCount(sctx context.PlanContext, +func crossEstimateIndexRowCount(sctx planctx.PlanContext, dsStatsInfo, dsTableStats *property.StatsInfo, dsStatisticTable *statistics.Table, path *util.AccessPath, expectedCnt float64, desc bool) (float64, bool, float64) { filtersLen := len(path.TableFilters) + len(path.IndexFilters) @@ -130,7 +130,7 @@ func crossEstimateIndexRowCount(sctx context.PlanContext, } // crossEstimateRowCount is the common logic of crossEstimateTableRowCount and crossEstimateIndexRowCount. -func crossEstimateRowCount(sctx context.PlanContext, +func crossEstimateRowCount(sctx planctx.PlanContext, dsStatsInfo, dsTableStats *property.StatsInfo, path *util.AccessPath, conds []expression.Expression, col *expression.Column, corr, expectedCnt float64, desc bool) (float64, bool, float64) { @@ -182,7 +182,7 @@ func crossEstimateRowCount(sctx context.PlanContext, } // getColumnRangeCounts estimates row count for each range respectively. -func getColumnRangeCounts(sctx context.PlanContext, colID int64, ranges []*ranger.Range, histColl *statistics.HistColl, idxID int64) ([]float64, bool) { +func getColumnRangeCounts(sctx planctx.PlanContext, colID int64, ranges []*ranger.Range, histColl *statistics.HistColl, idxID int64) ([]float64, bool) { var err error var count float64 rangeCounts := make([]float64, len(ranges)) diff --git a/pkg/planner/cardinality/join.go b/pkg/planner/cardinality/join.go index 063682f5c033d..06a8e3a3febd1 100644 --- a/pkg/planner/cardinality/join.go +++ b/pkg/planner/cardinality/join.go @@ -18,12 +18,12 @@ import ( "math" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" ) // EstimateFullJoinRowCount estimates the row count of a full join. -func EstimateFullJoinRowCount(sctx context.PlanContext, +func EstimateFullJoinRowCount(sctx planctx.PlanContext, isCartesian bool, leftProfile, rightProfile *property.StatsInfo, leftJoinKeys, rightJoinKeys []*expression.Column, diff --git a/pkg/planner/cardinality/pseudo.go b/pkg/planner/cardinality/pseudo.go index ab085589980d2..1f13a0862fc0f 100644 --- a/pkg/planner/cardinality/pseudo.go +++ b/pkg/planner/cardinality/pseudo.go @@ -21,7 +21,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/statistics" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/ranger" @@ -41,7 +41,7 @@ func PseudoAvgCountPerValue(t *statistics.Table) float64 { return float64(t.RealtimeCount) / pseudoEqualRate } -func pseudoSelectivity(sctx context.PlanContext, coll *statistics.HistColl, exprs []expression.Expression) float64 { +func pseudoSelectivity(sctx planctx.PlanContext, coll *statistics.HistColl, exprs []expression.Expression) float64 { minFactor := selectionFactor colExists := make(map[string]bool) for _, expr := range exprs { diff --git a/pkg/planner/cardinality/row_count_column.go b/pkg/planner/cardinality/row_count_column.go index 1f077e513cc54..5e6d75bf19a74 100644 --- a/pkg/planner/cardinality/row_count_column.go +++ b/pkg/planner/cardinality/row_count_column.go @@ -16,7 +16,7 @@ package cardinality import ( "github.com/pingcap/errors" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/planner/util/fixcontrol" "github.com/pingcap/tidb/pkg/statistics" @@ -34,7 +34,7 @@ func init() { } // GetRowCountByColumnRanges estimates the row count by a slice of Range. -func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colUniqueID int64, colRanges []*ranger.Range) (result float64, err error) { +func GetRowCountByColumnRanges(sctx planctx.PlanContext, coll *statistics.HistColl, colUniqueID int64, colRanges []*ranger.Range) (result float64, err error) { var name string if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) @@ -76,7 +76,7 @@ func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistCo } // GetRowCountByIntColumnRanges estimates the row count by a slice of IntColumnRange. -func GetRowCountByIntColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colUniqueID int64, intRanges []*ranger.Range) (result float64, err error) { +func GetRowCountByIntColumnRanges(sctx planctx.PlanContext, coll *statistics.HistColl, colUniqueID int64, intRanges []*ranger.Range) (result float64, err error) { var name string if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) @@ -125,7 +125,7 @@ func GetRowCountByIntColumnRanges(sctx context.PlanContext, coll *statistics.His } // equalRowCountOnColumn estimates the row count by a slice of Range and a Datum. -func equalRowCountOnColumn(sctx context.PlanContext, c *statistics.Column, val types.Datum, encodedVal []byte, realtimeRowCount, modifyCount int64) (result float64, err error) { +func equalRowCountOnColumn(sctx planctx.PlanContext, c *statistics.Column, val types.Datum, encodedVal []byte, realtimeRowCount, modifyCount int64) (result float64, err error) { if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) debugtrace.RecordAnyValuesWithNames(sctx, "Value", val.String(), "Encoded", encodedVal) @@ -183,7 +183,7 @@ func equalRowCountOnColumn(sctx context.PlanContext, c *statistics.Column, val t } // GetColumnRowCount estimates the row count by a slice of Range. -func GetColumnRowCount(sctx context.PlanContext, c *statistics.Column, ranges []*ranger.Range, realtimeRowCount, modifyCount int64, pkIsHandle bool) (float64, error) { +func GetColumnRowCount(sctx planctx.PlanContext, c *statistics.Column, ranges []*ranger.Range, realtimeRowCount, modifyCount int64, pkIsHandle bool) (float64, error) { sc := sctx.GetSessionVars().StmtCtx debugTrace := sc.EnableOptimizerDebugTrace if debugTrace { @@ -328,7 +328,7 @@ func GetColumnRowCount(sctx context.PlanContext, c *statistics.Column, ranges [] } // betweenRowCountOnColumn estimates the row count for interval [l, r). -func betweenRowCountOnColumn(sctx context.PlanContext, c *statistics.Column, l, r types.Datum, lowEncoded, highEncoded []byte) float64 { +func betweenRowCountOnColumn(sctx planctx.PlanContext, c *statistics.Column, l, r types.Datum, lowEncoded, highEncoded []byte) float64 { histBetweenCnt := c.Histogram.BetweenRowCount(sctx, l, r) if c.StatsVer <= statistics.Version1 { return histBetweenCnt @@ -339,7 +339,7 @@ func betweenRowCountOnColumn(sctx context.PlanContext, c *statistics.Column, l, // functions below are mainly for testing. // ColumnGreaterRowCount estimates the row count where the column greater than value. -func ColumnGreaterRowCount(sctx context.PlanContext, t *statistics.Table, value types.Datum, colID int64) float64 { +func ColumnGreaterRowCount(sctx planctx.PlanContext, t *statistics.Table, value types.Datum, colID int64) float64 { c := t.GetCol(colID) if statistics.ColumnStatsIsInvalid(c, sctx, &t.HistColl, colID) { return float64(t.RealtimeCount) / pseudoLessRate @@ -348,7 +348,7 @@ func ColumnGreaterRowCount(sctx context.PlanContext, t *statistics.Table, value } // columnLessRowCount estimates the row count where the column less than value. Note that null values are not counted. -func columnLessRowCount(sctx context.PlanContext, t *statistics.Table, value types.Datum, colID int64) float64 { +func columnLessRowCount(sctx planctx.PlanContext, t *statistics.Table, value types.Datum, colID int64) float64 { c := t.GetCol(colID) if statistics.ColumnStatsIsInvalid(c, sctx, &t.HistColl, colID) { return float64(t.RealtimeCount) / pseudoLessRate @@ -357,7 +357,7 @@ func columnLessRowCount(sctx context.PlanContext, t *statistics.Table, value typ } // columnBetweenRowCount estimates the row count where column greater or equal to a and less than b. -func columnBetweenRowCount(sctx context.PlanContext, t *statistics.Table, a, b types.Datum, colID int64) (float64, error) { +func columnBetweenRowCount(sctx planctx.PlanContext, t *statistics.Table, a, b types.Datum, colID int64) (float64, error) { sc := sctx.GetSessionVars().StmtCtx c := t.GetCol(colID) if statistics.ColumnStatsIsInvalid(c, sctx, &t.HistColl, colID) { @@ -381,7 +381,7 @@ func columnBetweenRowCount(sctx context.PlanContext, t *statistics.Table, a, b t } // ColumnEqualRowCount estimates the row count where the column equals to value. -func ColumnEqualRowCount(sctx context.PlanContext, t *statistics.Table, value types.Datum, colID int64) (float64, error) { +func ColumnEqualRowCount(sctx planctx.PlanContext, t *statistics.Table, value types.Datum, colID int64) (float64, error) { c := t.GetCol(colID) if statistics.ColumnStatsIsInvalid(c, sctx, &t.HistColl, colID) { return float64(t.RealtimeCount) / pseudoEqualRate, nil diff --git a/pkg/planner/cardinality/row_count_index.go b/pkg/planner/cardinality/row_count_index.go index 68ea1dc13d3e5..4393bf3b4552d 100644 --- a/pkg/planner/cardinality/row_count_index.go +++ b/pkg/planner/cardinality/row_count_index.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/tidb/pkg/kv" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/planner/util/fixcontrol" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" @@ -38,7 +38,7 @@ import ( ) // GetRowCountByIndexRanges estimates the row count by a slice of Range. -func GetRowCountByIndexRanges(sctx context.PlanContext, coll *statistics.HistColl, idxID int64, indexRanges []*ranger.Range) (result float64, err error) { +func GetRowCountByIndexRanges(sctx planctx.PlanContext, coll *statistics.HistColl, idxID int64, indexRanges []*ranger.Range) (result float64, err error) { var name string if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) @@ -90,7 +90,7 @@ func GetRowCountByIndexRanges(sctx context.PlanContext, coll *statistics.HistCol return result, errors.Trace(err) } -func getIndexRowCountForStatsV1(sctx context.PlanContext, coll *statistics.HistColl, idxID int64, indexRanges []*ranger.Range) (float64, error) { +func getIndexRowCountForStatsV1(sctx planctx.PlanContext, coll *statistics.HistColl, idxID int64, indexRanges []*ranger.Range) (float64, error) { sc := sctx.GetSessionVars().StmtCtx debugTrace := sc.EnableOptimizerDebugTrace if debugTrace { @@ -215,7 +215,7 @@ func isSingleColIdxNullRange(idx *statistics.Index, ran *ranger.Range) bool { } // It uses the modifyCount to adjust the influence of modifications on the table. -func getIndexRowCountForStatsV2(sctx context.PlanContext, idx *statistics.Index, coll *statistics.HistColl, indexRanges []*ranger.Range, realtimeRowCount, modifyCount int64) (float64, error) { +func getIndexRowCountForStatsV2(sctx planctx.PlanContext, idx *statistics.Index, coll *statistics.HistColl, indexRanges []*ranger.Range, realtimeRowCount, modifyCount int64) (float64, error) { sc := sctx.GetSessionVars().StmtCtx debugTrace := sc.EnableOptimizerDebugTrace if debugTrace { @@ -374,7 +374,7 @@ func getIndexRowCountForStatsV2(sctx context.PlanContext, idx *statistics.Index, var nullKeyBytes, _ = codec.EncodeKey(time.UTC, nil, types.NewDatum(nil)) -func equalRowCountOnIndex(sctx context.PlanContext, idx *statistics.Index, b []byte, realtimeRowCount, modifyCount int64) (result float64) { +func equalRowCountOnIndex(sctx planctx.PlanContext, idx *statistics.Index, b []byte, realtimeRowCount, modifyCount int64) (result float64) { if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) debugtrace.RecordAnyValuesWithNames(sctx, "Encoded Value", b) @@ -425,7 +425,7 @@ func equalRowCountOnIndex(sctx context.PlanContext, idx *statistics.Index, b []b } // expBackoffEstimation estimate the multi-col cases following the Exponential Backoff. See comment below for details. -func expBackoffEstimation(sctx context.PlanContext, idx *statistics.Index, coll *statistics.HistColl, indexRange *ranger.Range) (sel float64, success bool, err error) { +func expBackoffEstimation(sctx planctx.PlanContext, idx *statistics.Index, coll *statistics.HistColl, indexRange *ranger.Range) (sel float64, success bool, err error) { if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { @@ -560,7 +560,7 @@ func matchPrefix(row chunk.Row, colIdx int, ad *types.Datum) bool { // betweenRowCountOnIndex estimates the row count for interval [l, r). // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func betweenRowCountOnIndex(sctx context.PlanContext, idx *statistics.Index, l, r types.Datum) float64 { +func betweenRowCountOnIndex(sctx planctx.PlanContext, idx *statistics.Index, l, r types.Datum) float64 { histBetweenCnt := idx.Histogram.BetweenRowCount(sctx, l, r) if idx.StatsVer == statistics.Version1 { return histBetweenCnt diff --git a/pkg/planner/cardinality/row_size.go b/pkg/planner/cardinality/row_size.go index ffa96eea9fa0d..b57939d010ad0 100644 --- a/pkg/planner/cardinality/row_size.go +++ b/pkg/planner/cardinality/row_size.go @@ -20,7 +20,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/statistics" "github.com/pingcap/tidb/pkg/tablecodec" "github.com/pingcap/tidb/pkg/util/chunk" @@ -29,7 +29,7 @@ import ( const pseudoColSize = 8.0 // GetIndexAvgRowSize computes average row size for a index scan. -func GetIndexAvgRowSize(ctx context.PlanContext, coll *statistics.HistColl, cols []*expression.Column, isUnique bool) (size float64) { +func GetIndexAvgRowSize(ctx planctx.PlanContext, coll *statistics.HistColl, cols []*expression.Column, isUnique bool) (size float64) { size = GetAvgRowSize(ctx, coll, cols, true, true) // tablePrefix(1) + tableID(8) + indexPrefix(2) + indexID(8) // Because the cols for index scan always contain the handle, so we don't add the rowID here. @@ -42,7 +42,7 @@ func GetIndexAvgRowSize(ctx context.PlanContext, coll *statistics.HistColl, cols } // GetTableAvgRowSize computes average row size for a table scan, exclude the index key-value pairs. -func GetTableAvgRowSize(ctx context.PlanContext, coll *statistics.HistColl, cols []*expression.Column, storeType kv.StoreType, handleInCols bool) (size float64) { +func GetTableAvgRowSize(ctx planctx.PlanContext, coll *statistics.HistColl, cols []*expression.Column, storeType kv.StoreType, handleInCols bool) (size float64) { size = GetAvgRowSize(ctx, coll, cols, false, true) switch storeType { case kv.TiKV: @@ -58,7 +58,7 @@ func GetTableAvgRowSize(ctx context.PlanContext, coll *statistics.HistColl, cols } // GetAvgRowSize computes average row size for given columns. -func GetAvgRowSize(ctx context.PlanContext, coll *statistics.HistColl, cols []*expression.Column, isEncodedKey bool, isForScan bool) (size float64) { +func GetAvgRowSize(ctx planctx.PlanContext, coll *statistics.HistColl, cols []*expression.Column, isEncodedKey bool, isForScan bool) (size float64) { sessionVars := ctx.GetSessionVars() if coll.Pseudo || coll.ColNum() == 0 || coll.RealtimeCount == 0 { size = pseudoColSize * float64(len(cols)) diff --git a/pkg/planner/cardinality/selectivity.go b/pkg/planner/cardinality/selectivity.go index 6241160461aad..7877afb63b209 100644 --- a/pkg/planner/cardinality/selectivity.go +++ b/pkg/planner/cardinality/selectivity.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" planutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/statistics" @@ -48,7 +48,7 @@ var ( // should be held when you call this. // Currently, the time complexity is o(n^2). func Selectivity( - ctx context.PlanContext, + ctx planctx.PlanContext, coll *statistics.HistColl, exprs []expression.Expression, filledPaths []*planutil.AccessPath, @@ -671,7 +671,7 @@ func isColEqCorCol(filter expression.Expression) *expression.Column { // findPrefixOfIndexByCol will find columns in index by checking the unique id or the virtual expression. // So it will return at once no matching column is found. -func findPrefixOfIndexByCol(ctx context.PlanContext, cols []*expression.Column, idxColIDs []int64, +func findPrefixOfIndexByCol(ctx planctx.PlanContext, cols []*expression.Column, idxColIDs []int64, cachedPath *planutil.AccessPath) []*expression.Column { if cachedPath != nil { evalCtx := ctx.GetExprCtx().GetEvalCtx() @@ -693,7 +693,7 @@ func findPrefixOfIndexByCol(ctx context.PlanContext, cols []*expression.Column, return expression.FindPrefixOfIndex(cols, idxColIDs) } -func getMaskAndRanges(ctx context.PlanContext, exprs []expression.Expression, rangeType ranger.RangeType, +func getMaskAndRanges(ctx planctx.PlanContext, exprs []expression.Expression, rangeType ranger.RangeType, lengths []int, cachedPath *planutil.AccessPath, cols ...*expression.Column) ( mask int64, ranges []*ranger.Range, partCover bool, err error) { isDNF := false @@ -737,7 +737,7 @@ func getMaskAndRanges(ctx context.PlanContext, exprs []expression.Expression, ra } func getMaskAndSelectivityForMVIndex( - ctx context.PlanContext, + ctx planctx.PlanContext, coll *statistics.HistColl, id int64, exprs []expression.Expression, @@ -768,7 +768,7 @@ func getMaskAndSelectivityForMVIndex( // GetSelectivityByFilter try to estimate selectivity of expressions by evaluate the expressions using TopN, Histogram buckets boundaries and NULL. // Currently, this method can only handle expressions involving a single column. -func GetSelectivityByFilter(sctx context.PlanContext, coll *statistics.HistColl, filters []expression.Expression) (ok bool, selectivity float64, err error) { +func GetSelectivityByFilter(sctx planctx.PlanContext, coll *statistics.HistColl, filters []expression.Expression) (ok bool, selectivity float64, err error) { // 1. Make sure the expressions // (1) are safe to be evaluated here, // (2) involve only one column, @@ -917,7 +917,7 @@ func GetSelectivityByFilter(sctx context.PlanContext, coll *statistics.HistColl, return true, res, err } -func findAvailableStatsForCol(sctx context.PlanContext, coll *statistics.HistColl, uniqueID int64) (isIndex bool, idx int64) { +func findAvailableStatsForCol(sctx planctx.PlanContext, coll *statistics.HistColl, uniqueID int64) (isIndex bool, idx int64) { // try to find available stats in column stats if colStats := coll.GetCol(uniqueID); !statistics.ColumnStatsIsInvalid(colStats, sctx, coll, uniqueID) && colStats.IsFullLoad() { return false, uniqueID @@ -937,7 +937,7 @@ func findAvailableStatsForCol(sctx context.PlanContext, coll *statistics.HistCol } // getEqualCondSelectivity gets the selectivity of the equal conditions. -func getEqualCondSelectivity(sctx context.PlanContext, coll *statistics.HistColl, idx *statistics.Index, bytes []byte, +func getEqualCondSelectivity(sctx planctx.PlanContext, coll *statistics.HistColl, idx *statistics.Index, bytes []byte, usedColsLen int, idxPointRange *ranger.Range) (result float64, err error) { if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) @@ -1002,7 +1002,7 @@ func getEqualCondSelectivity(sctx context.PlanContext, coll *statistics.HistColl // and has the same distribution with analyzed rows, which means each unique value should have the // same number of rows(Tot/NDV) of it. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func outOfRangeEQSelectivity(sctx context.PlanContext, ndv, realtimeRowCount, columnRowCount int64) (result float64) { +func outOfRangeEQSelectivity(sctx planctx.PlanContext, ndv, realtimeRowCount, columnRowCount int64) (result float64) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { @@ -1026,7 +1026,7 @@ func outOfRangeEQSelectivity(sctx context.PlanContext, ndv, realtimeRowCount, co // crossValidationSelectivity gets the selectivity of multi-column equal conditions by cross validation. func crossValidationSelectivity( - sctx context.PlanContext, + sctx planctx.PlanContext, coll *statistics.HistColl, idx *statistics.Index, usedColsLen int, @@ -1093,7 +1093,7 @@ func crossValidationSelectivity( // defined in planner/core package and hard to move here. So we use this trick to avoid the import cycle. var ( CollectFilters4MVIndex func( - sctx context.PlanContext, + sctx planctx.PlanContext, filters []expression.Expression, idxCols []*expression.Column, ) ( @@ -1102,7 +1102,7 @@ var ( accessTp int, ) BuildPartialPaths4MVIndex func( - sctx context.PlanContext, + sctx planctx.PlanContext, accessFilters []expression.Expression, idxCols []*expression.Column, mvIndex *model.IndexInfo, diff --git a/pkg/planner/cardinality/trace.go b/pkg/planner/cardinality/trace.go index 42513d8c4f742..43fc43d92882c 100644 --- a/pkg/planner/cardinality/trace.go +++ b/pkg/planner/cardinality/trace.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/format" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/statistics" @@ -37,7 +37,7 @@ import ( ) // ceTraceExpr appends an expression and related information into CE trace -func ceTraceExpr(sctx context.PlanContext, tableID int64, tp string, expr expression.Expression, rowCount float64) { +func ceTraceExpr(sctx planctx.PlanContext, tableID int64, tp string, expr expression.Expression, rowCount float64) { exprStr, err := exprToString(sctx.GetExprCtx().GetEvalCtx(), expr) if err != nil { logutil.BgLogger().Debug("Failed to trace CE of an expression", zap.String("category", "OptimizerTrace"), @@ -126,7 +126,7 @@ type getRowCountInput struct { } func debugTraceGetRowCountInput( - s context.PlanContext, + s planctx.PlanContext, id int64, ranges ranger.Ranges, ) { @@ -142,10 +142,10 @@ func debugTraceGetRowCountInput( } // GetTblInfoForUsedStatsByPhysicalID get table name, partition name and TableInfo that will be used to record used stats. -var GetTblInfoForUsedStatsByPhysicalID func(sctx context.PlanContext, id int64) (fullName string, tblInfo *model.TableInfo) +var GetTblInfoForUsedStatsByPhysicalID func(sctx planctx.PlanContext, id int64) (fullName string, tblInfo *model.TableInfo) // recordUsedItemStatsStatus only records un-FullLoad item load status during user query -func recordUsedItemStatsStatus(sctx context.PlanContext, stats any, tableID, id int64) { +func recordUsedItemStatsStatus(sctx planctx.PlanContext, stats any, tableID, id int64) { // Sometimes we try to use stats on _tidb_rowid (id == -1), which must be empty, we ignore this case here. if id <= 0 { return @@ -213,7 +213,7 @@ func recordUsedItemStatsStatus(sctx context.PlanContext, stats any, tableID, id } // ceTraceRange appends a list of ranges and related information into CE trace -func ceTraceRange(sctx context.PlanContext, tableID int64, colNames []string, ranges []*ranger.Range, tp string, rowCount uint64) { +func ceTraceRange(sctx planctx.PlanContext, tableID int64, colNames []string, ranges []*ranger.Range, tp string, rowCount uint64) { sc := sctx.GetSessionVars().StmtCtx tc := sc.TypeCtx() allPoint := true @@ -257,7 +257,7 @@ type startEstimateRangeInfo struct { } func debugTraceStartEstimateRange( - s context.PlanContext, + s planctx.PlanContext, r *ranger.Range, lowBytes, highBytes []byte, currentCount float64, @@ -302,7 +302,7 @@ type endEstimateRangeInfo struct { } func debugTraceEndEstimateRange( - s context.PlanContext, + s planctx.PlanContext, count float64, addType debugTraceAddRowCountType, ) { diff --git a/pkg/planner/cascades/BUILD.bazel b/pkg/planner/cascades/BUILD.bazel index f6e7fed103137..115b5a3cfe87f 100644 --- a/pkg/planner/cascades/BUILD.bazel +++ b/pkg/planner/cascades/BUILD.bazel @@ -17,7 +17,6 @@ go_library( "//pkg/kv", "//pkg/parser/ast", "//pkg/parser/mysql", - "//pkg/planner/context", "//pkg/planner/core", "//pkg/planner/core/base", "//pkg/planner/core/operator/logicalop", @@ -25,6 +24,7 @@ go_library( "//pkg/planner/implementation", "//pkg/planner/memo", "//pkg/planner/pattern", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/planner/util", "//pkg/planner/util/coreusage", diff --git a/pkg/planner/cascades/transformation_rules.go b/pkg/planner/cascades/transformation_rules.go index a18cbc55ef449..355e328464f12 100644 --- a/pkg/planner/cascades/transformation_rules.go +++ b/pkg/planner/cascades/transformation_rules.go @@ -22,13 +22,13 @@ import ( "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/core/operator/logicalop" ruleutil "github.com/pingcap/tidb/pkg/planner/core/rule/util" "github.com/pingcap/tidb/pkg/planner/memo" "github.com/pingcap/tidb/pkg/planner/pattern" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/planner/util/coreusage" "github.com/pingcap/tidb/pkg/types" @@ -853,7 +853,7 @@ type pushDownJoin struct { } func (*pushDownJoin) predicatePushDown( - sctx context.PlanContext, + sctx planctx.PlanContext, predicates []expression.Expression, join *logicalop.LogicalJoin, leftSchema *expression.Schema, @@ -975,7 +975,7 @@ func (r *PushSelDownJoin) Match(expr *memo.ExprIter) bool { // buildChildSelectionGroup builds a new childGroup if the pushed down condition is not empty. func buildChildSelectionGroup( - sctx context.PlanContext, + sctx planctx.PlanContext, qbOffset int, conditions []expression.Expression, childGroup *memo.Group) *memo.Group { diff --git a/pkg/planner/core/BUILD.bazel b/pkg/planner/core/BUILD.bazel index b511fdfbde465..e2888d08c3c03 100644 --- a/pkg/planner/core/BUILD.bazel +++ b/pkg/planner/core/BUILD.bazel @@ -105,8 +105,8 @@ go_library( "//pkg/errctx", "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/context", - "//pkg/expression/contextopt", + "//pkg/expression/exprctx", + "//pkg/expression/expropt", "//pkg/infoschema", "//pkg/infoschema/context", "//pkg/kv", @@ -127,7 +127,6 @@ go_library( "//pkg/parser/types", "//pkg/planner/cardinality", "//pkg/planner/cascades/base", - "//pkg/planner/context", "//pkg/planner/core/base", "//pkg/planner/core/constraint", "//pkg/planner/core/cost", @@ -139,6 +138,7 @@ go_library( "//pkg/planner/core/rule", "//pkg/planner/core/rule/util", "//pkg/planner/funcdep", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/planner/util", "//pkg/planner/util/coreusage", @@ -275,9 +275,9 @@ go_test( "//pkg/domain", "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/context", - "//pkg/expression/contextopt", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/expropt", + "//pkg/expression/exprstatic", "//pkg/infoschema", "//pkg/kv", "//pkg/meta/model", diff --git a/pkg/planner/core/base/BUILD.bazel b/pkg/planner/core/base/BUILD.bazel index 42317eeeb8c48..74f31a04db635 100644 --- a/pkg/planner/core/base/BUILD.bazel +++ b/pkg/planner/core/base/BUILD.bazel @@ -15,8 +15,8 @@ go_library( "//pkg/expression", "//pkg/kv", "//pkg/planner/cascades/base", - "//pkg/planner/context", "//pkg/planner/funcdep", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/planner/util/costusage", "//pkg/planner/util/optimizetrace", diff --git a/pkg/planner/core/base/plan_base.go b/pkg/planner/core/base/plan_base.go index 9f3dc04c91bf2..ded50bc795c9d 100644 --- a/pkg/planner/core/base/plan_base.go +++ b/pkg/planner/core/base/plan_base.go @@ -20,8 +20,8 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/planner/cascades/base" - "github.com/pingcap/tidb/pkg/planner/context" fd "github.com/pingcap/tidb/pkg/planner/funcdep" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" "github.com/pingcap/tidb/pkg/planner/util/costusage" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" @@ -32,10 +32,10 @@ import ( ) // PlanContext is the context for building plan. -type PlanContext = context.PlanContext +type PlanContext = planctx.PlanContext // BuildPBContext is the context for building `*tipb.Executor`. -type BuildPBContext = context.BuildPBContext +type BuildPBContext = planctx.BuildPBContext // Note: appending the new adding method to the last, for the convenience of easy // locating in other implementor from other package. diff --git a/pkg/planner/core/casetest/rule/BUILD.bazel b/pkg/planner/core/casetest/rule/BUILD.bazel index f00aaebfc37d6..a97ca00c4945b 100644 --- a/pkg/planner/core/casetest/rule/BUILD.bazel +++ b/pkg/planner/core/casetest/rule/BUILD.bazel @@ -18,7 +18,7 @@ go_test( "//pkg/domain", "//pkg/expression", "//pkg/expression/aggregation", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/parser/ast", "//pkg/parser/mysql", "//pkg/planner/util/coretestsdk", diff --git a/pkg/planner/core/casetest/rule/rule_inject_extra_projection_test.go b/pkg/planner/core/casetest/rule/rule_inject_extra_projection_test.go index 4f84299f3f3a9..f490df4382cf6 100644 --- a/pkg/planner/core/casetest/rule/rule_inject_extra_projection_test.go +++ b/pkg/planner/core/casetest/rule/rule_inject_extra_projection_test.go @@ -19,7 +19,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/expression/aggregation" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/planner/util/coreusage" @@ -29,7 +29,7 @@ import ( ) func TestWrapCastForAggFuncs(t *testing.T) { - ctx := contextstatic.NewStaticEvalContext() + ctx := exprstatic.NewEvalContext() aggNames := []string{ast.AggFuncSum} modes := []aggregation.AggFunctionMode{aggregation.CompleteMode, diff --git a/pkg/planner/core/debugtrace.go b/pkg/planner/core/debugtrace.go index 688f724524cb3..254c278847ed1 100644 --- a/pkg/planner/core/debugtrace.go +++ b/pkg/planner/core/debugtrace.go @@ -24,8 +24,8 @@ import ( "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/statistics" @@ -137,7 +137,7 @@ func (b *bindingHint) MarshalJSON() ([]byte, error) { } // DebugTraceTryBinding records the hint that might be chosen to the debug trace. -func DebugTraceTryBinding(s context.PlanContext, binding *hint.HintsSet) { +func DebugTraceTryBinding(s planctx.PlanContext, binding *hint.HintsSet) { root := debugtrace.GetOrInitDebugTraceRoot(s) traceInfo := &bindingHint{ Hint: binding, @@ -147,7 +147,7 @@ func DebugTraceTryBinding(s context.PlanContext, binding *hint.HintsSet) { } // DebugTraceBestBinding records the chosen hint to the debug trace. -func DebugTraceBestBinding(s context.PlanContext, binding *hint.HintsSet) { +func DebugTraceBestBinding(s planctx.PlanContext, binding *hint.HintsSet) { root := debugtrace.GetOrInitDebugTraceRoot(s) traceInfo := &bindingHint{ Hint: binding, diff --git a/pkg/planner/core/expression_rewriter.go b/pkg/planner/core/expression_rewriter.go index 1fc3b2c416978..0d5caa6632fe4 100644 --- a/pkg/planner/core/expression_rewriter.go +++ b/pkg/planner/core/expression_rewriter.go @@ -23,8 +23,8 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/expression/aggregation" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" @@ -1664,7 +1664,7 @@ func (er *expressionRewriter) rewriteUserVariable(v *ast.VariableExpr) { return } - sessionVars, err := contextopt.SessionVarsPropReader{}.GetSessionVars(evalCtx) + sessionVars, err := expropt.SessionVarsPropReader{}.GetSessionVars(evalCtx) if err != nil { er.err = err return diff --git a/pkg/planner/core/expression_test.go b/pkg/planner/core/expression_test.go index 4b5b171fd0075..4d56aa96ff260 100644 --- a/pkg/planner/core/expression_test.go +++ b/pkg/planner/core/expression_test.go @@ -20,9 +20,9 @@ import ( "github.com/pingcap/tidb/pkg/domain" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextopt" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/expropt" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/ast" @@ -409,17 +409,17 @@ func TestBuildExpression(t *testing.T) { }, } - ctx := contextstatic.NewStaticExprContext() + ctx := exprstatic.NewExprContext() evalCtx := ctx.GetStaticEvalCtx() cols, names, err := expression.ColumnInfos2ColumnsAndNames(ctx, pmodel.NewCIStr(""), tbl.Name, tbl.Cols(), tbl) require.NoError(t, err) schema := expression.NewSchema(cols...) // normal build - ctx = ctx.Apply(contextstatic.WithColumnIDAllocator(context.NewSimplePlanColumnIDAllocator(0))) + ctx = ctx.Apply(exprstatic.WithColumnIDAllocator(exprctx.NewSimplePlanColumnIDAllocator(0))) expr, err := buildExpr(t, ctx, "(1+a)*(3+b)", expression.WithTableInfo("", tbl)) require.NoError(t, err) - ctx = ctx.Apply(contextstatic.WithColumnIDAllocator(context.NewSimplePlanColumnIDAllocator(0))) + ctx = ctx.Apply(exprstatic.WithColumnIDAllocator(exprctx.NewSimplePlanColumnIDAllocator(0))) expr2, err := expression.ParseSimpleExpr(ctx, "(1+a)*(3+b)", expression.WithTableInfo("", tbl)) require.NoError(t, err) require.True(t, expr.Equal(evalCtx, expr2)) @@ -494,8 +494,8 @@ func TestBuildExpression(t *testing.T) { // param marker params := variable.NewPlanCacheParamList() params.Append(types.NewIntDatum(5)) - evalCtx = evalCtx.Apply(contextstatic.WithParamList(params)) - ctx = ctx.Apply(contextstatic.WithEvalCtx(evalCtx)) + evalCtx = evalCtx.Apply(exprstatic.WithParamList(params)) + ctx = ctx.Apply(exprstatic.WithEvalCtx(evalCtx)) expr, err = buildExpr(t, ctx, "a + ?", expression.WithTableInfo("", tbl)) require.NoError(t, err) require.Equal(t, mysql.TypeLonglong, expr.GetType(evalCtx).GetType()) @@ -512,8 +512,8 @@ func TestBuildExpression(t *testing.T) { vars := variable.NewSessionVars(nil) vars.TimeZone = evalCtx.Location() vars.StmtCtx.SetTimeZone(vars.Location()) - evalCtx = evalCtx.Apply(contextstatic.WithUserVarsReader(vars.GetSessionVars().UserVars)) - ctx = ctx.Apply(contextstatic.WithEvalCtx(evalCtx)) + evalCtx = evalCtx.Apply(exprstatic.WithUserVarsReader(vars.GetSessionVars().UserVars)) + ctx = ctx.Apply(exprstatic.WithEvalCtx(evalCtx)) vars.SetUserVarVal("a", types.NewStringDatum("abc")) getVarExpr, err := buildExpr(t, ctx, "@a") require.NoError(t, err) @@ -523,8 +523,8 @@ func TestBuildExpression(t *testing.T) { require.Equal(t, "abc", v.GetString()) // writing user var - evalCtx = evalCtx.Apply(contextstatic.WithOptionalProperty(contextopt.NewSessionVarsProvider(vars))) - ctx = ctx.Apply(contextstatic.WithEvalCtx(evalCtx)) + evalCtx = evalCtx.Apply(exprstatic.WithOptionalProperty(expropt.NewSessionVarsProvider(vars))) + ctx = ctx.Apply(exprstatic.WithEvalCtx(evalCtx)) expr, err = buildExpr(t, ctx, "@a := 'def'") require.NoError(t, err) v, err = expr.Eval(evalCtx, chunk.Row{}) diff --git a/pkg/planner/core/index_join_path.go b/pkg/planner/core/index_join_path.go index d34821de013c6..00ee5ba8dbf68 100644 --- a/pkg/planner/core/index_join_path.go +++ b/pkg/planner/core/index_join_path.go @@ -24,8 +24,8 @@ import ( "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/planner/cardinality" - "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/operator/logicalop" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/statistics" @@ -66,7 +66,7 @@ func (mr *mutableIndexJoinRange) Range() ranger.Ranges { return mr.ranges } -func (mr *mutableIndexJoinRange) Rebuild(sctx context.PlanContext) error { +func (mr *mutableIndexJoinRange) Rebuild(sctx planctx.PlanContext) error { result, empty, err := indexJoinPathBuild(sctx, mr.path, mr.indexJoinInfo, true) if err != nil { return err @@ -128,7 +128,7 @@ type indexJoinTmpRange struct { // indexJoinPathNewMutableRange creates a mutableIndexJoinRange. // See more info in the comments of mutableIndexJoinRange. func indexJoinPathNewMutableRange( - sctx context.PlanContext, + sctx planctx.PlanContext, indexJoinInfo *indexJoinPathInfo, relatedExprs []expression.Expression, ranges []*ranger.Range, @@ -146,7 +146,7 @@ func indexJoinPathNewMutableRange( } func indexJoinPathUpdateTmpRange( - sctx context.PlanContext, + sctx planctx.PlanContext, buildTmp *indexJoinPathTmp, tempRangeRes *indexJoinTmpRange, accesses, remained []expression.Expression) (lastColPos int, newAccesses, newRemained []expression.Expression) { @@ -163,7 +163,7 @@ func indexJoinPathUpdateTmpRange( // indexJoinPathBuild tries to build an index join on this specified access path. // The result is recorded in the *indexJoinPathResult, see more info in that structure. -func indexJoinPathBuild(sctx context.PlanContext, +func indexJoinPathBuild(sctx planctx.PlanContext, path *util.AccessPath, indexJoinInfo *indexJoinPathInfo, rebuildMode bool) (result *indexJoinPathResult, emptyRange bool, err error) { @@ -334,7 +334,7 @@ func indexJoinPathConstructResult( } func indexJoinPathBuildTmpRange( - sctx context.PlanContext, + sctx planctx.PlanContext, buildTmp *indexJoinPathTmp, matchedKeyCnt int, eqAndInFuncs []expression.Expression, @@ -424,7 +424,7 @@ func indexJoinPathBuildTmpRange( } // indexJoinPathRangeInfo generates the range information for the index join path. -func indexJoinPathRangeInfo(sctx context.PlanContext, +func indexJoinPathRangeInfo(sctx planctx.PlanContext, outerJoinKeys []*expression.Column, indexJoinResult *indexJoinPathResult) string { buffer := bytes.NewBufferString("[") @@ -466,7 +466,7 @@ For each idxCols, // For example, innerKeys[t1.a, t1.sum_b, t1.c], idxCols [a, b, c] // 'curIdxOff2KeyOff' = [0, -1, 2] func indexJoinPathTmpInit( - sctx context.PlanContext, + sctx planctx.PlanContext, indexJoinInfo *indexJoinPathInfo, idxCols []*expression.Column, colLens []int) *indexJoinPathTmp { @@ -500,7 +500,7 @@ func indexJoinPathTmpInit( // usefulEqOrInFilters is the continuous eq/in conditions on current unused index columns. // remainedEqOrIn is part of usefulEqOrInFilters, which needs to be evaluated again in selection. // remainingRangeCandidates is the other conditions for future use. -func indexJoinPathFindUsefulEQIn(sctx context.PlanContext, indexJoinInfo *indexJoinPathInfo, +func indexJoinPathFindUsefulEQIn(sctx planctx.PlanContext, indexJoinInfo *indexJoinPathInfo, buildTmp *indexJoinPathTmp) (usefulEqOrInFilters, remainedEqOrIn, remainingRangeCandidates []expression.Expression, emptyRange bool) { // Extract the eq/in functions of possible join key. // you can see the comment of ExtractEqAndInCondition to get the meaning of the second return value. diff --git a/pkg/planner/core/indexmerge_path.go b/pkg/planner/core/indexmerge_path.go index 62844e1958050..08acf010b82da 100644 --- a/pkg/planner/core/indexmerge_path.go +++ b/pkg/planner/core/indexmerge_path.go @@ -28,9 +28,9 @@ import ( "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/planner/cardinality" - "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/core/cost" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/planner/util/fixcontrol" @@ -1118,7 +1118,7 @@ func buildPartialPathUp4MVIndex( // The accessFilters must be corresponding to these idxCols. // OK indicates whether it builds successfully. These partial paths should be ignored if ok==false. func buildPartialPaths4MVIndex( - sctx context.PlanContext, + sctx planctx.PlanContext, accessFilters []expression.Expression, idxCols []*expression.Column, mvIndex *model.IndexInfo, @@ -1247,7 +1247,7 @@ func isSafeTypeConversion4MVIndexRange(valType, mvIndexType *types.FieldType) (s // buildPartialPath4MVIndex builds a partial path on this MVIndex with these accessFilters. func buildPartialPath4MVIndex( - sctx context.PlanContext, + sctx planctx.PlanContext, accessFilters []expression.Expression, idxCols []*expression.Column, mvIndex *model.IndexInfo, @@ -1323,7 +1323,7 @@ func PrepareIdxColsAndUnwrapArrayType( // For idx(x, cast(a as array), z), `x=1 and (2 member of a) and z=1 and x+z>0` is split to: // accessFilters: `x=1 and (2 member of a) and z=1`, remaining: `x+z>0`. func collectFilters4MVIndex( - sctx context.PlanContext, + sctx planctx.PlanContext, filters []expression.Expression, idxCols []*expression.Column, ) (accessFilters, remainingFilters []expression.Expression, accessTp int) { diff --git a/pkg/planner/core/logical_plan_builder.go b/pkg/planner/core/logical_plan_builder.go index d48cee0af1fca..fe3c0f7f41ce3 100644 --- a/pkg/planner/core/logical_plan_builder.go +++ b/pkg/planner/core/logical_plan_builder.go @@ -31,7 +31,7 @@ import ( "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/expression/aggregation" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" diff --git a/pkg/planner/core/operator/baseimpl/BUILD.bazel b/pkg/planner/core/operator/baseimpl/BUILD.bazel index 426ef4ee414bf..01c216d35fda2 100644 --- a/pkg/planner/core/operator/baseimpl/BUILD.bazel +++ b/pkg/planner/core/operator/baseimpl/BUILD.bazel @@ -7,8 +7,8 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/expression", - "//pkg/planner/context", "//pkg/planner/core/base", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/types", "//pkg/util/stringutil", diff --git a/pkg/planner/core/operator/baseimpl/plan.go b/pkg/planner/core/operator/baseimpl/plan.go index 81eaf76d16d23..60459a651d1fa 100644 --- a/pkg/planner/core/operator/baseimpl/plan.go +++ b/pkg/planner/core/operator/baseimpl/plan.go @@ -20,8 +20,8 @@ import ( "unsafe" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/stringutil" @@ -30,7 +30,7 @@ import ( // Plan Should be used as embedded struct in Plan implementations. type Plan struct { - ctx context.PlanContext + ctx planctx.PlanContext stats *property.StatsInfo `plan-cache-clone:"shallow"` tp string id int @@ -38,7 +38,7 @@ type Plan struct { } // NewBasePlan creates a new base plan. -func NewBasePlan(ctx context.PlanContext, tp string, qbBlock int) Plan { +func NewBasePlan(ctx planctx.PlanContext, tp string, qbBlock int) Plan { id := ctx.GetSessionVars().PlanID.Add(1) return Plan{ tp: tp, @@ -49,12 +49,12 @@ func NewBasePlan(ctx context.PlanContext, tp string, qbBlock int) Plan { } // SCtx is to get the sessionctx from the plan. -func (p *Plan) SCtx() context.PlanContext { +func (p *Plan) SCtx() planctx.PlanContext { return p.ctx } // SetSCtx is to set the sessionctx for the plan. -func (p *Plan) SetSCtx(ctx context.PlanContext) { +func (p *Plan) SetSCtx(ctx planctx.PlanContext) { p.ctx = ctx } diff --git a/pkg/planner/core/plan_clone_generator.go b/pkg/planner/core/plan_clone_generator.go index b827aa1bfc0d2..2299f53b21098 100644 --- a/pkg/planner/core/plan_clone_generator.go +++ b/pkg/planner/core/plan_clone_generator.go @@ -110,7 +110,7 @@ func genPlanCloneForPlanCache(x any) ([]byte, error) { case "[][]*expression.Constant", "[][]types.Datum", "[][]expression.Expression": structureName := strings.Split(f.Type.String(), ".")[1] c.write("cloned.%v = util.Clone%v2D(op.%v)", f.Name, structureName, f.Name) - case "context.PlanContext": + case "planctx.PlanContext": c.write("cloned.%v = newCtx", f.Name) case "util.HandleCols": c.write("if op.%v != nil {", f.Name) diff --git a/pkg/planner/optimize.go b/pkg/planner/optimize.go index 808d467a76bb9..1c1f06fd6c04d 100644 --- a/pkg/planner/optimize.go +++ b/pkg/planner/optimize.go @@ -31,11 +31,11 @@ import ( "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/planner/cascades" - pctx "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/core/resolve" "github.com/pingcap/tidb/pkg/planner/indexadvisor" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/property" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" @@ -398,7 +398,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node *resolve.NodeW, // OptimizeForForeignKeyCascade does optimization and creates a Plan for foreign key cascade. // Compare to Optimize, OptimizeForForeignKeyCascade only build plan by StmtNode, // doesn't consider plan cache and plan binding, also doesn't do privilege check. -func OptimizeForForeignKeyCascade(ctx context.Context, sctx pctx.PlanContext, node *resolve.NodeW, is infoschema.InfoSchema) (base.Plan, error) { +func OptimizeForForeignKeyCascade(ctx context.Context, sctx planctx.PlanContext, node *resolve.NodeW, is infoschema.InfoSchema) (base.Plan, error) { builder := planBuilderPool.Get().(*core.PlanBuilder) defer planBuilderPool.Put(builder.ResetForReuse()) hintProcessor := hint.NewQBHintHandler(sctx.GetSessionVars().StmtCtx) @@ -413,7 +413,7 @@ func OptimizeForForeignKeyCascade(ctx context.Context, sctx pctx.PlanContext, no return p, nil } -func allowInReadOnlyMode(sctx pctx.PlanContext, node ast.Node) (bool, error) { +func allowInReadOnlyMode(sctx planctx.PlanContext, node ast.Node) (bool, error) { pm := privilege.GetPrivilegeManager(sctx) if pm == nil { return true, nil @@ -462,7 +462,7 @@ var planBuilderPool = sync.Pool{ // optimizeCnt is a global variable only used for test. var optimizeCnt int -func optimize(ctx context.Context, sctx pctx.PlanContext, node *resolve.NodeW, is infoschema.InfoSchema) (base.Plan, types.NameSlice, float64, error) { +func optimize(ctx context.Context, sctx planctx.PlanContext, node *resolve.NodeW, is infoschema.InfoSchema) (base.Plan, types.NameSlice, float64, error) { failpoint.Inject("checkOptimizeCountOne", func(val failpoint.Value) { // only count the optimization for SQL with specified text if testSQL, ok := val.(string); ok && testSQL == node.Node.OriginalText() { @@ -559,7 +559,7 @@ func OptimizeExecStmt(ctx context.Context, sctx sessionctx.Context, return exec, names, nil } -func buildLogicalPlan(ctx context.Context, sctx pctx.PlanContext, node *resolve.NodeW, builder *core.PlanBuilder) (base.Plan, error) { +func buildLogicalPlan(ctx context.Context, sctx planctx.PlanContext, node *resolve.NodeW, builder *core.PlanBuilder) (base.Plan, error) { sctx.GetSessionVars().PlanID.Store(0) sctx.GetSessionVars().PlanColumnID.Store(0) sctx.GetSessionVars().MapScalarSubQ = nil @@ -585,7 +585,7 @@ func buildLogicalPlan(ctx context.Context, sctx pctx.PlanContext, node *resolve. return p, nil } -func handleInvalidBinding(ctx context.Context, sctx pctx.PlanContext, level string, binding bindinfo.Binding) { +func handleInvalidBinding(ctx context.Context, sctx planctx.PlanContext, level string, binding bindinfo.Binding) { sessionHandle := sctx.Value(bindinfo.SessionBindInfoKeyType).(bindinfo.SessionBindingHandle) err := sessionHandle.DropSessionBinding([]string{binding.SQLDigest}) if err != nil { diff --git a/pkg/planner/context/BUILD.bazel b/pkg/planner/planctx/BUILD.bazel similarity index 75% rename from pkg/planner/context/BUILD.bazel rename to pkg/planner/planctx/BUILD.bazel index b0a9cf7a57db6..e981a1bb1374f 100644 --- a/pkg/planner/context/BUILD.bazel +++ b/pkg/planner/planctx/BUILD.bazel @@ -1,12 +1,12 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "context", + name = "planctx", srcs = ["context.go"], - importpath = "github.com/pingcap/tidb/pkg/planner/context", + importpath = "github.com/pingcap/tidb/pkg/planner/planctx", visibility = ["//visibility:public"], deps = [ - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema/context", "//pkg/kv", "//pkg/lock/context", @@ -20,13 +20,13 @@ go_library( ) go_test( - name = "context_test", + name = "planctx_test", timeout = "short", srcs = ["context_test.go"], - embed = [":context"], + embed = [":planctx"], flaky = True, deps = [ - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/util/context", "//pkg/util/deeptest", "@com_github_stretchr_testify//require", diff --git a/pkg/planner/context/context.go b/pkg/planner/planctx/context.go similarity index 98% rename from pkg/planner/context/context.go rename to pkg/planner/planctx/context.go index a53f9e86d4965..7a61c2a7e08e9 100644 --- a/pkg/planner/context/context.go +++ b/pkg/planner/planctx/context.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package planctx import ( - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" tablelock "github.com/pingcap/tidb/pkg/lock/context" diff --git a/pkg/planner/context/context_test.go b/pkg/planner/planctx/context_test.go similarity index 92% rename from pkg/planner/context/context_test.go rename to pkg/planner/planctx/context_test.go index 564565b4fc6f2..ece579a6b81b9 100644 --- a/pkg/planner/context/context_test.go +++ b/pkg/planner/planctx/context_test.go @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package planctx import ( "testing" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" contextutil "github.com/pingcap/tidb/pkg/util/context" "github.com/pingcap/tidb/pkg/util/deeptest" "github.com/stretchr/testify/require" @@ -26,7 +26,7 @@ import ( func TestContextDetach(t *testing.T) { warnHandler := contextutil.NewStaticWarnHandler(5) obj := &BuildPBContext{ - ExprCtx: contextstatic.NewStaticExprContext(), + ExprCtx: exprstatic.NewExprContext(), TiFlashFastScan: true, TiFlashFineGrainedShuffleBatchSize: 1, GroupConcatMaxLen: 1, diff --git a/pkg/planner/contextimpl/BUILD.bazel b/pkg/planner/plannersession/BUILD.bazel similarity index 52% rename from pkg/planner/contextimpl/BUILD.bazel rename to pkg/planner/plannersession/BUILD.bazel index fa66dbfb08ea1..015ced913217f 100644 --- a/pkg/planner/contextimpl/BUILD.bazel +++ b/pkg/planner/plannersession/BUILD.bazel @@ -1,13 +1,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( - name = "contextimpl", - srcs = ["impl.go"], - importpath = "github.com/pingcap/tidb/pkg/planner/contextimpl", + name = "plannersession", + srcs = ["context.go"], + importpath = "github.com/pingcap/tidb/pkg/planner/plannersession", visibility = ["//visibility:public"], deps = [ - "//pkg/expression/context", - "//pkg/planner/context", + "//pkg/expression/exprctx", + "//pkg/planner/planctx", "//pkg/sessionctx", "//pkg/sessiontxn", "//pkg/util/intest", diff --git a/pkg/planner/contextimpl/impl.go b/pkg/planner/plannersession/context.go similarity index 69% rename from pkg/planner/contextimpl/impl.go rename to pkg/planner/plannersession/context.go index 0d42754861e30..35cdd8017be76 100644 --- a/pkg/planner/contextimpl/impl.go +++ b/pkg/planner/plannersession/context.go @@ -12,37 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextimpl +package plannersession import ( - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessiontxn" "github.com/pingcap/tidb/pkg/util/intest" ) -var _ context.PlanContext = struct { +var _ planctx.PlanContext = struct { sessionctx.Context - *PlanCtxExtendedImpl + *PlanCtxExtended }{} -// PlanCtxExtendedImpl provides extended method for session context to implement `PlanContext` -type PlanCtxExtendedImpl struct { +// PlanCtxExtended provides extended method for session context to implement `PlanContext` +type PlanCtxExtended struct { sctx sessionctx.Context nullRejectCheckExprCtx *exprctx.NullRejectCheckExprContext } -// NewPlanCtxExtendedImpl creates a new PlanCtxExtendedImpl. -func NewPlanCtxExtendedImpl(sctx sessionctx.Context) *PlanCtxExtendedImpl { - return &PlanCtxExtendedImpl{ +// NewPlanCtxExtended creates a new PlanCtxExtended. +func NewPlanCtxExtended(sctx sessionctx.Context) *PlanCtxExtended { + return &PlanCtxExtended{ sctx: sctx, nullRejectCheckExprCtx: exprctx.WithNullRejectCheck(sctx.GetExprCtx()), } } // GetNullRejectCheckExprCtx returns a context with null rejected check -func (ctx *PlanCtxExtendedImpl) GetNullRejectCheckExprCtx() exprctx.ExprContext { +func (ctx *PlanCtxExtended) GetNullRejectCheckExprCtx() exprctx.ExprContext { intest.AssertFunc(func() bool { // assert `sctx.GetExprCtx()` should keep the same to avoid some unexpected behavior. return ctx.nullRejectCheckExprCtx.ExprContext == ctx.sctx.GetExprCtx() @@ -51,6 +51,6 @@ func (ctx *PlanCtxExtendedImpl) GetNullRejectCheckExprCtx() exprctx.ExprContext } // AdviseTxnWarmup advises the txn to warm up. -func (ctx *PlanCtxExtendedImpl) AdviseTxnWarmup() error { +func (ctx *PlanCtxExtended) AdviseTxnWarmup() error { return sessiontxn.GetTxnManager(ctx.sctx).AdviseWarmup() } diff --git a/pkg/planner/util/BUILD.bazel b/pkg/planner/util/BUILD.bazel index f10b9e3ecd9ed..b0cf22491e10a 100644 --- a/pkg/planner/util/BUILD.bazel +++ b/pkg/planner/util/BUILD.bazel @@ -21,9 +21,9 @@ go_library( "//pkg/parser/ast", "//pkg/parser/model", "//pkg/parser/mysql", - "//pkg/planner/context", "//pkg/planner/core/base", "//pkg/planner/funcdep", + "//pkg/planner/planctx", "//pkg/planner/property", "//pkg/sessionctx/stmtctx", "//pkg/tablecodec", diff --git a/pkg/planner/util/debugtrace/BUILD.bazel b/pkg/planner/util/debugtrace/BUILD.bazel index 13deb51fd2a5d..1482749eddfa5 100644 --- a/pkg/planner/util/debugtrace/BUILD.bazel +++ b/pkg/planner/util/debugtrace/BUILD.bazel @@ -5,5 +5,5 @@ go_library( srcs = ["base.go"], importpath = "github.com/pingcap/tidb/pkg/planner/util/debugtrace", visibility = ["//visibility:public"], - deps = ["//pkg/planner/context"], + deps = ["//pkg/planner/planctx"], ) diff --git a/pkg/planner/util/debugtrace/base.go b/pkg/planner/util/debugtrace/base.go index 45021ea51d9e0..dbf1bf5439c1a 100644 --- a/pkg/planner/util/debugtrace/base.go +++ b/pkg/planner/util/debugtrace/base.go @@ -19,7 +19,7 @@ import ( "encoding/json" "runtime" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" ) // OptimizerDebugTraceRoot is for recording the optimizer debug trace. @@ -94,7 +94,7 @@ func (root *OptimizerDebugTraceRoot) AppendStepWithNameToCurrentContext(step any // GetOrInitDebugTraceRoot returns the debug trace root. // If it's not initialized, it will initialize it first. -func GetOrInitDebugTraceRoot(sctx context.PlanContext) *OptimizerDebugTraceRoot { +func GetOrInitDebugTraceRoot(sctx planctx.PlanContext) *OptimizerDebugTraceRoot { stmtCtx := sctx.GetSessionVars().StmtCtx res, ok := stmtCtx.OptimizerDebugTrace.(*OptimizerDebugTraceRoot) if !ok || res == nil { @@ -123,7 +123,7 @@ func EncodeJSONCommon(input any) ([]byte, error) { // EnterContextCommon records the function name of the caller, // then creates and enter a new context for this debug trace structure. -func EnterContextCommon(sctx context.PlanContext) { +func EnterContextCommon(sctx planctx.PlanContext) { root := GetOrInitDebugTraceRoot(sctx) funcName := "Fail to get function name." pc, _, _, ok := runtime.Caller(1) @@ -139,7 +139,7 @@ func EnterContextCommon(sctx context.PlanContext) { } // LeaveContextCommon makes the debug trace goes to its parent context. -func LeaveContextCommon(sctx context.PlanContext) { +func LeaveContextCommon(sctx planctx.PlanContext) { root := GetOrInitDebugTraceRoot(sctx) root.currentCtx = root.currentCtx.parentCtx } @@ -148,7 +148,7 @@ func LeaveContextCommon(sctx context.PlanContext) { // The vals arguments should be a slice like ["name1", value1, "name2", value2]. // The names must be string, the values can be any type. func RecordAnyValuesWithNames( - s context.PlanContext, + s planctx.PlanContext, vals ...any, ) { root := GetOrInitDebugTraceRoot(s) diff --git a/pkg/planner/util/expression.go b/pkg/planner/util/expression.go index dce117ad396b4..0a3c5256772d8 100644 --- a/pkg/planner/util/expression.go +++ b/pkg/planner/util/expression.go @@ -17,7 +17,7 @@ package util import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/types" ) @@ -25,11 +25,11 @@ import ( // Different with expression.EvalSimpleAst, it uses planner context and is more powerful to build // some special expressions like subquery, window function, etc. // If you only want to evaluate simple expressions, use `expression.EvalSimpleAst` instead. -var EvalAstExprWithPlanCtx func(ctx context.PlanContext, expr ast.ExprNode) (types.Datum, error) +var EvalAstExprWithPlanCtx func(ctx planctx.PlanContext, expr ast.ExprNode) (types.Datum, error) // RewriteAstExprWithPlanCtx rewrites ast expression directly. // Different with expression.BuildSimpleExpr, it uses planner context and is more powerful to build // some special expressions like subquery, window function, etc. // If you only want to build simple expressions, use `expression.BuildSimpleExpr` instead. -var RewriteAstExprWithPlanCtx func(ctx context.PlanContext, expr ast.ExprNode, +var RewriteAstExprWithPlanCtx func(ctx planctx.PlanContext, expr ast.ExprNode, schema *expression.Schema, names types.NameSlice, allowCastArray bool) (expression.Expression, error) diff --git a/pkg/planner/util/null_misc.go b/pkg/planner/util/null_misc.go index 9aab80bcb3d7f..c1923d1377f95 100644 --- a/pkg/planner/util/null_misc.go +++ b/pkg/planner/util/null_misc.go @@ -18,8 +18,8 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/base" + "github.com/pingcap/tidb/pkg/planner/planctx" ) // allConstants checks if only the expression has only constants. @@ -99,7 +99,7 @@ func IsNullRejected(ctx base.PlanContext, innerSchema *expression.Schema, predic // A condition would be null-rejected in one of following cases: // If it is a predicate containing a reference to an inner table (null producing side) that evaluates // to UNKNOWN or FALSE when one of its arguments is NULL. -func isNullRejectedSimpleExpr(ctx context.PlanContext, schema *expression.Schema, expr expression.Expression) bool { +func isNullRejectedSimpleExpr(ctx planctx.PlanContext, schema *expression.Schema, expr expression.Expression) bool { // The expression should reference at least one field in innerSchema or all constants. if !expression.ExprReferenceSchema(expr, schema) && !allConstants(ctx.GetExprCtx(), expr) { return false diff --git a/pkg/planner/util/path.go b/pkg/planner/util/path.go index 2cfd107488885..ab3cd55ccc795 100644 --- a/pkg/planner/util/path.go +++ b/pkg/planner/util/path.go @@ -21,7 +21,7 @@ import ( "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/collate" "github.com/pingcap/tidb/pkg/util/ranger" @@ -145,7 +145,7 @@ func (path *AccessPath) IsTablePath() bool { // SplitCorColAccessCondFromFilters move the necessary filter in the form of index_col = corrlated_col to access conditions. // The function consider the `idx_col_1 = const and index_col_2 = cor_col and index_col_3 = const` case. // It enables more index columns to be considered. The range will be rebuilt in 'ResolveCorrelatedColumns'. -func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx context.PlanContext, eqOrInCount int) (access, remained []expression.Expression) { +func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext, eqOrInCount int) (access, remained []expression.Expression) { // The plan cache do not support subquery now. So we skip this function when // 'MaybeOverOptimized4PlanCache' function return true . if expression.MaybeOverOptimized4PlanCache(ctx.GetExprCtx(), path.TableFilters) { @@ -356,7 +356,7 @@ func CompareCol2Len(c1, c2 Col2Len) (int, bool) { } // GetCol2LenFromAccessConds returns columns with lengths from path.AccessConds. -func (path *AccessPath) GetCol2LenFromAccessConds(ctx context.PlanContext) Col2Len { +func (path *AccessPath) GetCol2LenFromAccessConds(ctx planctx.PlanContext) Col2Len { if path.IsTablePath() { return ExtractCol2Len(ctx.GetExprCtx().GetEvalCtx(), path.AccessConds, nil, nil) } diff --git a/pkg/session/BUILD.bazel b/pkg/session/BUILD.bazel index 1e3cec58a35a4..a2f289d32f47a 100644 --- a/pkg/session/BUILD.bazel +++ b/pkg/session/BUILD.bazel @@ -36,8 +36,8 @@ go_library( "//pkg/executor", "//pkg/executor/staticrecordset", "//pkg/expression", - "//pkg/expression/context", - "//pkg/expression/contextsession", + "//pkg/expression/exprctx", + "//pkg/expression/sessionexpr", "//pkg/extension", "//pkg/extension/extensionimpl", "//pkg/infoschema", @@ -58,11 +58,11 @@ go_library( "//pkg/parser/opcode", "//pkg/parser/terror", "//pkg/planner", - "//pkg/planner/context", - "//pkg/planner/contextimpl", "//pkg/planner/core", "//pkg/planner/core/base", "//pkg/planner/core/resolve", + "//pkg/planner/planctx", + "//pkg/planner/plannersession", "//pkg/plugin", "//pkg/privilege", "//pkg/privilege/conn", @@ -86,9 +86,9 @@ go_library( "//pkg/store/helper", "//pkg/store/mockstore", "//pkg/table", - "//pkg/table/context", - "//pkg/table/contextimpl", "//pkg/table/tables", + "//pkg/table/tblctx", + "//pkg/table/tblsession", "//pkg/table/temptable", "//pkg/tablecodec", "//pkg/testkit/testenv", @@ -159,7 +159,7 @@ go_test( "//pkg/domain", "//pkg/executor", "//pkg/expression", - "//pkg/expression/contextsession", + "//pkg/expression/sessionexpr", "//pkg/kv", "//pkg/meta", "//pkg/parser", @@ -170,7 +170,7 @@ go_test( "//pkg/sessionctx/variable", "//pkg/statistics", "//pkg/store/mockstore", - "//pkg/table/contextimpl", + "//pkg/table/tblsession", "//pkg/testkit/testmain", "//pkg/testkit/testsetup", "//pkg/types", diff --git a/pkg/session/bootstrap_test.go b/pkg/session/bootstrap_test.go index c0150461388e0..e456f701459c5 100644 --- a/pkg/session/bootstrap_test.go +++ b/pkg/session/bootstrap_test.go @@ -27,7 +27,7 @@ import ( "github.com/pingcap/tidb/pkg/bindinfo" "github.com/pingcap/tidb/pkg/ddl" "github.com/pingcap/tidb/pkg/domain" - "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" "github.com/pingcap/tidb/pkg/meta" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/auth" @@ -36,7 +36,7 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/statistics" "github.com/pingcap/tidb/pkg/store/mockstore" - tbctximpl "github.com/pingcap/tidb/pkg/table/contextimpl" + "github.com/pingcap/tidb/pkg/table/tblsession" "github.com/stretchr/testify/require" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -154,9 +154,9 @@ func TestBootstrapWithError(t *testing.T) { store: store, sessionVars: variable.NewSessionVars(nil), } - se.exprctx = contextsession.NewSessionExprContext(se) + se.exprctx = sessionexpr.NewExprContext(se) se.pctx = newPlanContextImpl(se) - se.tblctx = tbctximpl.NewTableContextImpl(se) + se.tblctx = tblsession.NewMutateContext(se) globalVarsAccessor := variable.NewMockGlobalAccessor4Tests() se.GetSessionVars().GlobalVarsAccessor = globalVarsAccessor se.txn.init() diff --git a/pkg/session/contextimpl.go b/pkg/session/contextimpl.go index 44bf8d7121432..9ddb247e23f80 100644 --- a/pkg/session/contextimpl.go +++ b/pkg/session/contextimpl.go @@ -15,8 +15,8 @@ package session import ( - planctx "github.com/pingcap/tidb/pkg/planner/context" - planctximpl "github.com/pingcap/tidb/pkg/planner/contextimpl" + "github.com/pingcap/tidb/pkg/planner/planctx" + "github.com/pingcap/tidb/pkg/planner/plannersession" ) var _ planctx.PlanContext = &planContextImpl{} @@ -26,13 +26,13 @@ var _ planctx.PlanContext = &planContextImpl{} // the `session` here to make it safe for casting. type planContextImpl struct { *session - *planctximpl.PlanCtxExtendedImpl + *plannersession.PlanCtxExtended } // NewPlanContextImpl creates a new PlanContextImpl. func newPlanContextImpl(s *session) *planContextImpl { return &planContextImpl{ - session: s, - PlanCtxExtendedImpl: planctximpl.NewPlanCtxExtendedImpl(s), + session: s, + PlanCtxExtended: plannersession.NewPlanCtxExtended(s), } } diff --git a/pkg/session/session.go b/pkg/session/session.go index 5c5ccf36c749a..71e78ca64f213 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -54,8 +54,8 @@ import ( "github.com/pingcap/tidb/pkg/executor" "github.com/pingcap/tidb/pkg/executor/staticrecordset" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" "github.com/pingcap/tidb/pkg/extension" "github.com/pingcap/tidb/pkg/extension/extensionimpl" "github.com/pingcap/tidb/pkg/infoschema" @@ -74,10 +74,10 @@ import ( "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" "github.com/pingcap/tidb/pkg/planner" - planctx "github.com/pingcap/tidb/pkg/planner/context" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/core/resolve" + planctx "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/plugin" "github.com/pingcap/tidb/pkg/privilege" "github.com/pingcap/tidb/pkg/privilege/conn" @@ -98,8 +98,8 @@ import ( storeerr "github.com/pingcap/tidb/pkg/store/driver/error" "github.com/pingcap/tidb/pkg/store/helper" "github.com/pingcap/tidb/pkg/table" - tbctx "github.com/pingcap/tidb/pkg/table/context" - tbctximpl "github.com/pingcap/tidb/pkg/table/contextimpl" + "github.com/pingcap/tidb/pkg/table/tblctx" + "github.com/pingcap/tidb/pkg/table/tblsession" "github.com/pingcap/tidb/pkg/table/temptable" "github.com/pingcap/tidb/pkg/tablecodec" "github.com/pingcap/tidb/pkg/ttl/ttlworker" @@ -188,8 +188,8 @@ type session struct { sessionManager util.SessionManager pctx *planContextImpl - exprctx *contextsession.SessionExprContext - tblctx *tbctximpl.TableContextImpl + exprctx *sessionexpr.ExprContext + tblctx *tblsession.MutateContext statsCollector *usage.SessionStatsItem // ddlOwnerManager is used in `select tidb_is_ddl_owner()` statement; @@ -2589,7 +2589,7 @@ func (s *session) GetExprCtx() exprctx.ExprContext { } // GetTableCtx returns the table.MutateContext -func (s *session) GetTableCtx() tbctx.MutateContext { +func (s *session) GetTableCtx() tblctx.MutateContext { return s.tblctx } @@ -3741,9 +3741,9 @@ func createSessionWithOpt(store kv.Storage, opt *Opt) (*session, error) { sessionStatesHandlers: make(map[sessionstates.SessionStateType]sessionctx.SessionStatesHandler), } s.sessionVars = variable.NewSessionVars(s) - s.exprctx = contextsession.NewSessionExprContext(s) + s.exprctx = sessionexpr.NewExprContext(s) s.pctx = newPlanContextImpl(s) - s.tblctx = tbctximpl.NewTableContextImpl(s) + s.tblctx = tblsession.NewMutateContext(s) if opt != nil && opt.PreparedPlanCache != nil { s.sessionPlanCache = opt.PreparedPlanCache @@ -3804,9 +3804,9 @@ func CreateSessionWithDomain(store kv.Storage, dom *domain.Domain) (*session, er stmtStats: stmtstats.CreateStatementStats(), sessionStatesHandlers: make(map[sessionstates.SessionStateType]sessionctx.SessionStatesHandler), } - s.exprctx = contextsession.NewSessionExprContext(s) + s.exprctx = sessionexpr.NewExprContext(s) s.pctx = newPlanContextImpl(s) - s.tblctx = tbctximpl.NewTableContextImpl(s) + s.tblctx = tblsession.NewMutateContext(s) s.mu.values = make(map[fmt.Stringer]any) s.lockedTables = make(map[int64]model.TableLockTpInfo) domain.BindDomain(s, dom) diff --git a/pkg/sessionctx/BUILD.bazel b/pkg/sessionctx/BUILD.bazel index 3a67400e4eb3a..eed0184a05285 100644 --- a/pkg/sessionctx/BUILD.bazel +++ b/pkg/sessionctx/BUILD.bazel @@ -7,20 +7,20 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/distsql/context", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/extension", "//pkg/infoschema/context", "//pkg/kv", "//pkg/lock/context", "//pkg/meta/model", "//pkg/metrics", - "//pkg/planner/context", + "//pkg/planner/planctx", "//pkg/session/cursor", "//pkg/sessionctx/sessionstates", "//pkg/sessionctx/stmtctx", "//pkg/sessionctx/variable", "//pkg/statistics/handle/usage/indexusage", - "//pkg/table/context", + "//pkg/table/tblctx", "//pkg/util", "//pkg/util/context", "//pkg/util/ranger/context", diff --git a/pkg/sessionctx/context.go b/pkg/sessionctx/context.go index 8a307dc5c9af6..db0a7ece9eb76 100644 --- a/pkg/sessionctx/context.go +++ b/pkg/sessionctx/context.go @@ -20,20 +20,20 @@ import ( "github.com/pingcap/errors" distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/extension" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" tablelock "github.com/pingcap/tidb/pkg/lock/context" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/metrics" - planctx "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/session/cursor" "github.com/pingcap/tidb/pkg/sessionctx/sessionstates" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/statistics/handle/usage/indexusage" - tbctx "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/util" contextutil "github.com/pingcap/tidb/pkg/util/context" rangerctx "github.com/pingcap/tidb/pkg/util/ranger/context" @@ -126,7 +126,7 @@ type Context interface { GetExprCtx() exprctx.ExprContext // GetTableCtx returns the table.MutateContext - GetTableCtx() tbctx.MutateContext + GetTableCtx() tblctx.MutateContext // GetPlanCtx gets the plan context of the current session. GetPlanCtx() planctx.PlanContext diff --git a/pkg/sessiontxn/staleread/BUILD.bazel b/pkg/sessiontxn/staleread/BUILD.bazel index 45c11e9e2e410..cea3cf4366c09 100644 --- a/pkg/sessiontxn/staleread/BUILD.bazel +++ b/pkg/sessiontxn/staleread/BUILD.bazel @@ -19,7 +19,7 @@ go_library( "//pkg/kv", "//pkg/parser/ast", "//pkg/parser/mysql", - "//pkg/planner/context", + "//pkg/planner/planctx", "//pkg/planner/util", "//pkg/sessionctx", "//pkg/sessionctx/stmtctx", diff --git a/pkg/sessiontxn/staleread/util.go b/pkg/sessiontxn/staleread/util.go index c66daedfa2ab5..a02a6110e9d81 100644 --- a/pkg/sessiontxn/staleread/util.go +++ b/pkg/sessiontxn/staleread/util.go @@ -22,7 +22,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/mysql" - pctx "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" plannerutil "github.com/pingcap/tidb/pkg/planner/util" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" @@ -33,7 +33,7 @@ import ( ) // CalculateAsOfTsExpr calculates the TsExpr of AsOfClause to get a StartTS. -func CalculateAsOfTsExpr(ctx context.Context, sctx pctx.PlanContext, tsExpr ast.ExprNode) (uint64, error) { +func CalculateAsOfTsExpr(ctx context.Context, sctx planctx.PlanContext, tsExpr ast.ExprNode) (uint64, error) { sctx.GetSessionVars().StmtCtx.SetStaleTSOProvider(func() (uint64, error) { failpoint.Inject("mockStaleReadTSO", func(val failpoint.Value) (uint64, error) { return uint64(val.(int)), nil diff --git a/pkg/statistics/BUILD.bazel b/pkg/statistics/BUILD.bazel index ddc59761edfe2..cad48db7936fe 100644 --- a/pkg/statistics/BUILD.bazel +++ b/pkg/statistics/BUILD.bazel @@ -30,8 +30,8 @@ go_library( "//pkg/parser/charset", "//pkg/parser/mysql", "//pkg/parser/terror", - "//pkg/planner/context", "//pkg/planner/core/resolve", + "//pkg/planner/planctx", "//pkg/planner/util/debugtrace", "//pkg/sessionctx", "//pkg/sessionctx/stmtctx", diff --git a/pkg/statistics/cmsketch.go b/pkg/statistics/cmsketch.go index 5c013189b55fe..f0c1ee11ceceb 100644 --- a/pkg/statistics/cmsketch.go +++ b/pkg/statistics/cmsketch.go @@ -28,7 +28,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" @@ -247,7 +247,7 @@ func (c *CMSketch) SubValue(h1, h2 uint64, count uint64) { } // QueryValue is used to query the count of specified value. -func QueryValue(sctx context.PlanContext, c *CMSketch, t *TopN, val types.Datum) (uint64, error) { +func QueryValue(sctx planctx.PlanContext, c *CMSketch, t *TopN, val types.Datum) (uint64, error) { var sc *stmtctx.StatementContext tz := time.UTC if sctx != nil { @@ -278,7 +278,7 @@ func (c *CMSketch) QueryBytes(d []byte) uint64 { } // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (c *CMSketch) queryHashValue(sctx context.PlanContext, h1, h2 uint64) (result uint64) { +func (c *CMSketch) queryHashValue(sctx planctx.PlanContext, h1, h2 uint64) (result uint64) { vals := make([]uint32, c.depth) originVals := make([]uint32, c.depth) minValue := uint32(math.MaxUint32) @@ -617,7 +617,7 @@ type TopNMeta struct { // QueryTopN returns the results for (h1, h2) in murmur3.Sum128(), if not exists, return (0, false). // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (c *TopN) QueryTopN(sctx context.PlanContext, d []byte) (result uint64, found bool) { +func (c *TopN) QueryTopN(sctx planctx.PlanContext, d []byte) (result uint64, found bool) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { @@ -681,7 +681,7 @@ func (c *TopN) LowerBound(d []byte) (idx int, match bool) { // BetweenCount estimates the row count for interval [l, r). // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (c *TopN) BetweenCount(sctx context.PlanContext, l, r []byte) (result uint64) { +func (c *TopN) BetweenCount(sctx planctx.PlanContext, l, r []byte) (result uint64) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { diff --git a/pkg/statistics/column.go b/pkg/statistics/column.go index 5cdc39238314f..6cd2d11a9a97a 100644 --- a/pkg/statistics/column.go +++ b/pkg/statistics/column.go @@ -17,7 +17,7 @@ package statistics import ( "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/statistics/asyncload" "github.com/pingcap/tidb/pkg/types" @@ -136,7 +136,7 @@ func (c *Column) MemoryUsage() CacheItemMemoryUsage { // ColumnStatsIsInvalid checks if this column is invalid. // If this column has histogram but not loaded yet, // then we mark it as need histogram. -func ColumnStatsIsInvalid(colStats *Column, sctx context.PlanContext, histColl *HistColl, cid int64) (res bool) { +func ColumnStatsIsInvalid(colStats *Column, sctx planctx.PlanContext, histColl *HistColl, cid int64) (res bool) { var totalCount float64 var ndv int64 var inValidForCollPseudo, essentialLoaded bool diff --git a/pkg/statistics/debugtrace.go b/pkg/statistics/debugtrace.go index a19f55a846c52..6bc93914ce28e 100644 --- a/pkg/statistics/debugtrace.go +++ b/pkg/statistics/debugtrace.go @@ -17,7 +17,7 @@ package statistics import ( "slices" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/types" ) @@ -190,7 +190,7 @@ type locateBucketInfo struct { } func debugTraceLocateBucket( - s context.PlanContext, + s planctx.PlanContext, value *types.Datum, exceed bool, bucketIdx int, @@ -219,7 +219,7 @@ type bucketInfo struct { } // DebugTraceBuckets is used to trace the buckets used in the histogram. -func DebugTraceBuckets(s context.PlanContext, hg *Histogram, bucketIdxs []int) { +func DebugTraceBuckets(s planctx.PlanContext, hg *Histogram, bucketIdxs []int) { root := debugtrace.GetOrInitDebugTraceRoot(s) buckets := make([]bucketInfo, len(bucketIdxs)) for i := range buckets { @@ -249,7 +249,7 @@ type topNRangeInfo struct { LastIdx int } -func debugTraceTopNRange(s context.PlanContext, t *TopN, startIdx, endIdx int) { +func debugTraceTopNRange(s planctx.PlanContext, t *TopN, startIdx, endIdx int) { if endIdx <= startIdx { return } diff --git a/pkg/statistics/histogram.go b/pkg/statistics/histogram.go index 2b3f3225af8d1..6a1f339903277 100644 --- a/pkg/statistics/histogram.go +++ b/pkg/statistics/histogram.go @@ -30,7 +30,7 @@ import ( "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" @@ -439,7 +439,7 @@ func (hg *Histogram) ToString(idxCols int) string { // EqualRowCount estimates the row count where the column equals to value. // matched: return true if this returned row count is from Bucket.Repeat or bucket NDV, which is more accurate than if not. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (hg *Histogram) EqualRowCount(sctx context.PlanContext, value types.Datum, hasBucketNDV bool) (count float64, matched bool) { +func (hg *Histogram) EqualRowCount(sctx planctx.PlanContext, value types.Datum, hasBucketNDV bool) (count float64, matched bool) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { @@ -489,7 +489,7 @@ func (hg *Histogram) GreaterRowCount(value types.Datum) float64 { // locateBucket(val2): false, 2, false, false // locateBucket(val3): false, 2, true, false // locateBucket(val4): true, 3, false, false -func (hg *Histogram) LocateBucket(sctx context.PlanContext, value types.Datum) (exceed bool, bucketIdx int, inBucket, matchLastValue bool) { +func (hg *Histogram) LocateBucket(sctx planctx.PlanContext, value types.Datum) (exceed bool, bucketIdx int, inBucket, matchLastValue bool) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { defer func() { debugTraceLocateBucket(sctx, &value, exceed, bucketIdx, inBucket, matchLastValue) @@ -522,7 +522,7 @@ func (hg *Histogram) LocateBucket(sctx context.PlanContext, value types.Datum) ( // LessRowCountWithBktIdx estimates the row count where the column less than value. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (hg *Histogram) LessRowCountWithBktIdx(sctx context.PlanContext, value types.Datum) (result float64, bucketIdx int) { +func (hg *Histogram) LessRowCountWithBktIdx(sctx planctx.PlanContext, value types.Datum) (result float64, bucketIdx int) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { @@ -557,14 +557,14 @@ func (hg *Histogram) LessRowCountWithBktIdx(sctx context.PlanContext, value type // LessRowCount estimates the row count where the column less than value. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (hg *Histogram) LessRowCount(sctx context.PlanContext, value types.Datum) float64 { +func (hg *Histogram) LessRowCount(sctx planctx.PlanContext, value types.Datum) float64 { result, _ := hg.LessRowCountWithBktIdx(sctx, value) return result } // BetweenRowCount estimates the row count where column greater or equal to a and less than b. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (hg *Histogram) BetweenRowCount(sctx context.PlanContext, a, b types.Datum) float64 { +func (hg *Histogram) BetweenRowCount(sctx planctx.PlanContext, a, b types.Datum) float64 { lessCountA := hg.LessRowCount(sctx, a) lessCountB := hg.LessRowCount(sctx, b) rangeEst := lessCountB - lessCountA @@ -912,7 +912,7 @@ func (hg *Histogram) OutOfRange(val types.Datum) bool { // leftPercent = (math.Pow(actualR-boundL, 2) - math.Pow(actualL-boundL, 2)) / math.Pow(histWidth, 2) // You can find more details at https://github.com/pingcap/tidb/pull/47966#issuecomment-1778866876 func (hg *Histogram) OutOfRangeRowCount( - sctx context.PlanContext, + sctx planctx.PlanContext, lDatum, rDatum *types.Datum, modifyCount, histNDV int64, increaseFactor float64, ) (result float64) { diff --git a/pkg/statistics/index.go b/pkg/statistics/index.go index c961613241b3e..53686852f0eb8 100644 --- a/pkg/statistics/index.go +++ b/pkg/statistics/index.go @@ -17,7 +17,7 @@ package statistics import ( "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/planner/util/debugtrace" "github.com/pingcap/tidb/pkg/statistics/asyncload" "github.com/pingcap/tidb/pkg/types" @@ -129,7 +129,7 @@ func (idx *Index) TotalRowCount() float64 { } // IndexStatsIsInvalid checks whether the index has valid stats or not. -func IndexStatsIsInvalid(sctx context.PlanContext, idxStats *Index, coll *HistColl, cid int64) (res bool) { +func IndexStatsIsInvalid(sctx planctx.PlanContext, idxStats *Index, coll *HistColl, cid int64) (res bool) { var totalCount float64 if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) @@ -195,7 +195,7 @@ func (idx *Index) MemoryUsage() CacheItemMemoryUsage { // QueryBytes is used to query the count of specified bytes. // The input sctx is just for debug trace, you can pass nil safely if that's not needed. -func (idx *Index) QueryBytes(sctx context.PlanContext, d []byte) (result uint64) { +func (idx *Index) QueryBytes(sctx planctx.PlanContext, d []byte) (result uint64) { if sctx != nil && sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) defer func() { diff --git a/pkg/statistics/table.go b/pkg/statistics/table.go index c59cddca90473..bee7a9b1c26dc 100644 --- a/pkg/statistics/table.go +++ b/pkg/statistics/table.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/ranger" "go.uber.org/atomic" @@ -51,13 +51,13 @@ var ( // Note: all functions below will be removed after finishing moving all estimation functions into the cardinality package. // GetRowCountByIndexRanges is a function type to get row count by index ranges. - GetRowCountByIndexRanges func(sctx context.PlanContext, coll *HistColl, idxID int64, indexRanges []*ranger.Range) (result float64, err error) + GetRowCountByIndexRanges func(sctx planctx.PlanContext, coll *HistColl, idxID int64, indexRanges []*ranger.Range) (result float64, err error) // GetRowCountByIntColumnRanges is a function type to get row count by int column ranges. - GetRowCountByIntColumnRanges func(sctx context.PlanContext, coll *HistColl, colID int64, intRanges []*ranger.Range) (result float64, err error) + GetRowCountByIntColumnRanges func(sctx planctx.PlanContext, coll *HistColl, colID int64, intRanges []*ranger.Range) (result float64, err error) // GetRowCountByColumnRanges is a function type to get row count by column ranges. - GetRowCountByColumnRanges func(sctx context.PlanContext, coll *HistColl, colID int64, colRanges []*ranger.Range) (result float64, err error) + GetRowCountByColumnRanges func(sctx planctx.PlanContext, coll *HistColl, colID int64, colRanges []*ranger.Range) (result float64, err error) ) // Table represents statistics for a table. diff --git a/pkg/table/BUILD.bazel b/pkg/table/BUILD.bazel index d730e6c966292..512733b85498d 100644 --- a/pkg/table/BUILD.bazel +++ b/pkg/table/BUILD.bazel @@ -14,7 +14,7 @@ go_library( "//pkg/errctx", "//pkg/errno", "//pkg/expression", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/kv", "//pkg/meta/autoid", "//pkg/meta/model", @@ -27,7 +27,7 @@ go_library( "//pkg/sessionctx", "//pkg/sessionctx/stmtctx", "//pkg/sessionctx/variable", - "//pkg/table/context", + "//pkg/table/tblctx", "//pkg/types", "//pkg/util/chunk", "//pkg/util/dbterror", diff --git a/pkg/table/column.go b/pkg/table/column.go index cba250b1480e4..cde8588ea524f 100644 --- a/pkg/table/column.go +++ b/pkg/table/column.go @@ -27,7 +27,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/ast" diff --git a/pkg/table/table.go b/pkg/table/table.go index d48fb475964be..f530847fdba3c 100644 --- a/pkg/table/table.go +++ b/pkg/table/table.go @@ -24,14 +24,14 @@ import ( mysql "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/autoid" "github.com/pingcap/tidb/pkg/meta/model" pmodel "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" - tbctx "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/dbterror" @@ -396,10 +396,10 @@ type columnAPI interface { } // MutateContext is used to when mutating a table. -type MutateContext = tbctx.MutateContext +type MutateContext = tblctx.MutateContext // AllocatorContext is used to provide context for method `table.Allocators`. -type AllocatorContext = tbctx.AllocatorContext +type AllocatorContext = tblctx.AllocatorContext // Table is used to retrieve and modify rows in table. type Table interface { diff --git a/pkg/table/tables/BUILD.bazel b/pkg/table/tables/BUILD.bazel index d9c7aeff2be4e..7e5a55be92b59 100644 --- a/pkg/table/tables/BUILD.bazel +++ b/pkg/table/tables/BUILD.bazel @@ -17,8 +17,8 @@ go_library( "//pkg/errctx", "//pkg/errno", "//pkg/expression", - "//pkg/expression/context", - "//pkg/expression/contextstatic", + "//pkg/expression/exprctx", + "//pkg/expression/exprstatic", "//pkg/kv", "//pkg/meta", "//pkg/meta/autoid", @@ -34,7 +34,7 @@ go_library( "//pkg/sessionctx/variable", "//pkg/statistics", "//pkg/table", - "//pkg/table/context", + "//pkg/table/tblctx", "//pkg/tablecodec", "//pkg/types", "//pkg/util", diff --git a/pkg/table/tables/partition.go b/pkg/table/tables/partition.go index 1d3e148ae6625..e09dee8b3541d 100644 --- a/pkg/table/tables/partition.go +++ b/pkg/table/tables/partition.go @@ -29,7 +29,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" @@ -241,19 +241,19 @@ func initPartition(t *partitionedTable, def model.PartitionDefinition) (*partiti // NewPartitionExprBuildCtx returns a context to build partition expression. func NewPartitionExprBuildCtx() expression.BuildContext { - return contextstatic.NewStaticExprContext( - contextstatic.WithEvalCtx(contextstatic.NewStaticEvalContext( + return exprstatic.NewExprContext( + exprstatic.WithEvalCtx(exprstatic.NewEvalContext( // Set a non-strict SQL mode and allow all date values if possible to make sure constant fold can work to // estimate some undetermined result when locating a row to a partition. // See issue: https://github.com/pingcap/tidb/issues/54271 for details. - contextstatic.WithSQLMode(mysql.ModeAllowInvalidDates), - contextstatic.WithTypeFlags(types.StrictFlags. + exprstatic.WithSQLMode(mysql.ModeAllowInvalidDates), + exprstatic.WithTypeFlags(types.StrictFlags. WithIgnoreTruncateErr(true). WithIgnoreZeroDateErr(true). WithIgnoreZeroInDate(true). WithIgnoreInvalidDateErr(true), ), - contextstatic.WithErrLevelMap(errctx.LevelMap{ + exprstatic.WithErrLevelMap(errctx.LevelMap{ errctx.ErrGroupTruncate: errctx.LevelIgnore, }), )), diff --git a/pkg/table/tables/tables.go b/pkg/table/tables/tables.go index dfcb12dd33b97..9ebea00596da8 100644 --- a/pkg/table/tables/tables.go +++ b/pkg/table/tables/tables.go @@ -30,7 +30,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta" "github.com/pingcap/tidb/pkg/meta/autoid" @@ -42,7 +42,7 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/statistics" "github.com/pingcap/tidb/pkg/table" - tbctx "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/tablecodec" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util" @@ -710,21 +710,21 @@ func TryGetCommonPkColumns(tbl table.Table) []*table.Column { return pkCols } -func addTemporaryTable(sctx table.MutateContext, tblInfo *model.TableInfo) (tbctx.TemporaryTableHandler, int64, bool) { +func addTemporaryTable(sctx table.MutateContext, tblInfo *model.TableInfo) (tblctx.TemporaryTableHandler, int64, bool) { if s, ok := sctx.GetTemporaryTableSupport(); ok { if h, ok := s.AddTemporaryTableToTxn(tblInfo); ok { return h, s.GetTemporaryTableSizeLimit(), ok } } - return tbctx.TemporaryTableHandler{}, 0, false + return tblctx.TemporaryTableHandler{}, 0, false } // The size of a temporary table is calculated by accumulating the transaction size delta. -func handleTempTableSize(t tbctx.TemporaryTableHandler, txnSizeBefore int, txn kv.Transaction) { +func handleTempTableSize(t tblctx.TemporaryTableHandler, txnSizeBefore int, txn kv.Transaction) { t.UpdateTxnDeltaSize(txn.Size() - txnSizeBefore) } -func checkTempTableSize(tmpTable tbctx.TemporaryTableHandler, sizeLimit int64) error { +func checkTempTableSize(tmpTable tblctx.TemporaryTableHandler, sizeLimit int64) error { if tmpTable.GetCommittedSize()+tmpTable.GetDirtySize() > sizeLimit { return table.ErrTempTableFull.GenWithStackByArgs(tmpTable.Meta().Name.O) } @@ -1268,7 +1268,7 @@ func (t *TableCommon) removeRecord(ctx table.MutateContext, txn kv.Transaction, return err } -func (t *TableCommon) addInsertBinlog(ctx table.MutateContext, support tbctx.BinlogSupport, h kv.Handle, encodeRowBuffer *tbctx.EncodeRowBuffer) error { +func (t *TableCommon) addInsertBinlog(ctx table.MutateContext, support tblctx.BinlogSupport, h kv.Handle, encodeRowBuffer *tblctx.EncodeRowBuffer) error { evalCtx := ctx.GetExprCtx().GetEvalCtx() loc, ec := evalCtx.Location(), evalCtx.ErrCtx() handleData, err := h.Data() @@ -1291,7 +1291,7 @@ func (t *TableCommon) addInsertBinlog(ctx table.MutateContext, support tbctx.Bin return nil } -func (t *TableCommon) addUpdateBinlog(ctx table.MutateContext, support tbctx.BinlogSupport, oldRow, newRow []types.Datum, colIDs []int64) error { +func (t *TableCommon) addUpdateBinlog(ctx table.MutateContext, support tblctx.BinlogSupport, oldRow, newRow []types.Datum, colIDs []int64) error { evalCtx := ctx.GetExprCtx().GetEvalCtx() loc, ec := evalCtx.Location(), evalCtx.ErrCtx() old, err := tablecodec.EncodeOldRow(loc, oldRow, colIDs, nil, nil) @@ -1311,7 +1311,7 @@ func (t *TableCommon) addUpdateBinlog(ctx table.MutateContext, support tbctx.Bin return nil } -func (t *TableCommon) addDeleteBinlog(ctx table.MutateContext, support tbctx.BinlogSupport, r []types.Datum, colIDs []int64) error { +func (t *TableCommon) addDeleteBinlog(ctx table.MutateContext, support tblctx.BinlogSupport, r []types.Datum, colIDs []int64) error { evalCtx := ctx.GetExprCtx().GetEvalCtx() loc, ec := evalCtx.Location(), evalCtx.ErrCtx() data, err := tablecodec.EncodeOldRow(loc, r, colIDs, nil, nil) @@ -1611,7 +1611,7 @@ func (t *TableCommon) Type() table.Type { return table.NormalTable } -func getBinlogSupport(ctx table.MutateContext, tblInfo *model.TableInfo) (tbctx.BinlogSupport, bool) { +func getBinlogSupport(ctx table.MutateContext, tblInfo *model.TableInfo) (tblctx.BinlogSupport, bool) { if tblInfo.TempTableType != model.TempTableNone || ctx.InRestrictedSQL() { return nil, false } diff --git a/pkg/table/context/BUILD.bazel b/pkg/table/tblctx/BUILD.bazel similarity index 85% rename from pkg/table/context/BUILD.bazel rename to pkg/table/tblctx/BUILD.bazel index 5eb49d4315d0d..b4f74e4ab80ec 100644 --- a/pkg/table/context/BUILD.bazel +++ b/pkg/table/tblctx/BUILD.bazel @@ -1,16 +1,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "context", + name = "tblctx", srcs = [ "buffers.go", "table.go", ], - importpath = "github.com/pingcap/tidb/pkg/table/context", + importpath = "github.com/pingcap/tidb/pkg/table/tblctx", visibility = ["//visibility:public"], deps = [ "//pkg/errctx", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema/context", "//pkg/kv", "//pkg/meta/autoid", @@ -28,10 +28,10 @@ go_library( ) go_test( - name = "context_test", + name = "tblctx_test", timeout = "short", srcs = ["buffers_test.go"], - embed = [":context"], + embed = [":tblctx"], flaky = True, shard_count = 6, deps = [ diff --git a/pkg/table/context/buffers.go b/pkg/table/tblctx/buffers.go similarity index 99% rename from pkg/table/context/buffers.go rename to pkg/table/tblctx/buffers.go index cc42e4bbcbec4..3cf537f2fc390 100644 --- a/pkg/table/context/buffers.go +++ b/pkg/table/tblctx/buffers.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package tblctx import ( "time" diff --git a/pkg/table/context/buffers_test.go b/pkg/table/tblctx/buffers_test.go similarity index 99% rename from pkg/table/context/buffers_test.go rename to pkg/table/tblctx/buffers_test.go index d6d20d3c9e514..802f0f1bac19d 100644 --- a/pkg/table/context/buffers_test.go +++ b/pkg/table/tblctx/buffers_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package tblctx import ( "testing" diff --git a/pkg/table/context/table.go b/pkg/table/tblctx/table.go similarity index 98% rename from pkg/table/context/table.go rename to pkg/table/tblctx/table.go index 63ed251a0959a..eca2222eca347 100644 --- a/pkg/table/context/table.go +++ b/pkg/table/tblctx/table.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package context +package tblctx import ( - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/meta/autoid" "github.com/pingcap/tidb/pkg/meta/model" diff --git a/pkg/table/contextimpl/BUILD.bazel b/pkg/table/tblsession/BUILD.bazel similarity index 80% rename from pkg/table/contextimpl/BUILD.bazel rename to pkg/table/tblsession/BUILD.bazel index da643f143cddc..9aff2c43006c8 100644 --- a/pkg/table/contextimpl/BUILD.bazel +++ b/pkg/table/tblsession/BUILD.bazel @@ -1,19 +1,19 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "contextimpl", + name = "tblsession", srcs = ["table.go"], - importpath = "github.com/pingcap/tidb/pkg/table/contextimpl", + importpath = "github.com/pingcap/tidb/pkg/table/tblsession", visibility = ["//visibility:public"], deps = [ - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/infoschema/context", "//pkg/meta/autoid", "//pkg/meta/model", "//pkg/sessionctx", "//pkg/sessionctx/stmtctx", "//pkg/sessionctx/variable", - "//pkg/table/context", + "//pkg/table/tblctx", "//pkg/util/intest", "@com_github_pingcap_failpoint//:failpoint", "@com_github_pingcap_tipb//go-binlog", @@ -21,12 +21,12 @@ go_library( ) go_test( - name = "contextimpl_test", + name = "tblsession_test", timeout = "short", srcs = ["table_test.go"], flaky = True, deps = [ - ":contextimpl", + ":tblsession", "//pkg/meta/model", "//pkg/sessionctx/binloginfo", "//pkg/sessionctx/variable", diff --git a/pkg/table/contextimpl/table.go b/pkg/table/tblsession/table.go similarity index 66% rename from pkg/table/contextimpl/table.go rename to pkg/table/tblsession/table.go index a13c25f61df27..91110da76701d 100644 --- a/pkg/table/contextimpl/table.go +++ b/pkg/table/tblsession/table.go @@ -12,44 +12,44 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextimpl +package tblsession import ( "github.com/pingcap/failpoint" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/meta/autoid" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/sessionctx/variable" - "github.com/pingcap/tidb/pkg/table/context" + "github.com/pingcap/tidb/pkg/table/tblctx" "github.com/pingcap/tidb/pkg/util/intest" "github.com/pingcap/tipb/go-binlog" ) -var _ context.MutateContext = &TableContextImpl{} -var _ context.AllocatorContext = &TableContextImpl{} +var _ tblctx.MutateContext = &MutateContext{} +var _ tblctx.AllocatorContext = &MutateContext{} -// TableContextImpl is used to provide context for table operations. -type TableContextImpl struct { +// MutateContext is used to provide context for table operations. +type MutateContext struct { sessionctx.Context // mutateBuffers is a memory pool for table related memory allocation that aims to reuse memory // and saves allocation // The buffers are supposed to be used inside AddRecord/UpdateRecord/RemoveRecord. - mutateBuffers *context.MutateBuffers + mutateBuffers *tblctx.MutateBuffers } -// NewTableContextImpl creates a new TableContextImpl. -func NewTableContextImpl(sctx sessionctx.Context) *TableContextImpl { - return &TableContextImpl{ +// NewMutateContext creates a new MutateContext. +func NewMutateContext(sctx sessionctx.Context) *MutateContext { + return &MutateContext{ Context: sctx, - mutateBuffers: context.NewMutateBuffers(sctx.GetSessionVars().GetWriteStmtBufs()), + mutateBuffers: tblctx.NewMutateBuffers(sctx.GetSessionVars().GetWriteStmtBufs()), } } // AlternativeAllocators implements the AllocatorContext interface -func (ctx *TableContextImpl) AlternativeAllocators(tbl *model.TableInfo) (allocators autoid.Allocators, ok bool) { +func (ctx *MutateContext) AlternativeAllocators(tbl *model.TableInfo) (allocators autoid.Allocators, ok bool) { // Use an independent allocator for global temporary tables. if tbl.TempTableType == model.TempTableGlobal { if tempTbl := ctx.vars().GetTemporaryTable(tbl); tempTbl != nil { @@ -63,51 +63,51 @@ func (ctx *TableContextImpl) AlternativeAllocators(tbl *model.TableInfo) (alloca } // GetExprCtx returns the ExprContext -func (ctx *TableContextImpl) GetExprCtx() exprctx.ExprContext { +func (ctx *MutateContext) GetExprCtx() exprctx.ExprContext { return ctx.Context.GetExprCtx() } // ConnectionID implements the MutateContext interface. -func (ctx *TableContextImpl) ConnectionID() uint64 { +func (ctx *MutateContext) ConnectionID() uint64 { return ctx.vars().ConnectionID } // InRestrictedSQL returns whether the current context is used in restricted SQL. -func (ctx *TableContextImpl) InRestrictedSQL() bool { +func (ctx *MutateContext) InRestrictedSQL() bool { return ctx.vars().InRestrictedSQL } // TxnAssertionLevel implements the MutateContext interface. -func (ctx *TableContextImpl) TxnAssertionLevel() variable.AssertionLevel { +func (ctx *MutateContext) TxnAssertionLevel() variable.AssertionLevel { return ctx.vars().AssertionLevel } // EnableMutationChecker implements the MutateContext interface. -func (ctx *TableContextImpl) EnableMutationChecker() bool { +func (ctx *MutateContext) EnableMutationChecker() bool { return ctx.vars().EnableMutationChecker } // GetRowEncodingConfig returns the RowEncodingConfig. -func (ctx *TableContextImpl) GetRowEncodingConfig() context.RowEncodingConfig { +func (ctx *MutateContext) GetRowEncodingConfig() tblctx.RowEncodingConfig { vars := ctx.vars() - return context.RowEncodingConfig{ + return tblctx.RowEncodingConfig{ IsRowLevelChecksumEnabled: vars.IsRowLevelChecksumEnabled(), RowEncoder: &vars.RowEncoder, } } // GetMutateBuffers implements the MutateContext interface. -func (ctx *TableContextImpl) GetMutateBuffers() *context.MutateBuffers { +func (ctx *MutateContext) GetMutateBuffers() *tblctx.MutateBuffers { return ctx.mutateBuffers } // GetRowIDShardGenerator implements the MutateContext interface. -func (ctx *TableContextImpl) GetRowIDShardGenerator() *variable.RowIDShardGenerator { +func (ctx *MutateContext) GetRowIDShardGenerator() *variable.RowIDShardGenerator { return ctx.vars().GetRowIDShardGenerator() } // GetReservedRowIDAlloc implements the MutateContext interface. -func (ctx *TableContextImpl) GetReservedRowIDAlloc() (*stmtctx.ReservedRowIDAlloc, bool) { +func (ctx *MutateContext) GetReservedRowIDAlloc() (*stmtctx.ReservedRowIDAlloc, bool) { if sc := ctx.vars().StmtCtx; sc != nil { return &sc.ReservedRowIDAlloc, true } @@ -120,7 +120,7 @@ func (ctx *TableContextImpl) GetReservedRowIDAlloc() (*stmtctx.ReservedRowIDAllo } // GetBinlogSupport implements the MutateContext interface. -func (ctx *TableContextImpl) GetBinlogSupport() (context.BinlogSupport, bool) { +func (ctx *MutateContext) GetBinlogSupport() (tblctx.BinlogSupport, bool) { failpoint.Inject("forceWriteBinlog", func() { // Just to cover binlog related code in this package, since the `BinlogClient` is // still nil, mutations won't be written to pump on commit. @@ -133,12 +133,12 @@ func (ctx *TableContextImpl) GetBinlogSupport() (context.BinlogSupport, bool) { } // GetBinlogMutation implements the BinlogSupport interface. -func (ctx *TableContextImpl) GetBinlogMutation(tblID int64) *binlog.TableMutation { +func (ctx *MutateContext) GetBinlogMutation(tblID int64) *binlog.TableMutation { return ctx.Context.StmtGetMutation(tblID) } // GetStatisticsSupport implements the MutateContext interface. -func (ctx *TableContextImpl) GetStatisticsSupport() (context.StatisticsSupport, bool) { +func (ctx *MutateContext) GetStatisticsSupport() (tblctx.StatisticsSupport, bool) { if ctx.vars().TxnCtx != nil { return ctx, true } @@ -146,7 +146,7 @@ func (ctx *TableContextImpl) GetStatisticsSupport() (context.StatisticsSupport, } // UpdatePhysicalTableDelta implements the StatisticsSupport interface. -func (ctx *TableContextImpl) UpdatePhysicalTableDelta( +func (ctx *MutateContext) UpdatePhysicalTableDelta( physicalTableID int64, delta int64, count int64, cols variable.DeltaCols, ) { if txnCtx := ctx.vars().TxnCtx; txnCtx != nil { @@ -155,7 +155,7 @@ func (ctx *TableContextImpl) UpdatePhysicalTableDelta( } // GetCachedTableSupport implements the MutateContext interface. -func (ctx *TableContextImpl) GetCachedTableSupport() (context.CachedTableSupport, bool) { +func (ctx *MutateContext) GetCachedTableSupport() (tblctx.CachedTableSupport, bool) { if ctx.vars().TxnCtx != nil { return ctx, true } @@ -163,7 +163,7 @@ func (ctx *TableContextImpl) GetCachedTableSupport() (context.CachedTableSupport } // AddCachedTableHandleToTxn implements `CachedTableSupport` interface -func (ctx *TableContextImpl) AddCachedTableHandleToTxn(tableID int64, handle any) { +func (ctx *MutateContext) AddCachedTableHandleToTxn(tableID int64, handle any) { txnCtx := ctx.vars().TxnCtx if txnCtx.CachedTables == nil { txnCtx.CachedTables = make(map[int64]any) @@ -174,7 +174,7 @@ func (ctx *TableContextImpl) AddCachedTableHandleToTxn(tableID int64, handle any } // GetTemporaryTableSupport implements the MutateContext interface. -func (ctx *TableContextImpl) GetTemporaryTableSupport() (context.TemporaryTableSupport, bool) { +func (ctx *MutateContext) GetTemporaryTableSupport() (tblctx.TemporaryTableSupport, bool) { if ctx.vars().TxnCtx == nil { return nil, false } @@ -182,30 +182,30 @@ func (ctx *TableContextImpl) GetTemporaryTableSupport() (context.TemporaryTableS } // GetInfoSchemaToCheckExchangeConstraint implements the ExchangePartitionDMLSupport interface. -func (ctx *TableContextImpl) GetInfoSchemaToCheckExchangeConstraint() infoschema.MetaOnlyInfoSchema { +func (ctx *MutateContext) GetInfoSchemaToCheckExchangeConstraint() infoschema.MetaOnlyInfoSchema { return ctx.Context.GetDomainInfoSchema() } // GetExchangePartitionDMLSupport implements the MutateContext interface. -func (ctx *TableContextImpl) GetExchangePartitionDMLSupport() (context.ExchangePartitionDMLSupport, bool) { +func (ctx *MutateContext) GetExchangePartitionDMLSupport() (tblctx.ExchangePartitionDMLSupport, bool) { return ctx, true } // GetTemporaryTableSizeLimit implements TemporaryTableSupport interface. -func (ctx *TableContextImpl) GetTemporaryTableSizeLimit() int64 { +func (ctx *MutateContext) GetTemporaryTableSizeLimit() int64 { return ctx.vars().TMPTableSize } // AddTemporaryTableToTxn implements the TemporaryTableSupport interface. -func (ctx *TableContextImpl) AddTemporaryTableToTxn(tblInfo *model.TableInfo) (context.TemporaryTableHandler, bool) { +func (ctx *MutateContext) AddTemporaryTableToTxn(tblInfo *model.TableInfo) (tblctx.TemporaryTableHandler, bool) { vars := ctx.vars() if tbl := vars.GetTemporaryTable(tblInfo); tbl != nil { tbl.SetModified(true) - return context.NewTemporaryTableHandler(tbl, vars.TemporaryTableData), true + return tblctx.NewTemporaryTableHandler(tbl, vars.TemporaryTableData), true } - return context.TemporaryTableHandler{}, false + return tblctx.TemporaryTableHandler{}, false } -func (ctx *TableContextImpl) vars() *variable.SessionVars { +func (ctx *MutateContext) vars() *variable.SessionVars { return ctx.Context.GetSessionVars() } diff --git a/pkg/table/contextimpl/table_test.go b/pkg/table/tblsession/table_test.go similarity index 97% rename from pkg/table/contextimpl/table_test.go rename to pkg/table/tblsession/table_test.go index d3bef9b4ecc9e..9b691fb1f4000 100644 --- a/pkg/table/contextimpl/table_test.go +++ b/pkg/table/tblsession/table_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contextimpl_test +package tblsession_test import ( "testing" @@ -21,7 +21,7 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/binloginfo" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/table" - "github.com/pingcap/tidb/pkg/table/contextimpl" + "github.com/pingcap/tidb/pkg/table/tblsession" "github.com/pingcap/tidb/pkg/testkit" "github.com/pingcap/tidb/pkg/util/mock" "github.com/pingcap/tipb/go-binlog" @@ -37,10 +37,10 @@ func (m *mockTemporaryData) GetTableSize(tableID int64) int64 { return tableID*1000000 + m.size } -func TestMutateContextImplFields(t *testing.T) { +func TestSessionMutateContextFields(t *testing.T) { sctx := mock.NewContext() sctx.Mutations = make(map[int64]*binlog.TableMutation) - ctx := contextimpl.NewTableContextImpl(sctx) + ctx := tblsession.NewMutateContext(sctx) // expression require.True(t, sctx.GetExprCtx() == ctx.GetExprCtx()) // binlog diff --git a/pkg/ttl/cache/BUILD.bazel b/pkg/ttl/cache/BUILD.bazel index f8f82617d89be..70a7b514aae22 100644 --- a/pkg/ttl/cache/BUILD.bazel +++ b/pkg/ttl/cache/BUILD.bazel @@ -13,7 +13,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/expression", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/infoschema", "//pkg/kv", "//pkg/meta/model", diff --git a/pkg/ttl/cache/table.go b/pkg/ttl/cache/table.go index 2b97f6c8ef49d..48c1c7b63d560 100644 --- a/pkg/ttl/cache/table.go +++ b/pkg/ttl/cache/table.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser/ast" @@ -209,7 +209,7 @@ func EvalExpireTime(now time.Time, interval string, unit ast.TimeUnitType) (time now.Nanosecond(), time.UTC, ) - exprCtx := contextstatic.NewStaticExprContext() + exprCtx := exprstatic.NewExprContext() // we need to set the location to UTC to make sure the time is in the same timezone as the start time. intest.Assert(exprCtx.GetEvalCtx().Location() == time.UTC) expr, err := expression.ParseSimpleExpr( diff --git a/pkg/util/mock/BUILD.bazel b/pkg/util/mock/BUILD.bazel index 3c14502716741..98d3bde2dc473 100644 --- a/pkg/util/mock/BUILD.bazel +++ b/pkg/util/mock/BUILD.bazel @@ -13,8 +13,8 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/distsql/context", - "//pkg/expression/context", - "//pkg/expression/contextsession", + "//pkg/expression/exprctx", + "//pkg/expression/sessionexpr", "//pkg/extension", "//pkg/infoschema/context", "//pkg/kv", @@ -22,15 +22,15 @@ go_library( "//pkg/parser/ast", "//pkg/parser/model", "//pkg/parser/terror", - "//pkg/planner/context", "//pkg/planner/core/resolve", + "//pkg/planner/planctx", "//pkg/session/cursor", "//pkg/sessionctx", "//pkg/sessionctx/sessionstates", "//pkg/sessionctx/variable", "//pkg/statistics/handle/usage/indexusage", - "//pkg/table/context", - "//pkg/table/contextimpl", + "//pkg/table/tblctx", + "//pkg/table/tblsession", "//pkg/util", "//pkg/util/chunk", "//pkg/util/disk", diff --git a/pkg/util/mock/context.go b/pkg/util/mock/context.go index 587d492c99eeb..e0457d20fcb3a 100644 --- a/pkg/util/mock/context.go +++ b/pkg/util/mock/context.go @@ -23,8 +23,8 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" distsqlctx "github.com/pingcap/tidb/pkg/distsql/context" - exprctx "github.com/pingcap/tidb/pkg/expression/context" - exprctximpl "github.com/pingcap/tidb/pkg/expression/contextsession" + "github.com/pingcap/tidb/pkg/expression/exprctx" + "github.com/pingcap/tidb/pkg/expression/sessionexpr" "github.com/pingcap/tidb/pkg/extension" infoschema "github.com/pingcap/tidb/pkg/infoschema/context" "github.com/pingcap/tidb/pkg/kv" @@ -32,15 +32,15 @@ import ( "github.com/pingcap/tidb/pkg/parser/ast" pmodel "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/terror" - planctx "github.com/pingcap/tidb/pkg/planner/context" "github.com/pingcap/tidb/pkg/planner/core/resolve" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/session/cursor" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/sessionctx/sessionstates" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/statistics/handle/usage/indexusage" - tbctx "github.com/pingcap/tidb/pkg/table/context" - tbctximpl "github.com/pingcap/tidb/pkg/table/contextimpl" + "github.com/pingcap/tidb/pkg/table/tblctx" + "github.com/pingcap/tidb/pkg/table/tblsession" "github.com/pingcap/tidb/pkg/util" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/disk" @@ -63,7 +63,7 @@ var ( // Context represents mocked sessionctx.Context. type Context struct { planctx.EmptyPlanContextExtended - *exprctximpl.SessionExprContext + *sessionexpr.ExprContext txn wrapTxn // mock global variable Store kv.Storage // mock global variable ctx context.Context @@ -72,7 +72,7 @@ type Context struct { values map[fmt.Stringer]any Mutations map[int64]*binlog.TableMutation sessionVars *variable.SessionVars - tblctx *tbctximpl.TableContextImpl + tblctx *tblsession.MutateContext cancel context.CancelFunc pcache sessionctx.SessionPlanCache level kvrpcpb.DiskFullOpt @@ -244,7 +244,7 @@ func (c *Context) GetExprCtx() exprctx.ExprContext { } // GetTableCtx returns the table.MutateContext -func (c *Context) GetTableCtx() tbctx.MutateContext { +func (c *Context) GetTableCtx() tblctx.MutateContext { return c.tblctx } @@ -636,8 +636,8 @@ func NewContext() *Context { } vars := variable.NewSessionVars(sctx) sctx.sessionVars = vars - sctx.SessionExprContext = exprctximpl.NewSessionExprContext(sctx) - sctx.tblctx = tbctximpl.NewTableContextImpl(sctx) + sctx.ExprContext = sessionexpr.NewExprContext(sctx) + sctx.tblctx = tblsession.NewMutateContext(sctx) vars.InitChunkSize = 2 vars.MaxChunkSize = 32 vars.TimeZone = time.UTC diff --git a/pkg/util/ranger/BUILD.bazel b/pkg/util/ranger/BUILD.bazel index e2d98b515f10c..698c48707c612 100644 --- a/pkg/util/ranger/BUILD.bazel +++ b/pkg/util/ranger/BUILD.bazel @@ -21,7 +21,7 @@ go_library( "//pkg/parser/format", "//pkg/parser/mysql", "//pkg/parser/terror", - "//pkg/planner/context", + "//pkg/planner/planctx", "//pkg/planner/util/fixcontrol", "//pkg/sessionctx/stmtctx", "//pkg/types", @@ -52,7 +52,7 @@ go_test( "//pkg/config", "//pkg/domain", "//pkg/expression", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/parser/ast", "//pkg/parser/model", "//pkg/parser/mysql", diff --git a/pkg/util/ranger/context/BUILD.bazel b/pkg/util/ranger/context/BUILD.bazel index bc0b60c7a4af8..68c6ace6f73c5 100644 --- a/pkg/util/ranger/context/BUILD.bazel +++ b/pkg/util/ranger/context/BUILD.bazel @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/errctx", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/types", "//pkg/util/context", ], @@ -21,7 +21,7 @@ go_test( flaky = True, deps = [ "//pkg/errctx", - "//pkg/expression/contextstatic", + "//pkg/expression/exprstatic", "//pkg/types", "//pkg/util/context", "//pkg/util/deeptest", diff --git a/pkg/util/ranger/context/context.go b/pkg/util/ranger/context/context.go index a70c369bff774..c86025d9c349f 100644 --- a/pkg/util/ranger/context/context.go +++ b/pkg/util/ranger/context/context.go @@ -16,7 +16,7 @@ package context import ( "github.com/pingcap/tidb/pkg/errctx" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/types" contextutil "github.com/pingcap/tidb/pkg/util/context" ) diff --git a/pkg/util/ranger/context/context_test.go b/pkg/util/ranger/context/context_test.go index 758877744f367..43add686d6f57 100644 --- a/pkg/util/ranger/context/context_test.go +++ b/pkg/util/ranger/context/context_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/pingcap/tidb/pkg/errctx" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/types" contextutil "github.com/pingcap/tidb/pkg/util/context" "github.com/pingcap/tidb/pkg/util/deeptest" @@ -32,7 +32,7 @@ func TestContextDetach(t *testing.T) { obj := &RangerContext{ TypeCtx: types.DefaultStmtNoWarningContext, ErrCtx: errctx.StrictNoWarningContext, - ExprCtx: contextstatic.NewStaticExprContext(), + ExprCtx: exprstatic.NewExprContext(), RangeFallbackHandler: &rangeFallbackHandler, PlanCacheTracker: &planCacheTracker, OptimizerFixControl: map[uint64]string{1: "a"}, diff --git a/pkg/util/ranger/ranger_test.go b/pkg/util/ranger/ranger_test.go index 2177561925c0c..02e68b94c44d2 100644 --- a/pkg/util/ranger/ranger_test.go +++ b/pkg/util/ranger/ranger_test.go @@ -22,7 +22,7 @@ import ( "github.com/pingcap/tidb/pkg/config" "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/expression/contextstatic" + "github.com/pingcap/tidb/pkg/expression/exprstatic" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -1877,7 +1877,7 @@ func getSelectionFromQuery(t *testing.T, sctx sessionctx.Context, sql string) *l func checkDetachRangeResult(t *testing.T, res *ranger.DetachRangeResult, expectedAccessConds, expectedRemainedConds, expectedRanges string) { // TODO: get the context from argument - ectx := contextstatic.NewStaticEvalContext() + ectx := exprstatic.NewEvalContext() require.Equal(t, expectedAccessConds, expression.StringifyExpressionsWithCtx(ectx, res.AccessConds)) require.Equal(t, expectedRemainedConds, expression.StringifyExpressionsWithCtx(ectx, res.RemainedConds)) require.Equal(t, expectedRanges, fmt.Sprintf("%v", res.Ranges)) diff --git a/pkg/util/ranger/types.go b/pkg/util/ranger/types.go index 8d0920f0be5fc..5b2e0d9491870 100644 --- a/pkg/util/ranger/types.go +++ b/pkg/util/ranger/types.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/kv" - "github.com/pingcap/tidb/pkg/planner/context" + "github.com/pingcap/tidb/pkg/planner/planctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/codec" "github.com/pingcap/tidb/pkg/util/collate" @@ -37,7 +37,7 @@ type MutableRanges interface { // Range returns the underlying range values. Range() Ranges // Rebuild rebuilds the underlying ranges again. - Rebuild(sctx context.PlanContext) error + Rebuild(sctx planctx.PlanContext) error // CloneForPlanCache clones the MutableRanges for plan cache. CloneForPlanCache() MutableRanges } @@ -51,7 +51,7 @@ func (rs Ranges) Range() Ranges { } // Rebuild rebuilds this range. -func (Ranges) Rebuild(context.PlanContext) error { +func (Ranges) Rebuild(planctx.PlanContext) error { return nil } diff --git a/pkg/util/rowDecoder/BUILD.bazel b/pkg/util/rowDecoder/BUILD.bazel index f5f541bc65d39..563a3ffa4ef52 100644 --- a/pkg/util/rowDecoder/BUILD.bazel +++ b/pkg/util/rowDecoder/BUILD.bazel @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/expression", - "//pkg/expression/context", + "//pkg/expression/exprctx", "//pkg/kv", "//pkg/meta/model", "//pkg/table", diff --git a/pkg/util/rowDecoder/decoder.go b/pkg/util/rowDecoder/decoder.go index b42973db34396..c81c9fea62045 100644 --- a/pkg/util/rowDecoder/decoder.go +++ b/pkg/util/rowDecoder/decoder.go @@ -19,7 +19,7 @@ import ( "time" "github.com/pingcap/tidb/pkg/expression" - exprctx "github.com/pingcap/tidb/pkg/expression/context" + "github.com/pingcap/tidb/pkg/expression/exprctx" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/table"