From 14d085ba54ad19a53c7d2bab207be5fcb170e846 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 29 Sep 2022 11:57:44 +0800 Subject: [PATCH 1/2] executor,sessionctx: enable coprocessor paging and make TestCoprocessorPagingSize stable (#38161) close pingcap/tidb#38158 --- executor/distsql_test.go | 3 ++ planner/core/testdata/plan_suite_out.json | 34 +++++++++++------------ sessionctx/variable/tidb_vars.go | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/executor/distsql_test.go b/executor/distsql_test.go index 1f895a6703420..59b3aecc2bb6a 100644 --- a/executor/distsql_test.go +++ b/executor/distsql_test.go @@ -431,6 +431,9 @@ func TestCoprocessorPagingSize(t *testing.T) { tk.MustExec(fmt.Sprintf("insert into t_paging values %v", strings.Join(values, ", "))) tk.MustQuery("select @@tidb_min_paging_size").Check(testkit.Rows(strconv.FormatUint(paging.MinPagingSize, 10))) + // Enable the coprocessor paging protocol. + tk.MustExec("set @@tidb_enable_paging = on") + // When the min paging size is small, we need more RPC roundtrip! // Check 'rpc_num' in the execution information // diff --git a/planner/core/testdata/plan_suite_out.json b/planner/core/testdata/plan_suite_out.json index 4af35c8f71984..18e4396e16de6 100644 --- a/planner/core/testdata/plan_suite_out.json +++ b/planner/core/testdata/plan_suite_out.json @@ -6090,11 +6090,11 @@ " │ ├─IndexRangeScan(Build) 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:[\"chad999\",\"chad99:\"), keep order:false, stats:pseudo", " │ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo", " └─MaxOneRow(Probe) 1.00 root ", - " └─HashAgg 1.00 root funcs:sum(Column#17)->Column#13", - " └─IndexLookUp 1.00 root ", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", - " └─HashAgg(Probe) 1.00 cop[tikv] funcs:sum(test.tb.code)->Column#17", - " └─TableRowIDScan 10.00 cop[tikv] table:tb keep order:false, stats:pseudo" + " └─StreamAgg 1.00 root funcs:sum(Column#21)->Column#13", + " └─Projection 10.00 root cast(test.tb.code, decimal(10,0) BINARY)->Column#21", + " └─IndexLookUp 10.00 root ", + " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", + " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:tb keep order:false, stats:pseudo" ], "Result": null, "Warning": null @@ -6287,12 +6287,12 @@ " └─Selection(Probe) 0.80 root gt(Column#19, 100)", " └─MaxOneRow 1.00 root ", " └─StreamAgg 1.00 root funcs:max(test.td.id)->Column#19", - " └─TopN 0.25 root test.td.id:desc, offset:0, count:1", - " └─IndexLookUp 0.25 root ", - " ├─Selection(Build) 9.99 cop[tikv] eq(test.ta.id, test.td.id)", - " │ └─IndexFullScan 9990.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:false, stats:pseudo", - " └─TopN(Probe) 0.25 cop[tikv] test.td.id:desc, offset:0, count:1", - " └─Selection 0.25 cop[tikv] like(test.td.name, \"chad999%\", 92)", + " └─Limit 0.25 root offset:0, count:1", + " └─Projection 0.25 root test.td.id, test.td.name", + " └─IndexLookUp 0.25 root ", + " ├─Selection(Build) 9.99 cop[tikv] eq(test.ta.id, test.td.id)", + " │ └─IndexFullScan 9990.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo", + " └─Selection(Probe) 0.25 cop[tikv] like(test.td.name, \"chad999%\", 92)", " └─TableRowIDScan 9.99 cop[tikv] table:td keep order:false, stats:pseudo" ], "Result": null, @@ -6324,12 +6324,12 @@ " └─Selection(Probe) 0.80 root gt(Column#19, 100)", " └─MaxOneRow 1.00 root ", " └─StreamAgg 1.00 root funcs:max(test.td.id)->Column#19", - " └─TopN 0.25 root test.td.id:desc, offset:0, count:1", - " └─IndexLookUp 0.25 root ", - " ├─Selection(Build) 9.99 cop[tikv] eq(test.ta.id, test.td.id)", - " │ └─IndexFullScan 9990.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:false, stats:pseudo", - " └─TopN(Probe) 0.25 cop[tikv] test.td.id:desc, offset:0, count:1", - " └─Selection 0.25 cop[tikv] like(test.td.name, \"chad999%\", 92)", + " └─Limit 0.25 root offset:0, count:1", + " └─Projection 0.25 root test.td.id, test.td.name", + " └─IndexLookUp 0.25 root ", + " ├─Selection(Build) 9.99 cop[tikv] eq(test.ta.id, test.td.id)", + " │ └─IndexFullScan 9990.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo", + " └─Selection(Probe) 0.25 cop[tikv] like(test.td.name, \"chad999%\", 92)", " └─TableRowIDScan 9.99 cop[tikv] table:td keep order:false, stats:pseudo" ], "Result": null, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 2d4c79954fad3..47ef49a593648 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -1055,7 +1055,7 @@ const ( DefTiDBPrepPlanCacheMemoryGuardRatio = 0.1 DefTiDBEnableConcurrentDDL = concurrencyddl.TiDBEnableConcurrentDDL DefTiDBSimplifiedMetrics = false - DefTiDBEnablePaging = false + DefTiDBEnablePaging = true DefTiFlashFineGrainedShuffleStreamCount = 0 DefStreamCountWhenMaxThreadsNotSet = 8 DefTiFlashFineGrainedShuffleBatchSize = 8192 From 52099eb910df6e2546791075e6cfd5cb08447f21 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 29 Sep 2022 14:07:45 +0800 Subject: [PATCH 2/2] *: DATA RACE in the temptable.AttachLocalTemporaryTableInfoSchema (#38237) close pingcap/tidb#38236 --- infoschema/infoschema.go | 5 +++-- table/temptable/infoschema.go | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index efbb5f33d8af6..085c5f1d3e3e2 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -623,8 +623,9 @@ func (is *SessionTables) schemaTables(schema model.CIStr) *schemaTables { // So when a database is dropped, its temporary tables still exist and can be returned by TableByName/TableByID. type SessionExtendedInfoSchema struct { InfoSchema - LocalTemporaryTables *SessionTables - MdlTables *SessionTables + LocalTemporaryTablesOnce sync.Once + LocalTemporaryTables *SessionTables + MdlTables *SessionTables } // TableByName implements InfoSchema.TableByName diff --git a/table/temptable/infoschema.go b/table/temptable/infoschema.go index b8523a1ed5595..f2de5cf8b5dfe 100644 --- a/table/temptable/infoschema.go +++ b/table/temptable/infoschema.go @@ -26,7 +26,9 @@ func AttachLocalTemporaryTableInfoSchema(sctx sessionctx.Context, is infoschema. return is } if se, ok := is.(*infoschema.SessionExtendedInfoSchema); ok { - se.LocalTemporaryTables = localTemporaryTables + se.LocalTemporaryTablesOnce.Do(func() { + se.LocalTemporaryTables = localTemporaryTables + }) return is } @@ -39,9 +41,9 @@ func AttachLocalTemporaryTableInfoSchema(sctx sessionctx.Context, is infoschema. // DetachLocalTemporaryTableInfoSchema detach local temporary table information schema from is func DetachLocalTemporaryTableInfoSchema(is infoschema.InfoSchema) infoschema.InfoSchema { if attachedInfoSchema, ok := is.(*infoschema.SessionExtendedInfoSchema); ok { - newIs := *attachedInfoSchema + newIs := attachedInfoSchema newIs.LocalTemporaryTables = nil - return &newIs + return newIs } return is