Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#41120
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
solotzg authored and ti-chi-bot committed Feb 7, 2023
1 parent df204de commit a823414
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (builder *RequestBuilder) SetDAGRequest(dag *tipb.DAGRequest) *RequestBuild
if limit != nil && limit.Limit < estimatedRegionRowCount {
builder.Request.Concurrency = 1
}
builder.Request.LimitSize = limit.GetLimit()
}
return builder
}
Expand Down
1 change: 1 addition & 0 deletions distsql/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ func TestScanLimitConcurrency(t *testing.T) {
Build()
require.NoError(t, err)
require.Equal(t, tt.concurrency, actual.Concurrency)
require.Equal(t, actual.LimitSize, tt.limit)
})
}
}
Expand Down
7 changes: 7 additions & 0 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,13 @@ type Request struct {
FixedRowCountHint []int
// StoreBatchSize indicates the batch size of coprocessor in the same store.
StoreBatchSize int
<<<<<<< HEAD
=======
// ResourceGroupName is the name of the bind resource group.
ResourceGroupName string
// LimitSize indicates whether the request is scan and limit
LimitSize uint64
>>>>>>> 98aff8c2119 (executor: disable paging for small limit (#41120))
}

// CoprRequestAdjuster is used to check and adjust a copr request according to specific rules.
Expand Down
8 changes: 7 additions & 1 deletion store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,13 @@ func buildCopTasks(bo *Backoffer, cache *RegionCache, ranges *KeyRanges, req *kv
}
i = nextI
if req.Paging.Enable {
pagingSize = paging.GrowPagingSize(pagingSize, req.Paging.MaxPagingSize)
if req.LimitSize != 0 && req.LimitSize < pagingSize {
// disable paging for small limit.
task.paging = false
task.pagingSize = 0
} else {
pagingSize = paging.GrowPagingSize(pagingSize, req.Paging.MaxPagingSize)
}
}
taskID++
}
Expand Down
35 changes: 35 additions & 0 deletions store/copr/coprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,13 @@ func TestBuildPagingTasks(t *testing.T) {
req := &kv.Request{}
req.Paging.Enable = true
req.Paging.MinPagingSize = paging.MinPagingSize
<<<<<<< HEAD
flashReq := &kv.Request{}
flashReq.StoreType = kv.TiFlash
tasks, err := buildCopTasks(bo, cache, buildCopRanges("a", "c"), req, nil)
=======
tasks, err := buildTestCopTasks(bo, cache, buildCopRanges("a", "c"), req, nil)
>>>>>>> 98aff8c2119 (executor: disable paging for small limit (#41120))
require.NoError(t, err)
require.Len(t, tasks, 1)
require.Len(t, tasks, 1)
Expand All @@ -510,6 +514,37 @@ func TestBuildPagingTasks(t *testing.T) {
require.Equal(t, tasks[0].pagingSize, paging.MinPagingSize)
}

func TestBuildPagingTasksDisablePagingForSmallLimit(t *testing.T) {
mockClient, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
require.NoError(t, err)
defer func() {
pdClient.Close()
err = mockClient.Close()
require.NoError(t, err)
}()
_, regionIDs, _ := testutils.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t"))

pdCli := tikv.NewCodecPDClient(tikv.ModeTxn, pdClient)
defer pdCli.Close()

cache := NewRegionCache(tikv.NewRegionCache(pdCli))
defer cache.Close()

bo := backoff.NewBackofferWithVars(context.Background(), 3000, nil)

req := &kv.Request{}
req.Paging.Enable = true
req.Paging.MinPagingSize = paging.MinPagingSize
req.LimitSize = 1
tasks, err := buildTestCopTasks(bo, cache, buildCopRanges("a", "c"), req, nil)
require.NoError(t, err)
require.Len(t, tasks, 1)
require.Len(t, tasks, 1)
taskEqual(t, tasks[0], regionIDs[0], 0, "a", "c")
require.False(t, tasks[0].paging)
require.Equal(t, tasks[0].pagingSize, uint64(0))
}

func toCopRange(r kv.KeyRange) *coprocessor.KeyRange {
coprRange := coprocessor.KeyRange{}
coprRange.Start = r.StartKey
Expand Down

0 comments on commit a823414

Please sign in to comment.