Skip to content
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
27 changes: 10 additions & 17 deletions enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,20 @@ func TestSingleScript(t *testing.T) {
t.Skip()
var scripts = []queries.ScriptTest{
{
Name: "Parse table name as column",
Name: "test ranges",
SetUpScript: []string{
`CREATE TABLE test (pk INT PRIMARY KEY, v1 VARCHAR(255));`,
`INSERT INTO test VALUES (1, 'a'), (2, 'b');`,
"create table t (i int primary key);",
"insert into t values (1), (2), (3), (4), (5);",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT temporarytesting(t) FROM test AS t;",
Expected: []sql.Row{},
},
{
Query: "SELECT temporarytesting(test) FROM test;",
Expected: []sql.Row{},
},
{
Query: "SELECT temporarytesting(pk, test) FROM test;",
Expected: []sql.Row{},
},
{
Query: "SELECT temporarytesting(v1, test, pk) FROM test;",
Expected: []sql.Row{},
Query: "select * from t where i between 1 and 2 or i between 3 and 5;",
Expected: []sql.Row{
{1},
{2},
{3},
{4},
},
},
},
},
Expand Down
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
}
12 changes: 3 additions & 9 deletions sql/analyzer/costed_index_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ type indexCoster struct {
// bestStat is the lowest cardinality indexScan option
bestStat sql.Statistic
// idToExpr is a record of conj decomposition so we can remove duplicates later
idToExpr map[indexScanId]sql.Expression
idToExpr map[indexScanId]sql.Expression // TODO: there are quite a few map reassign and map grow
// bestFilters is the set of conjunctions used to create bestStat
bestFilters sql.FastIntSet
// bestConstant are the constant best filters
Expand Down 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
Loading
Loading