Skip to content

Commit

Permalink
expression: NOW() should be folded in constant folding stage (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Aug 31, 2017
1 parent 19a13de commit 9ae2639
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 2 additions & 5 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ type builtinFunc interface {
// getArgs returns the arguments expressions.
getArgs() []Expression
// isDeterministic checks if a function is deterministic.
// A function is deterministic if it returns same results for same inputs.
// e.g. random is non-deterministic.
// A function is deterministic if it returns the same result whenever it's called with the same inputs.
// e.g. SUBSTR, CONCAT is deterministic, but RANDOM, SYSDATE is not.
isDeterministic() bool
// equal check if this function equals to another function.
equal(builtinFunc) bool
Expand Down Expand Up @@ -695,9 +695,6 @@ type functionClass interface {
getFunction(args []Expression, ctx context.Context) (builtinFunc, error)
}

// BuiltinFunc is the function signature for builtin functions
type BuiltinFunc func([]types.Datum, context.Context) (types.Datum, error)

// funcs holds all registered builtin functions.
var funcs = map[string]functionClass{
// common functions
Expand Down
1 change: 0 additions & 1 deletion expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,6 @@ func (c *nowFunctionClass) getFunction(args []Expression, ctx context.Context) (
} else {
bf.tp.Flen, bf.tp.Decimal = 19, 0
}
bf.deterministic = false

var sig builtinFunc
if len(args) == 1 {
Expand Down
8 changes: 6 additions & 2 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
return tt
}

for _, x := range []struct {
for i, x := range []struct {
fc functionClass
now func() time.Time
}{
Expand All @@ -689,7 +689,11 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
} {
f, err := x.fc.getFunction(datumsToConstants(nil), s.ctx)
c.Assert(err, IsNil)
c.Assert(f.isDeterministic(), IsFalse)
if i == 0 {
c.Assert(f.isDeterministic(), IsTrue)
} else {
c.Assert(f.isDeterministic(), IsFalse)
}
v, err := f.eval(nil)
ts := x.now()
c.Assert(err, IsNil)
Expand Down

0 comments on commit 9ae2639

Please sign in to comment.