From 1fa56cff16e5855ae4b5bdcecdfa47e96fde112f Mon Sep 17 00:00:00 2001 From: qw4990 Date: Wed, 8 May 2019 16:43:56 +0800 Subject: [PATCH] add comments --- expression/builtin_time.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 3f49ca53138d0..883cad23a64de 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -4734,6 +4734,7 @@ func (c *periodAddFunctionClass) getFunction(ctx sessionctx.Context, args []Expr return sig, nil } +// validPeriod checks if this period is valid, it comes from MySQL 8.0+. func validPeriod(p int64) bool { return !(p < 0 || p%100 == 0 || p%100 > 12) } @@ -4794,6 +4795,7 @@ func (b *builtinPeriodAddSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, true, err } + // in MySQL, if p is invalid but n is NULL, the result is NULL, so we have to check if n is NULL first. if !validPeriod(p) { return 0, false, errIncorrectArgs.GenWithStackByArgs("period_add") }