github.com/matrixorigin/matrixone@v0.7.0/pkg/common/hashmap/joinmap.go (about) 1 // Copyright 2021 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 hashmap 16 17 import ( 18 "sync/atomic" 19 20 "github.com/matrixorigin/matrixone/pkg/container/index" 21 "github.com/matrixorigin/matrixone/pkg/pb/plan" 22 ) 23 24 func NewJoinMap(sels [][]int32, expr *plan.Expr, mp *StrHashMap, hasNull bool, idx *index.LowCardinalityIndex) *JoinMap { 25 cnt := int64(1) 26 return &JoinMap{ 27 cnt: &cnt, 28 mp: mp, 29 expr: expr, 30 sels: sels, 31 hasNull: hasNull, 32 idx: idx, 33 } 34 } 35 36 func (jm *JoinMap) Sels() [][]int32 { 37 return jm.sels 38 } 39 40 func (jm *JoinMap) Map() *StrHashMap { 41 return jm.mp 42 } 43 44 func (jm *JoinMap) Expr() *plan.Expr { 45 return jm.expr 46 } 47 48 func (jm *JoinMap) HasNull() bool { 49 return jm.hasNull 50 } 51 52 func (jm *JoinMap) Index() *index.LowCardinalityIndex { 53 return jm.idx 54 } 55 56 func (jm *JoinMap) Dup() *JoinMap { 57 m0 := &StrHashMap{ 58 m: jm.mp.m, 59 hashMap: jm.mp.hashMap, 60 hasNull: jm.mp.hasNull, 61 ibucket: jm.mp.ibucket, 62 nbucket: jm.mp.nbucket, 63 values: make([]uint64, UnitLimit), 64 zValues: make([]int64, UnitLimit), 65 keys: make([][]byte, UnitLimit), 66 strHashStates: make([][3]uint64, UnitLimit), 67 } 68 jm0 := &JoinMap{ 69 mp: m0, 70 expr: jm.expr, 71 sels: jm.sels, 72 hasNull: jm.hasNull, 73 cnt: jm.cnt, 74 idx: jm.idx, 75 } 76 if atomic.AddInt64(jm.dupCnt, -1) == 0 { 77 jm.mp = nil 78 jm.sels = nil 79 } 80 return jm0 81 } 82 83 func (jm *JoinMap) IncRef(ref int64) { 84 atomic.AddInt64(jm.cnt, ref) 85 } 86 87 func (jm *JoinMap) SetDupCount(ref int64) { 88 jm.dupCnt = new(int64) 89 atomic.AddInt64(jm.dupCnt, ref) 90 } 91 92 func (jm *JoinMap) Free() { 93 if atomic.AddInt64(jm.cnt, -1) != 0 { 94 return 95 } 96 for i := range jm.sels { 97 jm.sels[i] = nil 98 } 99 jm.sels = nil 100 jm.mp.Free() 101 } 102 103 func (jm *JoinMap) Size() int64 { 104 // TODO: add the size of the other JoinMap parts 105 if jm.mp == nil { 106 return 0 107 } 108 return jm.mp.Size() 109 }