github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/shuffle_algo.go (about) 1 // Copyright 2022 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import ( 18 pb "github.com/matrixorigin/matrixone/pkg/pb/statsinfo" 19 ) 20 21 func NewShuffleRange(isString bool) *pb.ShuffleRange { 22 return &pb.ShuffleRange{IsStrType: isString} 23 } 24 25 func ShuffleRangeReEvalUnsigned(ranges []float64, k2 int, nullCnt int64, tableCnt int64) []uint64 { 26 k1 := len(ranges) 27 if k2 > k1/2 { 28 return nil 29 } 30 result := make([]uint64, k2-1) 31 if tableCnt/int64(k2) <= nullCnt { 32 result[0] = uint64(ranges[0]) 33 for i := 1; i <= k2-2; i++ { 34 result[i] = uint64(ranges[(i)*(k1-1)/(k2-1)]) 35 } 36 } else { 37 for i := 0; i <= k2-2; i++ { 38 result[i] = uint64(ranges[(i+1)*k1/k2-1]) 39 } 40 } 41 return result 42 } 43 44 func ShuffleRangeReEvalSigned(ranges []float64, k2 int, nullCnt int64, tableCnt int64) []int64 { 45 k1 := len(ranges) 46 if k2 > k1/2 { 47 return nil 48 } 49 result := make([]int64, k2-1) 50 if tableCnt/int64(k2) <= nullCnt { 51 result[0] = int64(ranges[0]) 52 for i := 1; i <= k2-2; i++ { 53 result[i] = int64(ranges[(i)*(k1-1)/(k2-1)]) 54 } 55 } else { 56 for i := 0; i <= k2-2; i++ { 57 result[i] = int64(ranges[(i+1)*k1/k2-1]) 58 } 59 } 60 return result 61 }