diff --git a/evaluator/builtin_time.go b/evaluator/builtin_time.go index baacb77d05..b28778191f 100644 --- a/evaluator/builtin_time.go +++ b/evaluator/builtin_time.go @@ -184,7 +184,7 @@ func builtinNow(args []types.Datum, _ context.Context) (d types.Datum, err error d.SetNull() return d, errors.Trace(err) } - d.SetMysqlTime(&tr) + d.SetMysqlTime(tr) return d, nil } @@ -373,7 +373,7 @@ func builtinCurrentDate(args []types.Datum, _ context.Context) (d types.Datum, e t := mysql.Time{ Time: time.Date(year, month, day, 0, 0, 0, 0, time.Local), Type: mysql.TypeDate, Fsp: 0} - d.SetMysqlTime(&t) + d.SetMysqlTime(t) return d, nil } diff --git a/mysql/time.go b/mysql/time.go index 678a5bc34f..7f98199415 100644 --- a/mysql/time.go +++ b/mysql/time.go @@ -280,10 +280,7 @@ func (t Time) ConvertToDuration() (Duration, error) { // Compare returns an integer comparing the time instant t to o. // If t is after o, return 1, equal o, return 0, before o, return -1. -func (t *Time) Compare(o *Time) int { - if o == nil { - return 1 - } +func (t Time) Compare(o Time) int { if t.Time.After(o.Time) { return 1 } else if t.Time.Equal(o.Time) { @@ -302,7 +299,7 @@ func (t Time) CompareString(str string) (int, error) { return 0, errors.Trace(err) } - return t.Compare(&o), nil + return t.Compare(o), nil } // RoundFrac rounds fractional seconds precision with new fsp and returns a new one. @@ -1030,10 +1027,7 @@ func checkTimestamp(t Time) bool { } // ExtractTimeNum extracts time value number from time unit and format. -func ExtractTimeNum(unit string, t *Time) (int64, error) { - if t == nil { - return 0, errors.Errorf("invalid time t") - } +func ExtractTimeNum(unit string, t Time) (int64, error) { switch strings.ToUpper(unit) { case "MICROSECOND": return int64(t.Nanosecond() / 1000), nil diff --git a/tidb-server/server/util.go b/tidb-server/server/util.go index c143f48bf3..4d6c76d3d7 100644 --- a/tidb-server/server/util.go +++ b/tidb-server/server/util.go @@ -293,7 +293,7 @@ func dumpRowValuesBinary(alloc arena.Allocator, columns []*ColumnInfo, row []typ case types.KindMysqlDecimal: data = append(data, dumpLengthEncodedString(hack.Slice(val.GetMysqlDecimal().String()), alloc)...) case types.KindMysqlTime: - data = append(data, dumpBinaryDateTime(*val.GetMysqlTime(), nil)...) + data = append(data, dumpBinaryDateTime(val.GetMysqlTime(), nil)...) case types.KindMysqlDuration: data = append(data, dumpBinaryTime(val.GetMysqlDuration().Duration)...) case types.KindMysqlSet: diff --git a/util/types/datum.go b/util/types/datum.go index 5d46aa2c2a..ebdd2d4df7 100644 --- a/util/types/datum.go +++ b/util/types/datum.go @@ -244,12 +244,12 @@ func (d *Datum) SetMysqlSet(b mysql.Set) { } // GetMysqlTime gets mysql.Time value -func (d *Datum) GetMysqlTime() *mysql.Time { - return d.x.(*mysql.Time) +func (d *Datum) GetMysqlTime() mysql.Time { + return d.x.(mysql.Time) } // SetMysqlTime sets mysql.Time value -func (d *Datum) SetMysqlTime(b *mysql.Time) { +func (d *Datum) SetMysqlTime(b mysql.Time) { d.k = KindMysqlTime d.x = b } @@ -282,7 +282,7 @@ func (d *Datum) GetValue() interface{} { case KindMysqlSet: return d.GetMysqlSet() case KindMysqlTime: - return *d.GetMysqlTime() + return d.GetMysqlTime() default: return d.GetInterface() } @@ -325,10 +325,8 @@ func (d *Datum) SetValue(val interface{}) { d.SetMysqlHex(x) case mysql.Set: d.SetMysqlSet(x) - case *mysql.Time: - d.SetMysqlTime(x) case mysql.Time: - d.SetMysqlTime(&x) + d.SetMysqlTime(x) case []Datum: d.SetRow(x) case []interface{}: @@ -477,7 +475,7 @@ func (d *Datum) compareString(s string) (int, error) { return d.GetMysqlDecimal().Cmp(dec), err case KindMysqlTime: dt, err := mysql.ParseDatetime(s) - return d.GetMysqlTime().Compare(&dt), err + return d.GetMysqlTime().Compare(dt), err case KindMysqlDuration: dur, err := mysql.ParseDuration(s, mysql.MaxFsp) return d.GetMysqlDuration().Compare(dur), err @@ -563,10 +561,7 @@ func (d *Datum) compareMysqlSet(set mysql.Set) (int, error) { } } -func (d *Datum) compareMysqlTime(time *mysql.Time) (int, error) { - if time == nil { - return 0, errors.Errorf("invalid time t") - } +func (d *Datum) compareMysqlTime(time mysql.Time) (int, error) { switch d.k { case KindString, KindBytes: dt, err := mysql.ParseDatetime(d.GetString()) diff --git a/xapi/tablecodec/tablecodec.go b/xapi/tablecodec/tablecodec.go index 0a64901436..5421bb17ee 100644 --- a/xapi/tablecodec/tablecodec.go +++ b/xapi/tablecodec/tablecodec.go @@ -128,7 +128,7 @@ func unflatten(datum types.Datum, ft *types.FieldType) (types.Datum, error) { if err != nil { return datum, errors.Trace(err) } - datum.SetMysqlTime(&t) + datum.SetMysqlTime(t) return datum, nil case mysql.TypeDuration: dur := mysql.Duration{Duration: time.Duration(datum.GetInt64())}