Skip to content

Commit 2493981

Browse files
authored
distsql, executor: remove pctx from trectx (#52496)
close #52495
1 parent 7a85b01 commit 2493981

File tree

8 files changed

+43
-40
lines changed

8 files changed

+43
-40
lines changed

pkg/distsql/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ go_library(
1616
"//pkg/errctx",
1717
"//pkg/errno",
1818
"//pkg/expression",
19-
"//pkg/infoschema",
19+
"//pkg/infoschema/context",
2020
"//pkg/kv",
2121
"//pkg/metrics",
2222
"//pkg/parser/model",

pkg/distsql/request_builder.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/pingcap/tidb/pkg/ddl/placement"
2828
distsqlctx "github.com/pingcap/tidb/pkg/distsql/context"
2929
"github.com/pingcap/tidb/pkg/errctx"
30-
"github.com/pingcap/tidb/pkg/infoschema"
30+
infoschema "github.com/pingcap/tidb/pkg/infoschema/context"
3131
"github.com/pingcap/tidb/pkg/kv"
3232
"github.com/pingcap/tidb/pkg/parser/model"
3333
"github.com/pingcap/tidb/pkg/parser/mysql"
@@ -45,7 +45,7 @@ import (
4545
// It is called before we issue a kv request by "Select".
4646
type RequestBuilder struct {
4747
kv.Request
48-
is infoschema.InfoSchema
48+
is infoschema.MetaOnlyInfoSchema
4949
err error
5050
}
5151

@@ -340,11 +340,7 @@ func (builder *RequestBuilder) SetTiDBServerID(serverID uint64) *RequestBuilder
340340

341341
// SetFromInfoSchema sets the following fields from infoSchema:
342342
// "bundles"
343-
func (builder *RequestBuilder) SetFromInfoSchema(pis any) *RequestBuilder {
344-
is, ok := pis.(infoschema.InfoSchema)
345-
if !ok {
346-
return builder
347-
}
343+
func (builder *RequestBuilder) SetFromInfoSchema(is infoschema.MetaOnlyInfoSchema) *RequestBuilder {
348344
builder.is = is
349345
builder.Request.SchemaVar = is.SchemaMetaVersion()
350346
return builder
@@ -387,13 +383,13 @@ func (builder *RequestBuilder) verifyTxnScope() error {
387383
if !valid {
388384
var tblName string
389385
var partName string
390-
tblInfo, _, partInfo := builder.is.FindTableByPartitionID(phyTableID)
386+
tblInfo, _, partInfo := builder.is.FindTableInfoByPartitionID(phyTableID)
391387
if tblInfo != nil && partInfo != nil {
392-
tblName = tblInfo.Meta().Name.String()
388+
tblName = tblInfo.Name.String()
393389
partName = partInfo.Name.String()
394390
} else {
395-
tblInfo, _ = builder.is.TableByID(phyTableID)
396-
tblName = tblInfo.Meta().Name.String()
391+
tblInfo, _ = builder.is.TableInfoByID(phyTableID)
392+
tblName = tblInfo.Name.String()
397393
}
398394
err := fmt.Errorf("table %v can not be read by %v txn_scope", tblName, txnScope)
399395
if len(partName) > 0 {
@@ -703,7 +699,7 @@ func CommonHandleRangesToKVRanges(dctx *distsqlctx.DistSQLContext, tids []int64,
703699
}
704700

705701
// VerifyTxnScope verify whether the txnScope and visited physical table break the leader rule's dcLocation.
706-
func VerifyTxnScope(txnScope string, physicalTableID int64, is infoschema.InfoSchema) bool {
702+
func VerifyTxnScope(txnScope string, physicalTableID int64, is infoschema.MetaOnlyInfoSchema) bool {
707703
if txnScope == "" || txnScope == kv.GlobalTxnScope {
708704
return true
709705
}

pkg/executor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ go_library(
132132
"//pkg/expression/aggregation",
133133
"//pkg/expression/context",
134134
"//pkg/infoschema",
135+
"//pkg/infoschema/context",
135136
"//pkg/keyspace",
136137
"//pkg/kv",
137138
"//pkg/lightning/log",

pkg/executor/table_reader.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/pingcap/tidb/pkg/expression"
3535
exprctx "github.com/pingcap/tidb/pkg/expression/context"
3636
"github.com/pingcap/tidb/pkg/infoschema"
37+
isctx "github.com/pingcap/tidb/pkg/infoschema/context"
3738
"github.com/pingcap/tidb/pkg/kv"
3839
"github.com/pingcap/tidb/pkg/parser/model"
3940
planctx "github.com/pingcap/tidb/pkg/planner/context"
@@ -81,16 +82,16 @@ type tableReaderExecutorContext struct {
8182
dctx *distsqlctx.DistSQLContext
8283
rctx *rangerctx.RangerContext
8384
buildPBCtx *planctx.BuildPBContext
84-
pctx planctx.PlanContext
8585
ectx exprctx.BuildContext
8686

8787
stmtMemTracker *memory.Tracker
8888

89+
infoSchema isctx.MetaOnlyInfoSchema
8990
getDDLOwner func(context.Context) (*infosync.ServerInfo, error)
9091
}
9192

92-
func (treCtx *tableReaderExecutorContext) GetInfoSchema() infoschema.InfoSchema {
93-
return treCtx.pctx.GetInfoSchema().(infoschema.InfoSchema)
93+
func (treCtx *tableReaderExecutorContext) GetInfoSchema() isctx.MetaOnlyInfoSchema {
94+
return treCtx.infoSchema
9495
}
9596

9697
func (treCtx *tableReaderExecutorContext) GetDDLOwner(ctx context.Context) (*infosync.ServerInfo, error) {
@@ -123,9 +124,9 @@ func newTableReaderExecutorContext(sctx sessionctx.Context) tableReaderExecutorC
123124
dctx: sctx.GetDistSQLCtx(),
124125
rctx: pctx.GetRangerCtx(),
125126
buildPBCtx: pctx.GetBuildPBCtx(),
126-
pctx: pctx,
127127
ectx: sctx.GetExprCtx(),
128128
stmtMemTracker: sctx.GetSessionVars().StmtCtx.MemTracker,
129+
infoSchema: pctx.GetInfoSchema(),
129130
getDDLOwner: getDDLOwner,
130131
}
131132
}

pkg/infoschema/context/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ go_library(
55
srcs = ["infoschema.go"],
66
importpath = "github.com/pingcap/tidb/pkg/infoschema/context",
77
visibility = ["//visibility:public"],
8-
deps = ["//pkg/parser/model"],
8+
deps = [
9+
"//pkg/ddl/placement",
10+
"//pkg/parser/model",
11+
],
912
)

pkg/infoschema/context/infoschema.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
package context
1616

17-
import "github.com/pingcap/tidb/pkg/parser/model"
17+
import (
18+
"github.com/pingcap/tidb/pkg/ddl/placement"
19+
"github.com/pingcap/tidb/pkg/parser/model"
20+
)
1821

1922
// MetaOnlyInfoSchema is a workaround.
2023
// Due to circular dependency cannot return the complete interface.
@@ -31,4 +34,23 @@ type MetaOnlyInfoSchema interface {
3134
AllSchemas() []*model.DBInfo
3235
AllSchemaNames() []model.CIStr
3336
SchemaTableInfos(schema model.CIStr) []*model.TableInfo
37+
Misc
38+
}
39+
40+
// Misc contains the methods that are not closely related to InfoSchema.
41+
type Misc interface {
42+
PolicyByName(name model.CIStr) (*model.PolicyInfo, bool)
43+
ResourceGroupByName(name model.CIStr) (*model.ResourceGroupInfo, bool)
44+
// PlacementBundleByPhysicalTableID is used to get a rule bundle.
45+
PlacementBundleByPhysicalTableID(id int64) (*placement.Bundle, bool)
46+
// AllPlacementBundles is used to get all placement bundles
47+
AllPlacementBundles() []*placement.Bundle
48+
// AllPlacementPolicies returns all placement policies
49+
AllPlacementPolicies() []*model.PolicyInfo
50+
// AllResourceGroups returns all resource groups
51+
AllResourceGroups() []*model.ResourceGroupInfo
52+
// HasTemporaryTable returns whether information schema has temporary table
53+
HasTemporaryTable() bool
54+
// GetTableReferredForeignKeys gets the table's ReferredFKInfo by lowercase schema and table name.
55+
GetTableReferredForeignKeys(schema, table string) []*model.ReferredFKInfo
3456
}

pkg/infoschema/infoschema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/pingcap/tidb/pkg/util/mock"
3333
)
3434

35-
var _ Misc = &infoSchemaMisc{}
35+
var _ context.Misc = &infoSchemaMisc{}
3636

3737
type sortedTables []table.Table
3838

pkg/infoschema/interface.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package infoschema
1616

1717
import (
18-
"github.com/pingcap/tidb/pkg/ddl/placement"
1918
"github.com/pingcap/tidb/pkg/infoschema/context"
2019
"github.com/pingcap/tidb/pkg/parser/model"
2120
"github.com/pingcap/tidb/pkg/table"
@@ -30,24 +29,5 @@ type InfoSchema interface {
3029
TableByID(id int64) (table.Table, bool)
3130
SchemaTables(schema model.CIStr) []table.Table
3231
FindTableByPartitionID(partitionID int64) (table.Table, *model.DBInfo, *model.PartitionDefinition)
33-
Misc
3432
base() *infoSchema
3533
}
36-
37-
// Misc contains the methods that are not closely related to InfoSchema.
38-
type Misc interface {
39-
PolicyByName(name model.CIStr) (*model.PolicyInfo, bool)
40-
ResourceGroupByName(name model.CIStr) (*model.ResourceGroupInfo, bool)
41-
// PlacementBundleByPhysicalTableID is used to get a rule bundle.
42-
PlacementBundleByPhysicalTableID(id int64) (*placement.Bundle, bool)
43-
// AllPlacementBundles is used to get all placement bundles
44-
AllPlacementBundles() []*placement.Bundle
45-
// AllPlacementPolicies returns all placement policies
46-
AllPlacementPolicies() []*model.PolicyInfo
47-
// AllResourceGroups returns all resource groups
48-
AllResourceGroups() []*model.ResourceGroupInfo
49-
// HasTemporaryTable returns whether information schema has temporary table
50-
HasTemporaryTable() bool
51-
// GetTableReferredForeignKeys gets the table's ReferredFKInfo by lowercase schema and table name.
52-
GetTableReferredForeignKeys(schema, table string) []*model.ReferredFKInfo
53-
}

0 commit comments

Comments
 (0)