-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
plan: forbid limit to push across selection. #2793
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -807,20 +807,21 @@ func (p *Selection) convert2PhysicalPlan(prop *requiredProperty) (*physicalPlanI | |
info = infoEnforce | ||
} | ||
} | ||
if ds, ok := p.children[0].(*DataSource); !ok { | ||
info = p.matchProperty(prop, info) | ||
} else { | ||
client := p.ctx.GetClient() | ||
memDB := infoschema.IsMemoryDB(ds.DBName.L) | ||
isDistReq := !memDB && client != nil && client.SupportRequestType(kv.ReqTypeSelect, 0) | ||
if !isDistReq { | ||
info = p.matchProperty(prop, info) | ||
} | ||
} | ||
info = p.matchProperty(prop, info) | ||
p.storePlanInfo(prop, info) | ||
return info, nil | ||
} | ||
|
||
func (p *Selection) appendSelToInfo(info *physicalPlanInfo) *physicalPlanInfo { | ||
np := *p | ||
np.SetChildren(info.p) | ||
return &physicalPlanInfo{ | ||
p: &np, | ||
cost: info.cost, | ||
count: uint64(float64(info.count) * selectionFactor), | ||
} | ||
} | ||
|
||
func (p *Selection) convert2PhysicalPlanPushOrder(prop *requiredProperty) (*physicalPlanInfo, error) { | ||
child := p.children[0].(LogicalPlan) | ||
limit := prop.limit | ||
|
@@ -838,7 +839,17 @@ func (p *Selection) convert2PhysicalPlanPushOrder(prop *requiredProperty) (*phys | |
info = enforceProperty(&requiredProperty{limit: limit}, info) | ||
} | ||
} else { | ||
info = enforceProperty(&requiredProperty{limit: limit}, info) | ||
info = enforceProperty(&requiredProperty{limit: limit}, p.appendSelToInfo(info)) | ||
} | ||
} else if ds, ok := p.children[0].(*DataSource); !ok { | ||
// TODO: It's tooooooo tricky here, we will remove all these logic after implementing DAG push down. | ||
info = p.appendSelToInfo(info) | ||
} else { | ||
client := p.ctx.GetClient() | ||
memDB := infoschema.IsMemoryDB(ds.DBName.L) | ||
isDistReq := !memDB && client != nil && client.SupportRequestType(kv.ReqTypeSelect, 0) | ||
if !isDistReq { | ||
info = p.appendSelToInfo(info) | ||
} | ||
} | ||
return info, nil | ||
|
@@ -855,6 +866,8 @@ func (p *Selection) convert2PhysicalPlanEnforce(prop *requiredProperty) (*physic | |
if prop.limit != nil && len(prop.props) > 0 { | ||
if t, ok := info.p.(physicalDistSQLPlan); ok { | ||
t.addTopN(p.ctx, prop) | ||
} else if _, ok := info.p.(*Selection); !ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the child There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If child is selection, it means the selection has been processed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I remembered, the child has pulled the parent Selection down. |
||
info = p.appendSelToInfo(info) | ||
} | ||
info = enforceProperty(prop, info) | ||
} else if len(prop.props) != 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the
childPlanInfo
is actually not child, it is the selection itself?Then the
matchProperty
is not used as it is supposed to be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in case of not on table, it's the selection itself.