Skip to content

Commit a206b0b

Browse files
authored
distsql: do not change concurrency for keep order request when @@tidb_distsql_scan_concurrency is set (#60803)
close #60891
1 parent cb04077 commit a206b0b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

pkg/distsql/request_builder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/pingcap/tidb/pkg/kv"
3333
"github.com/pingcap/tidb/pkg/meta/model"
3434
"github.com/pingcap/tidb/pkg/parser/mysql"
35+
"github.com/pingcap/tidb/pkg/sessionctx/vardef"
3536
"github.com/pingcap/tidb/pkg/tablecodec"
3637
"github.com/pingcap/tidb/pkg/types"
3738
"github.com/pingcap/tidb/pkg/util/codec"
@@ -81,14 +82,17 @@ func (builder *RequestBuilder) Build() (*kv.Request, error) {
8182

8283
if dag := builder.dag; dag != nil {
8384
if execCnt := len(dag.Executors); execCnt == 1 {
84-
oldConcurrency := builder.Request.Concurrency
8585
// select * from t order by id
86-
if builder.Request.KeepOrder {
86+
if builder.Request.KeepOrder && builder.Request.Concurrency == vardef.DefDistSQLScanConcurrency {
8787
// When the DAG is just simple scan and keep order, set concurrency to 2.
8888
// If a lot data are returned to client, mysql protocol is the bottleneck so concurrency 2 is enough.
8989
// If very few data are returned to client, the speed is not optimal but good enough.
90+
//
91+
// If a user set @@tidb_distsql_scan_concurrency, he must be doing it by intention.
92+
// so only rewrite concurrency when @@tidb_distsql_scan_concurrency is default value.
9093
switch dag.Executors[0].Tp {
9194
case tipb.ExecType_TypeTableScan, tipb.ExecType_TypeIndexScan, tipb.ExecType_TypePartitionTableScan:
95+
oldConcurrency := builder.Request.Concurrency
9296
builder.Request.Concurrency = 2
9397
failpoint.Inject("testRateLimitActionMockConsumeAndAssert", func(val failpoint.Value) {
9498
if val.(bool) {

tests/integrationtest/r/executor/issues.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,14 @@ Limit_11 1.00 <actRows> root NULL NULL offset:0, count:100 <memory> <disk>
10001000
└─Limit_19 1.00 <actRows> cop[tikv] NULL NULL offset:0, count:100 <memory> <disk>
10011001
└─Selection_18 1.00 <actRows> cop[tikv] NULL NULL eq(executor__issues.pt.val, 126) <memory> <disk>
10021002
└─TableFullScan_17 256.00 <actRows> cop[tikv] table:pt NULL keep order:true <memory> <disk>
1003+
explain analyze select /*+ set_var(tidb_distsql_scan_concurrency=5)*/ * from t order by id;
1004+
id estRows actRows task access object execution info operator info memory disk
1005+
TableReader_11 256.00 <actRows> root NULL max_distsql_concurrency: 5 NULL <memory> <disk>
1006+
└─TableFullScan_10 256.00 <actRows> cop[tikv] table:t NULL keep order:true <memory> <disk>
1007+
explain analyze select /*+ set_var(tidb_distsql_scan_concurrency=15)*/ * from t order by id;
1008+
id estRows actRows task access object execution info operator info memory disk
1009+
TableReader_11 256.00 <actRows> root NULL max_distsql_concurrency: 2 NULL <memory> <disk>
1010+
└─TableFullScan_10 256.00 <actRows> cop[tikv] table:t NULL keep order:true <memory> <disk>
10031011
CREATE TABLE test_55837 (col1 int(4) NOT NULL, col2 bigint(4) NOT NULL, KEY col2_index (col2));
10041012
insert into test_55837 values(0,1725292800),(0,1725292800);
10051013
select from_unixtime( if(col2 >9999999999, col2/1000, col2), '%Y-%m-%d %H:%i:%s') as result from test_55837;

tests/integrationtest/t/executor/issues.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,15 @@ explain analyze select * from pt order by id limit 100000; # expected dists
763763
-- replace_regex /.*max_distsql_concurrency: (?P<num>[0-9]+).*/max_distsql_concurrency: $num/ /tikv_task:.*// /time:.*// /data:.*//
764764
explain analyze select * from pt where val = 126 order by id limit 100; # expected distsql concurrency 15
765765

766+
-- replace_column 8 <memory> 9 <disk> 3 <actRows>
767+
-- replace_regex /.*max_distsql_concurrency: (?P<num>[0-9]+).*/max_distsql_concurrency: $num/ /tikv_task:.*// /time:.*// /data:.*//
768+
explain analyze select /*+ set_var(tidb_distsql_scan_concurrency=5)*/ * from t order by id; # expected distsql concurrency 5
769+
770+
-- replace_column 8 <memory> 9 <disk> 3 <actRows>
771+
-- replace_regex /.*max_distsql_concurrency: (?P<num>[0-9]+).*/max_distsql_concurrency: $num/ /tikv_task:.*// /time:.*// /data:.*//
772+
explain analyze select /*+ set_var(tidb_distsql_scan_concurrency=15)*/ * from t order by id; # expected distsql concurrency 2
773+
774+
766775
# TestIssue55837
767776
CREATE TABLE test_55837 (col1 int(4) NOT NULL, col2 bigint(4) NOT NULL, KEY col2_index (col2));
768777
insert into test_55837 values(0,1725292800),(0,1725292800);

0 commit comments

Comments
 (0)