Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinCurren… (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin authored and zz-jason committed Oct 14, 2019
1 parent 542ba12 commit ad72829
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ CHECK_LDFLAGS += $(LDFLAGS) ${TEST_LDFLAGS}

TARGET = ""

# VB = Vector Benchmark
VB_FILE =
VB_FUNC =


.PHONY: all build update clean todo test gotest interpreter server dev benchkv benchraw check checklist parser tidy ddltest

default: server buildsucc
Expand Down Expand Up @@ -266,3 +271,13 @@ tools/bin/misspell:tools/check/go.mod
tools/bin/ineffassign:tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/ineffassign github.com/gordonklaus/ineffassign

# Usage:
#
# $ make vectorized-bench VB_FILE=Time VB_FUNC=builtinCurrentDateSig
vectorized-bench:
cd ./expression && \
go test -v -benchmem \
-bench=BenchmarkVectorizedBuiltin$(VB_FILE)Func \
-run=BenchmarkVectorizedBuiltin$(VB_FILE)Func \
-args "$(VB_FUNC)"
18 changes: 16 additions & 2 deletions expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,25 @@ func getColumnLen(col *chunk.Column, eType types.EvalType) int {
return chk.NumRows()
}

// removeTestOptions removes all not needed options like '-test.timeout=' from argument list
func removeTestOptions(args []string) []string {
argList := args[:0]

// args contains '-test.timeout=' option for example
// excluding it to be able to run all tests
for _, arg := range args {
if strings.HasPrefix(arg, "builtin") {
argList = append(argList, arg)
}
}
return argList
}

// testVectorizedBuiltinFunc is used to verify that the vectorized
// expression is evaluated correctly
func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) {
testFunc := make(map[string]bool)
argList := flag.Args()
argList := removeTestOptions(flag.Args())
testAll := len(argList) == 0
for _, arg := range argList {
testFunc[arg] = true
Expand Down Expand Up @@ -862,7 +876,7 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) {
func benchmarkVectorizedBuiltinFunc(b *testing.B, vecExprCases vecExprBenchCases) {
ctx := mock.NewContext()
testFunc := make(map[string]bool)
argList := flag.Args()
argList := removeTestOptions(flag.Args())
testAll := len(argList) == 0
for _, arg := range argList {
testFunc[arg] = true
Expand Down
22 changes: 20 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,29 @@ func (b *builtinDateDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column
}

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

func (b *builtinCurrentDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
nowTs, err := getStmtTimestamp(b.ctx)
if err != nil {
return err
}

tz := b.ctx.GetSessionVars().Location()
year, month, day := nowTs.In(tz).Date()
timeValue := types.Time{
Time: types.FromDate(year, int(month), day, 0, 0, 0, 0),
Type: mysql.TypeDate,
Fsp: 0}

n := input.NumRows()
result.ResizeTime(n, false)
times := result.Times()
for i := 0; i < n; i++ {
times[i] = timeValue
}
return nil
}

func (b *builtinAddDateStringStringSig) vectorized() bool {
Expand Down
14 changes: 8 additions & 6 deletions expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.DayOfYear: {},
ast.Day: {},
ast.CurrentTime: {},
ast.CurrentDate: {},
ast.MakeDate: {},
ast.MakeTime: {},
ast.PeriodAdd: {},
ast.PeriodDiff: {},
ast.Quarter: {},
ast.CurrentDate: {
{retEvalType: types.ETDatetime},
},
ast.MakeDate: {},
ast.MakeTime: {},
ast.PeriodAdd: {},
ast.PeriodDiff: {},
ast.Quarter: {},
ast.TimeFormat: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDuration, types.ETString}, geners: []dataGenerator{&rangeDurationGener{0.5}, &timeFormatGener{0.5}}},
},
Expand Down

0 comments on commit ad72829

Please sign in to comment.