github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_info_vec_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package memex
    15  
    16  import (
    17  	"encoding/hex"
    18  	"math/rand"
    19  	"testing"
    20  
    21  	"github.com/whtcorpsinc/BerolinaSQL/allegrosql"
    22  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    23  	. "github.com/whtcorpsinc/check"
    24  	"github.com/whtcorpsinc/milevadb/blockcodec"
    25  	"github.com/whtcorpsinc/milevadb/ekv"
    26  	"github.com/whtcorpsinc/milevadb/types"
    27  )
    28  
    29  type milevadbKeyGener struct {
    30  	inner *defaultGener
    31  }
    32  
    33  func (g *milevadbKeyGener) gen() interface{} {
    34  	blockID := g.inner.gen().(int64)
    35  	var result []byte
    36  	if rand.Intn(2) == 1 {
    37  		// Generate a record key
    38  		handle := g.inner.gen().(int64)
    39  		result = blockcodec.EncodeEventKeyWithHandle(blockID, ekv.IntHandle(handle))
    40  	} else {
    41  		// Generate an index key
    42  		idx := g.inner.gen().(int64)
    43  		result = blockcodec.EncodeBlockIndexPrefix(blockID, idx)
    44  	}
    45  	return hex.EncodeToString(result)
    46  }
    47  
    48  var vecBuiltinInfoCases = map[string][]vecExprBenchCase{
    49  	ast.Version: {
    50  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    51  	},
    52  	ast.MilevaDBVersion: {
    53  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    54  	},
    55  	ast.CurrentUser: {
    56  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    57  	},
    58  	ast.FoundEvents: {
    59  		{retEvalType: types.ETInt},
    60  	},
    61  	ast.Database: {
    62  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    63  	},
    64  	ast.User: {
    65  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    66  	},
    67  	ast.MilevaDBDecodeKey: {
    68  		{
    69  			retEvalType:   types.ETString,
    70  			childrenTypes: []types.EvalType{types.ETString},
    71  			geners: []dataGenerator{&milevadbKeyGener{
    72  				inner: newDefaultGener(0, types.ETInt),
    73  			}},
    74  		},
    75  	},
    76  	ast.EventCount: {
    77  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
    78  	},
    79  	ast.CurrentRole: {
    80  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{}},
    81  	},
    82  	ast.MilevaDBIsDBSTenant: {
    83  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
    84  	},
    85  	ast.ConnectionID: {
    86  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
    87  	},
    88  	ast.LastInsertId: {
    89  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{}},
    90  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
    91  	},
    92  	ast.Benchmark: {
    93  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    94  			constants: []*Constant{{Value: types.NewIntCauset(10), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
    95  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETReal},
    96  			constants: []*Constant{{Value: types.NewIntCauset(11), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
    97  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETDecimal},
    98  			constants: []*Constant{{Value: types.NewIntCauset(12), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
    99  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETString},
   100  			constants: []*Constant{{Value: types.NewIntCauset(13), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
   101  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETDatetime},
   102  			constants: []*Constant{{Value: types.NewIntCauset(14), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
   103  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETTimestamp},
   104  			constants: []*Constant{{Value: types.NewIntCauset(15), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
   105  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETDuration},
   106  			constants: []*Constant{{Value: types.NewIntCauset(16), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
   107  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETJson},
   108  			constants: []*Constant{{Value: types.NewIntCauset(17), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil}},
   109  	},
   110  }
   111  
   112  func (s *testEvaluatorSuite) TestVectorizedBuiltinInfoFunc(c *C) {
   113  	testVectorizedBuiltinFunc(c, vecBuiltinInfoCases)
   114  }
   115  
   116  func BenchmarkVectorizedBuiltinInfoFunc(b *testing.B) {
   117  	benchmarkVectorizedBuiltinFunc(b, vecBuiltinInfoCases)
   118  }