github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/ekv/checker.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 ekv
    15  
    16  import "github.com/whtcorpsinc/fidelpb/go-fidelpb"
    17  
    18  // RequestTypeSupportedChecker is used to check memex can be pushed down.
    19  type RequestTypeSupportedChecker struct{}
    20  
    21  // IsRequestTypeSupported checks whether reqType is supported.
    22  func (d RequestTypeSupportedChecker) IsRequestTypeSupported(reqType, subType int64) bool {
    23  	switch reqType {
    24  	case ReqTypeSelect, ReqTypeIndex:
    25  		switch subType {
    26  		case ReqSubTypeGroupBy, ReqSubTypeBasic, ReqSubTypeTopN:
    27  			return true
    28  		default:
    29  			return d.supportExpr(fidelpb.ExprType(subType))
    30  		}
    31  	case ReqTypePosetDag:
    32  		return d.supportExpr(fidelpb.ExprType(subType))
    33  	case ReqTypeAnalyze:
    34  		return true
    35  	}
    36  	return false
    37  }
    38  
    39  func (d RequestTypeSupportedChecker) supportExpr(exprType fidelpb.ExprType) bool {
    40  	switch exprType {
    41  	case fidelpb.ExprType_Null, fidelpb.ExprType_Int64, fidelpb.ExprType_Uint64, fidelpb.ExprType_String, fidelpb.ExprType_Bytes,
    42  		fidelpb.ExprType_MysqlDuration, fidelpb.ExprType_MysqlTime, fidelpb.ExprType_MysqlDecimal,
    43  		fidelpb.ExprType_Float32, fidelpb.ExprType_Float64, fidelpb.ExprType_DeferredCausetRef:
    44  		return true
    45  	// aggregate functions.
    46  	case fidelpb.ExprType_Count, fidelpb.ExprType_First, fidelpb.ExprType_Max, fidelpb.ExprType_Min, fidelpb.ExprType_Sum, fidelpb.ExprType_Avg,
    47  		fidelpb.ExprType_Agg_BitXor, fidelpb.ExprType_Agg_BitAnd, fidelpb.ExprType_Agg_BitOr, fidelpb.ExprType_ApproxCountDistinct:
    48  		return true
    49  	case ReqSubTypeDesc:
    50  		return true
    51  	case ReqSubTypeSignature:
    52  		return true
    53  	default:
    54  		return false
    55  	}
    56  }