github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/allegrosql/partition_prune.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 // // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 13 package embedded 14 15 import ( 16 "github.com/whtcorpsinc/BerolinaSQL/perceptron" 17 "github.com/whtcorpsinc/milevadb/causet" 18 "github.com/whtcorpsinc/milevadb/memex" 19 "github.com/whtcorpsinc/milevadb/stochastikctx" 20 "github.com/whtcorpsinc/milevadb/types" 21 ) 22 23 // PartitionPruning finds all used partitions according to query conditions, it will 24 // return nil if condition match none of partitions. The return value is a array of the 25 // idx in the partition definitions array, use pi.Definitions[idx] to get the partition ID 26 func PartitionPruning(ctx stochastikctx.Context, tbl causet.PartitionedBlock, conds []memex.Expression, partitionNames []perceptron.CIStr, 27 columns []*memex.DeferredCauset, names types.NameSlice) ([]int, error) { 28 s := partitionProcessor{} 29 pi := tbl.Meta().Partition 30 switch pi.Type { 31 case perceptron.PartitionTypeHash: 32 return s.pruneHashPartition(ctx, tbl, partitionNames, conds, columns, names) 33 case perceptron.PartitionTypeRange: 34 rangeOr, err := s.pruneRangePartition(ctx, pi, tbl, conds, columns, names) 35 if err != nil { 36 return nil, err 37 } 38 ret := s.convertToIntSlice(rangeOr, pi, partitionNames) 39 return ret, nil 40 } 41 return []int{FullRange}, nil 42 }