Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: implement vectorized evaluation for builtinCurrentRoleSig #13352

Merged
merged 4 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions expression/builtin_info_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package expression

import (
"sort"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -103,11 +106,37 @@ func (b *builtinCurrentUserSig) vecEvalString(input *chunk.Chunk, result *chunk.
}

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

// evalString evals a builtinCurrentUserSig.
// See https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_current-user
func (b *builtinCurrentRoleSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()

data := b.ctx.GetSessionVars()
if data == nil || data.ActiveRoles == nil {
return errors.Errorf("Missing session variable when eval builtin")
}

result.ReserveString(n)
if len(data.ActiveRoles) == 0 {
for i := 0; i < n; i++ {
result.AppendString("")
}
return nil
}

sortedRes := make([]string, 0, 10)
for _, r := range data.ActiveRoles {
sortedRes = append(sortedRes, r.String())
}
sort.Strings(sortedRes)
res := strings.Join(sortedRes, ",")
for i := 0; i < n; i++ {
result.AppendString(res)
}
return nil
}

func (b *builtinUserSig) vectorized() bool {
Expand Down
4 changes: 3 additions & 1 deletion expression/builtin_info_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ var vecBuiltinInfoCases = map[string][]vecExprBenchCase{
ast.RowCount: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
},
ast.CurrentRole: {},
ast.CurrentRole: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
},
ast.TiDBIsDDLOwner: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
},
Expand Down