Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinGreatestTimeS…
Browse files Browse the repository at this point in the history
…ig` (pingcap#12825)
  • Loading branch information
mmyj authored and qw4990 committed Nov 9, 2019
1 parent 8772717 commit 66a2412
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
47 changes: 45 additions & 2 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,54 @@ func vecCompareInt(isUnsigned0, isUnsigned1 bool, largs, rargs, result *chunk.Co
}

func (b *builtinGreatestTimeSig) vectorized() bool {
return false
return true
}

func (b *builtinGreatestTimeSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
dst, err := b.bufAllocator.get(types.ETTimestamp, n)
if err != nil {
return err
}
defer b.bufAllocator.put(dst)

sc := b.ctx.GetSessionVars().StmtCtx
dst.ResizeTime(n, false)
dstTimes := dst.Times()
for i := 0; i < n; i++ {
dstTimes[i] = types.ZeroDatetime
}
var argTime types.Time
for j := 0; j < len(b.args); j++ {
if err := b.args[j].VecEvalString(b.ctx, input, result); err != nil {
return err
}
for i := 0; i < n; i++ {
if result.IsNull(i) || dst.IsNull(i) {
dst.SetNull(i, true)
continue
}
argTime, err = types.ParseDatetime(sc, result.GetString(i))
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
continue
}
if argTime.Compare(dstTimes[i]) > 0 {
dstTimes[i] = argTime
}
}
}
result.ReserveString(n)
for i := 0; i < n; i++ {
if dst.IsNull(i) {
result.AppendNull()
} else {
result.AppendString(dstTimes[i].String())
}
}
return nil
}

func (b *builtinGreatestRealSig) vectorized() bool {
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime, types.ETDatetime}},
},
ast.Least: {
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}},
Expand Down

0 comments on commit 66a2412

Please sign in to comment.