Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

push limit for incorrelate subquery. #1195

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions executor/subquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type subquery struct {
func (sq *subquery) EvalRows(ctx context.Context, rowCount int) ([]types.Datum, error) {
b := newExecutorBuilder(ctx, sq.is)
plan.Refine(sq.plan)
plan.PushLimit(sq.plan, &ast.Limit{Count: 1})
e := b.build(sq.plan)
if b.err != nil {
return nil, errors.Trace(b.err)
Expand Down
11 changes: 6 additions & 5 deletions optimizer/plan/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (b *planBuilder) buildSelect(sel *ast.SelectStmt) Plan {
}
if sel.Limit != nil {
if canPushLimit {
pushLimit(p, sel.Limit)
PushLimit(p, sel.Limit)
}
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
Expand Down Expand Up @@ -594,7 +594,8 @@ func buildResultField(tableName, name string, tp byte, size int) *ast.ResultFiel
}
}

func pushLimit(p Plan, limit *ast.Limit) {
// PushLimit tries to push limit count to the plan.
func PushLimit(p Plan, limit *ast.Limit) {
switch x := p.(type) {
case *IndexScan:
limitCount := int64(limit.Offset + limit.Count)
Expand All @@ -605,7 +606,7 @@ func pushLimit(p Plan, limit *ast.Limit) {
default:
child := x.GetChildByIndex(0)
if child != nil {
pushLimit(child, limit)
PushLimit(child, limit)
}
}
}
Expand Down Expand Up @@ -812,7 +813,7 @@ func (b *planBuilder) buildUpdate(update *ast.UpdateStmt) Plan {
}
}
if sel.Limit != nil {
pushLimit(p, sel.Limit)
PushLimit(p, sel.Limit)
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
return nil
Expand Down Expand Up @@ -851,7 +852,7 @@ func (b *planBuilder) buildDelete(del *ast.DeleteStmt) Plan {
}
}
if sel.Limit != nil {
pushLimit(p, sel.Limit)
PushLimit(p, sel.Limit)
p = b.buildLimit(p, sel.Limit)
if b.err != nil {
return nil
Expand Down