Skip to content
Merged
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
2 changes: 1 addition & 1 deletion optgen/cmd/support/agg_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (g *AggGen) genAggStringer(define AggDef) {
fmt.Fprintf(g.w, " pr.WriteChildren(children...)\n")
fmt.Fprintf(g.w, " return pr.String()\n")
fmt.Fprintf(g.w, " }\n")
fmt.Fprintf(g.w, " return fmt.Sprintf(\"%s(%%s)\", a.Child)\n", strings.ToUpper(sqlName))
fmt.Fprintf(g.w, " return \"%s(\" + a.Child.String() + \")\"\n", strings.ToUpper(sqlName))
fmt.Fprintf(g.w, "}\n\n")

fmt.Fprintf(g.w, "func (a *%s) DebugString() string {\n", define.Name)
Expand Down
2 changes: 1 addition & 1 deletion optgen/cmd/support/agg_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestAggGen(t *testing.T) {
pr.WriteChildren(children...)
return pr.String()
}
return fmt.Sprintf("TEST(%s)", a.Child)
return "TEST(" + a.Child.String() + ")"
}

func (a *Test) DebugString() string {
Expand Down
56 changes: 12 additions & 44 deletions sql/analyzer/apply_indexes_from_outer_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,53 +392,21 @@ func extractJoinColumnExpr(e sql.Expression) (leftCol *joinColExpr, rightCol *jo
}
}

func containsColumns(e sql.Expression) bool {
var result bool
sql.Inspect(e, func(e sql.Expression) bool {
_, ok1 := e.(*expression.GetField)
_, ok2 := e.(*expression.UnresolvedColumn)
if ok1 || ok2 {
result = true
return false
}
return true
})
return result
}

func containsSubquery(e sql.Expression) bool {
var result bool
sql.Inspect(e, func(e sql.Expression) bool {
if _, ok := e.(*plan.Subquery); ok {
result = true
return false
}
return true
})
return result
}

// isEvaluable determines if sql.Expression has/contains columns, subqueries, bindvars, or procedure params.
// Those expressions are NOT evaluable.
func isEvaluable(e sql.Expression) bool {
return !containsColumns(e) && !containsSubquery(e) && !containsBindvars(e) && !containsProcedureParam(e)
}

func containsBindvars(e sql.Expression) bool {
var result bool
var hasUnevaluable bool
sql.Inspect(e, func(e sql.Expression) bool {
if _, ok := e.(*expression.BindVar); ok {
result = true
switch e.(type) {
case *expression.GetField, *expression.UnresolvedColumn,
*plan.Subquery,
*expression.BindVar,
*expression.ProcedureParam:
hasUnevaluable = true
return false
default:
return true
}
return true
})
return result
}

func containsProcedureParam(e sql.Expression) bool {
var result bool
sql.Inspect(e, func(e sql.Expression) bool {
_, result = e.(*expression.ProcedureParam)
return !result
})
return result
return !hasUnevaluable
}
10 changes: 2 additions & 8 deletions sql/analyzer/costed_index_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ func (c *indexCoster) flattenAnd(e *expression.And, and *iScanAnd) (sql.FastIntS
invalid.Add(int(newOr.Id()))
} else {
and.orChildren = append(and.orChildren, newOr)
and.cnt++
if imp {
imprecise.Add(int(newOr.id))
}
Expand Down Expand Up @@ -1243,6 +1244,7 @@ func (a *iScanAnd) newLeaf(l *iScanLeaf) {
a.leafChildren = make(map[string][]*iScanLeaf)
}
a.leafChildren[strings.ToLower(l.gf.Name())] = append(a.leafChildren[strings.ToLower(l.gf.Name())], l)
a.cnt++
}

// leaves returns a list of this nodes leaf filters, sorted by id
Expand All @@ -1260,14 +1262,6 @@ func (a *iScanAnd) leaves() []*iScanLeaf {
}

func (a *iScanAnd) childCnt() int {
if a.cnt > 0 {
return a.cnt
}
cnt := len(a.orChildren)
for _, leaves := range a.leafChildren {
cnt += len(leaves)
}
a.cnt = cnt
return a.cnt
}

Expand Down
4 changes: 1 addition & 3 deletions sql/expression/function/aggregation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package aggregation

import (
"fmt"

"gopkg.in/src-d/go-errors.v1"

"github.com/dolthub/go-mysql-server/sql"
Expand Down Expand Up @@ -59,7 +57,7 @@ func (a *unaryAggBase) Window() *sql.WindowDefinition {
}

func (a *unaryAggBase) String() string {
return fmt.Sprintf("%s(%s)", a.functionName, a.Child)
return a.functionName + "(" + a.Child.String() + ")"
}

func (a *unaryAggBase) Type() sql.Type {
Expand Down
32 changes: 16 additions & 16 deletions sql/expression/function/aggregation/unary_aggs.og.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions sql/index_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,19 @@ func (b *MySQLIndexBuilder) In(ctx *Context, colExpr string, keyTypes []Type, ke
for i, k := range keys {
// if converting from float to int results in rounding, then it's empty range
if t, ok := colTyp.(NumberType); ok && t.IsNumericType() && !t.IsFloat() {
f, c := floor(k), ceil(k)
switch k.(type) {
case float32, float64:
if f != c {
switch k := k.(type) {
case float32:
if float32(int64(k)) != k {
potentialRanges[i] = EmptyRangeColumnExpr(colTyp)
continue
}
case float64:
if float64(int64(k)) != k {
potentialRanges[i] = EmptyRangeColumnExpr(colTyp)
continue
}
case decimal.Decimal:
if !f.(decimal.Decimal).Equals(c.(decimal.Decimal)) {
if !k.Equal(decimal.NewFromInt(k.IntPart())) {
potentialRanges[i] = EmptyRangeColumnExpr(colTyp)
continue
}
Expand Down Expand Up @@ -246,15 +250,19 @@ func (b *MySQLIndexBuilder) NotEquals(ctx *Context, colExpr string, keyType Type
return b
}
// if converting from float to int results in rounding, then it's entire range (excluding nulls)
f, c := floor(key), ceil(key)
switch key.(type) {
case float32, float64:
if f != c {
switch k := key.(type) {
case float32:
if float32(int64(k)) != k {
b.updateCol(ctx, colExpr, NotNullRangeColumnExpr(colTyp))
return b
}
case float64:
if float64(int64(k)) != k {
b.updateCol(ctx, colExpr, NotNullRangeColumnExpr(colTyp))
return b
}
case decimal.Decimal:
if !f.(decimal.Decimal).Equals(c.(decimal.Decimal)) {
if !k.Equal(decimal.NewFromInt(k.IntPart())) {
b.updateCol(ctx, colExpr, NotNullRangeColumnExpr(colTyp))
return b
}
Expand Down
2 changes: 1 addition & 1 deletion sql/planbuilder/orderby.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (b *Builder) normalizeValArg(e *ast.SQLVal) (sql.Expression, bool) {

func (b *Builder) normalizeIntVal(e *ast.SQLVal) (any, bool) {
if e.Type == ast.IntVal {
lit := b.convertInt(string(e.Val), 10)
lit := b.convertInt(e.Val, 10)
return lit.Value(), true
} else if replace, ok := b.normalizeValArg(e); ok {
if lit, ok := replace.(*expression.Literal); ok && types.IsNumber(lit.Type()) {
Expand Down
Loading
Loading