Skip to content

Commit

Permalink
small improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Mar 9, 2023
1 parent d72bab7 commit c45f116
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ func (ssr *sortedSelectResults) Next(ctx context.Context, c *chunk.Chunk) (err e
for c.NumRows() < c.RequiredRows() {
minSelectResultIdx := -1
for i := range ssr.cachedChunks {
if ssr.cachedChunkIdx[i] >= ssr.cachedChunks[i].NumRows() {
if ssr.cachedChunkIdx[i] == ssr.cachedChunks[i].NumRows() {
prevMemUsage := ssr.cachedChunks[i].MemoryUsage()
if err = ssr.selectResult[i].Next(ctx, ssr.cachedChunks[i]); err != nil {
return err
}
ssr.cachedChunkIdx[i] = 0
ssr.memTracker.Consume(ssr.cachedChunks[i].MemoryUsage() - prevMemUsage)
if ssr.cachedChunks[i].NumRows() == 0 {
continue
}
ssr.cachedChunkIdx[i] = 0
ssr.memTracker.Consume(ssr.cachedChunks[i].MemoryUsage() - prevMemUsage)
}
idx := ssr.cachedChunkIdx[i]
row := ssr.cachedChunks[i].GetRow(idx)
Expand Down
3 changes: 2 additions & 1 deletion executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ type IndexReaderExecutor struct {

keepOrder bool
desc bool
byItems []*plannerutil.ByItems
// byItems only for partition table with orderBy + pushedLimit
byItems []*plannerutil.ByItems

corColInFilter bool
corColInAccess bool
Expand Down
1 change: 1 addition & 0 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type TableReaderExecutor struct {

keepOrder bool
desc bool
// byItems only for partition table with orderBy + pushedLimit
byItems []*util.ByItems
paging bool
storeType kv.StoreType
Expand Down
6 changes: 4 additions & 2 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ type PhysicalIndexScan struct {
isPartition bool
Desc bool
KeepOrder bool
ByItems []*util.ByItems
// ByItems only for partition table with orderBy + pushedLimit
ByItems []*util.ByItems

// DoubleRead means if the index executor will read kv two times.
// If the query requires the columns that don't belong to index, DoubleRead will be true.
DoubleRead bool
Expand Down Expand Up @@ -826,7 +828,7 @@ type PhysicalTableScan struct {
// KeepOrder is true, if sort data by scanning pkcol,
KeepOrder bool
Desc bool
// ByItems only for partition table with pushed limit
// ByItems only for partition table with orderBy + pushedLimit
ByItems []*util.ByItems

isChildOfIndexLookUp bool
Expand Down
9 changes: 5 additions & 4 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,13 +1233,14 @@ func (p *PhysicalTopN) pushPartialTopNDownToCop(copTsk *copTask) (task, bool) {
}

rootTask := copTsk.convertToRootTask(p.ctx)
if _, ok := rootTask.p.(*PhysicalIndexLookUpReader); !ok {
// only support IndexReader now.
if _, ok := rootTask.p.(*PhysicalIndexReader); ok {
rootLimit := PhysicalLimit{
Count: p.Count,
Offset: p.Offset,
PartitionBy: newPartitionBy,
}.Init(p.SCtx(), stats, p.SelectBlockOffset())
rootLimit.SetSchema(copTsk.indexPlan.Schema())
rootLimit.SetSchema(rootTask.plan().Schema())
return attachPlan2Task(rootLimit, rootTask), true
}
}
Expand Down Expand Up @@ -1285,13 +1286,13 @@ func (p *PhysicalTopN) pushPartialTopNDownToCop(copTsk *copTask) (task, bool) {
tblScan.SetStats(tblScan.Stats().ScaleByExpectCnt(scaledRowCount))
}

rootTask := copTsk.convertToRootTask(p.ctx)
rootLimit := PhysicalLimit{
Count: p.Count,
Offset: p.Offset,
PartitionBy: newPartitionBy,
}.Init(p.SCtx(), stats, p.SelectBlockOffset())
rootLimit.SetSchema(copTsk.tablePlan.Schema())
rootTask := copTsk.convertToRootTask(p.ctx)
rootLimit.SetSchema(rootTask.plan().Schema())
return attachPlan2Task(rootLimit, rootTask), true
} else {
return nil, false
Expand Down

0 comments on commit c45f116

Please sign in to comment.