Skip to content

Commit 7dc5037

Browse files
committed
This is an automated cherry-pick of pingcap#52979
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 2c3afb7 commit 7dc5037

File tree

3 files changed

+4788
-3
lines changed

3 files changed

+4788
-3
lines changed

pkg/planner/core/task.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,12 @@ func (p *PhysicalLimit) attach2Task(tasks ...task) task {
877877
} else if !cop.idxMergeIsIntersection {
878878
// We only support push part of the order prop down to index merge build case.
879879
if len(cop.rootTaskConds) == 0 {
880-
if cop.indexPlanFinished {
881-
// when the index plan is finished, sink the limit to the index merge table side.
880+
// For double read which requires order being kept, the limit cannot be pushed down to the table side,
881+
// because handles would be reordered before being sent to table scan.
882+
if cop.indexPlanFinished && !cop.keepOrder {
883+
// when the index plan is finished and index plan is not ordered, sink the limit to the index merge table side.
882884
suspendLimitAboveTablePlan()
883-
} else {
885+
} else if !cop.indexPlanFinished {
884886
// cop.indexPlanFinished = false indicates the table side is a pure table-scan, sink the limit to the index merge index side.
885887
newCount := p.Offset + p.Count
886888
limitChildren := make([]PhysicalPlan, 0, len(cop.idxMergePartPlans))
@@ -895,6 +897,10 @@ func (p *PhysicalLimit) attach2Task(tasks ...task) task {
895897
cop.idxMergePartPlans = limitChildren
896898
t = cop.convertToRootTask(p.SCtx())
897899
sunk = p.sinkIntoIndexMerge(t)
900+
} else {
901+
// when there are some limitations, just sink the limit upon the index merge reader.
902+
t = cop.ConvertToRootTask(p.SCtx())
903+
sunk = p.sinkIntoIndexMerge(t)
898904
}
899905
} else {
900906
// when there are some root conditions, just sink the limit upon the index merge reader.

0 commit comments

Comments
 (0)