github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_compare_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  	"testing"
    18  
    19  	. "github.com/whtcorpsinc/check"
    20  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    21  	"github.com/whtcorpsinc/BerolinaSQL/allegrosql"
    22  	"github.com/whtcorpsinc/milevadb/types"
    23  )
    24  
    25  var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
    26  	ast.NE: {
    27  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
    28  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    29  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    30  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    31  			},
    32  		},
    33  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    34  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong},
    35  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    36  			},
    37  		},
    38  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    39  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    40  				{Tp: allegrosql.TypeLonglong},
    41  			},
    42  		},
    43  	},
    44  	ast.IsNull: {},
    45  	ast.LE: {
    46  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
    47  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    48  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    49  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    50  			},
    51  		},
    52  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    53  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong},
    54  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    55  			},
    56  		},
    57  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    58  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    59  				{Tp: allegrosql.TypeLonglong},
    60  			},
    61  		},
    62  	},
    63  	ast.LT: {
    64  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
    65  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    66  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    67  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    68  			},
    69  		},
    70  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    71  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong},
    72  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    73  			},
    74  		},
    75  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    76  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    77  				{Tp: allegrosql.TypeLonglong},
    78  			},
    79  		},
    80  	},
    81  	ast.Coalesce: {},
    82  	ast.NullEQ: {
    83  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
    84  	},
    85  	ast.GT: {
    86  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
    87  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    88  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    89  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    90  			},
    91  		},
    92  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    93  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong},
    94  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    95  			},
    96  		},
    97  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
    98  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
    99  				{Tp: allegrosql.TypeLonglong},
   100  			},
   101  		},
   102  	},
   103  	ast.EQ: {},
   104  	ast.GE: {
   105  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
   106  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
   107  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
   108  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
   109  			},
   110  		},
   111  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
   112  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong},
   113  				{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
   114  			},
   115  		},
   116  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
   117  			childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag},
   118  				{Tp: allegrosql.TypeLonglong},
   119  			},
   120  		},
   121  	},
   122  	ast.Date: {},
   123  	ast.Greatest: {
   124  		{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}},
   125  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}},
   126  		{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal}},
   127  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
   128  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}},
   129  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime}},
   130  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime, types.ETDatetime}},
   131  	},
   132  	ast.Least: {
   133  		{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}},
   134  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}},
   135  		{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal}},
   136  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
   137  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime, types.ETDatetime}},
   138  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}},
   139  	},
   140  	ast.Interval: {
   141  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 10, 0)}},
   142  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 10, 0), newRangeRealGener(10, 20, 0)}},
   143  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 10, 0), newRangeRealGener(10, 20, 0), newRangeRealGener(20, 30, 0)}},
   144  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
   145  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}},
   146  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(0, 10), newRangeInt64Gener(10, 20)}},
   147  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt, types.ETInt}},
   148  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(0, 10), newRangeInt64Gener(10, 20), newRangeInt64Gener(20, 30)}},
   149  	},
   150  }
   151  
   152  func (s *testEvaluatorSuite) TestVectorizedBuiltinCompareEvalOneVec(c *C) {
   153  	testVectorizedEvalOneVec(c, vecBuiltinCompareCases)
   154  }
   155  
   156  func (s *testEvaluatorSuite) TestVectorizedBuiltinCompareFunc(c *C) {
   157  	testVectorizedBuiltinFunc(c, vecBuiltinCompareCases)
   158  }
   159  
   160  func BenchmarkVectorizedBuiltinCompareEvalOneVec(b *testing.B) {
   161  	benchmarkVectorizedEvalOneVec(b, vecBuiltinCompareCases)
   162  }
   163  
   164  func BenchmarkVectorizedBuiltinCompareFunc(b *testing.B) {
   165  	benchmarkVectorizedBuiltinFunc(b, vecBuiltinCompareCases)
   166  }