Skip to content

Commit

Permalink
optimize limit 0 query by skipping ranges call (#17535)
Browse files Browse the repository at this point in the history
  • Loading branch information
badboynt1 authored Jul 15, 2024
1 parent b410d7b commit b44e732
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 1245,20 @@ func (c *Compile) compilePlanScope(step int32, curNodeIdx int32, ns []*plan.Node
ss = c.compileSort(n, c.compileProjection(n, c.compileRestrict(node, ss)))
return ss, nil
case plan.Node_TABLE_SCAN:
if n.Limit != nil {
if cExpr, ok := n.Limit.Expr.(*plan.Expr_Lit); ok {
if cval, ok := cExpr.Lit.Value.(*plan.Literal_U64Val); ok {
if cval.U64Val == 0 {
// optimize for limit 0
rs := newScope(Merge)
rs.NodeInfo = engine.Node{Addr: c.addr, Mcpu: 1}
rs.Proc = process.NewFromProc(c.proc, c.proc.Ctx, 0)
return c.compileLimit(n, []*Scope{rs}), nil
}
}
}
}

c.appendMetaTables(n.ObjRef)
ss, err = c.compileTableScan(n)
if err != nil {
Expand Down Expand Up @@ -2968,7 2982,6 @@ func (c *Compile) compileOffset(n *plan.Node, ss []*Scope) []*Scope {

func (c *Compile) compileLimit(n *plan.Node, ss []*Scope) []*Scope {
currentFirstFlag := c.anal.isFirst

for i := range ss {
c.anal.isFirst = currentFirstFlag
if containBrokenNode(ss[i]) {
Expand Down

0 comments on commit b44e732

Please sign in to comment.