@@ -81,17 +81,16 @@ func (ikr *InternalKeyBounds) Largest() InternalKey {
8181}
8282
8383func (ikr * InternalKeyBounds ) SetSmallest (ik InternalKey ) {
84- largest := ikr .Largest ()
85- ikr .userKeyData = string (ik .UserKey ) + string (largest .UserKey )
84+ ikr .userKeyData = string (ik .UserKey ) + string (ikr .LargestUserKey ())
8685 ikr .smallestTrailer = ik .Trailer
8786 ikr .userKeySeparatorIdx = len (ik .UserKey )
8887}
8988
9089func (ikr * InternalKeyBounds ) SetLargest (ik InternalKey ) {
91- smallest := ikr .Smallest ()
92- ikr .userKeyData = string (smallest . UserKey ) + string (ik .UserKey )
90+ smallestUserKey := ikr .SmallestUserKey ()
91+ ikr .userKeyData = string (smallestUserKey ) + string (ik .UserKey )
9392 ikr .largestTrailer = ik .Trailer
94- ikr .userKeySeparatorIdx = len (smallest . UserKey )
93+ ikr .userKeySeparatorIdx = len (smallestUserKey )
9594}
9695
9796// TableInfo contains the common information for table related events.
@@ -237,8 +236,8 @@ func (s CompactionState) String() string {
237236//
238237// When using these fields in the context of a Virtual Table, These fields
239238// have additional invariants imposed on them, and/or slightly varying meanings:
240- // - Smallest and Largest (and their counterparts
241- // {Smallest, Largest}{Point,Range}Key ) remain tight bounds that represent a
239+ // - boundTypeSmallest and boundTypeLargest (and their counterparts
240+ // {Point,Range}KeyBounds.{ Smallest() , Largest()} ) remain tight bounds that represent a
242241// key at that exact bound. We make the effort to determine the next smallest
243242// or largest key in an sstable after virtualizing it, to maintain this
244243// tightness. If the largest is a sentinel key (IsExclusiveSentinel()), it
@@ -323,7 +322,7 @@ type TableMetadata struct {
323322 // internal range keys stored in the table.
324323 // NB: these field should be set using ExtendRangeKeyBounds. They are left
325324 // exported for reads as an optimization.
326- RangeKeyBounds InternalKeyBounds
325+ RangeKeyBounds * InternalKeyBounds
327326 // BlobReferences is a list of blob files containing values that are
328327 // referenced by this sstable.
329328 BlobReferences BlobReferences
@@ -472,6 +471,9 @@ func (m *TableMetadata) UserKeyBoundsByType(keyType KeyType) base.UserKeyBounds
472471 case KeyTypePoint :
473472 return base .UserKeyBoundsFromInternal (m .PointKeyBounds .Smallest (), m .PointKeyBounds .Largest ())
474473 case KeyTypeRange :
474+ if ! m .HasRangeKeys {
475+ return base.UserKeyBounds {}
476+ }
475477 return base .UserKeyBoundsFromInternal (m .RangeKeyBounds .Smallest (), m .RangeKeyBounds .Largest ())
476478 default :
477479 return base .UserKeyBoundsFromInternal (m .Smallest (), m .Largest ())
@@ -723,6 +725,7 @@ func (m *TableMetadata) ExtendRangeKeyBounds(
723725) * TableMetadata {
724726 // Update the range key bounds.
725727 if ! m .HasRangeKeys {
728+ m .RangeKeyBounds = & InternalKeyBounds {}
726729 m .RangeKeyBounds .SetInternalKeyBounds (smallest , largest )
727730 m .HasRangeKeys = true
728731 } else {
@@ -795,11 +798,13 @@ func (m *TableMetadata) ContainsKeyType(kt KeyType) bool {
795798func (m * TableMetadata ) SmallestBound (kt KeyType ) (InternalKey , bool ) {
796799 switch kt {
797800 case KeyTypePointAndRange :
798- ik := m .Smallest ()
799- return ik , true
801+ return m .Smallest (), true
800802 case KeyTypePoint :
801803 return m .PointKeyBounds .Smallest (), m .HasPointKeys
802804 case KeyTypeRange :
805+ if ! m .HasRangeKeys {
806+ return InternalKey {}, m .HasRangeKeys
807+ }
803808 return m .RangeKeyBounds .Smallest (), m .HasRangeKeys
804809 default :
805810 panic ("unrecognized key type" )
@@ -817,6 +822,9 @@ func (m *TableMetadata) LargestBound(kt KeyType) (InternalKey, bool) {
817822 case KeyTypePoint :
818823 return m .PointKeyBounds .Largest (), m .HasPointKeys
819824 case KeyTypeRange :
825+ if ! m .HasRangeKeys {
826+ return InternalKey {}, m .HasRangeKeys
827+ }
820828 return m .RangeKeyBounds .Largest (), m .HasRangeKeys
821829 default :
822830 panic ("unrecognized key type" )
@@ -961,6 +969,7 @@ func ParseTableMetadataDebug(s string) (_ *TableMetadata, err error) {
961969 p .Expect ("]" )
962970
963971 case "ranges" :
972+ m .RangeKeyBounds = & InternalKeyBounds {}
964973 p .Expect ("[" )
965974 smallest := p .InternalKey ()
966975 p .Expect ("-" )
@@ -999,13 +1008,12 @@ func ParseTableMetadataDebug(s string) (_ *TableMetadata, err error) {
9991008 cmp := base .DefaultComparer .Compare
10001009 if base .InternalCompare (cmp , smallest , m .PointKeyBounds .Smallest ()) == 0 {
10011010 m .boundTypeSmallest = boundTypePointKey
1002-
1003- } else if base .InternalCompare (cmp , smallest , m .RangeKeyBounds .Smallest ()) == 0 {
1011+ } else if m .HasRangeKeys && base .InternalCompare (cmp , smallest , m .RangeKeyBounds .Smallest ()) == 0 {
10041012 m .boundTypeSmallest = boundTypeRangeKey
10051013 }
10061014 if base .InternalCompare (cmp , largest , m .PointKeyBounds .Largest ()) == 0 {
10071015 m .boundTypeLargest = boundTypePointKey
1008- } else if base .InternalCompare (cmp , largest , m .RangeKeyBounds .Largest ()) == 0 {
1016+ } else if m . HasRangeKeys && base .InternalCompare (cmp , largest , m .RangeKeyBounds .Largest ()) == 0 {
10091017 m .boundTypeLargest = boundTypeRangeKey
10101018 }
10111019
@@ -1192,6 +1200,9 @@ func (m *TableMetadata) Smallest() InternalKey {
11921200 case boundTypePointKey :
11931201 return m .PointKeyBounds .Smallest ()
11941202 case boundTypeRangeKey :
1203+ if ! m .HasRangeKeys {
1204+ return InternalKey {}
1205+ }
11951206 return m .RangeKeyBounds .Smallest ()
11961207 default :
11971208 return InternalKey {}
@@ -1205,6 +1216,9 @@ func (m *TableMetadata) Largest() InternalKey {
12051216 case boundTypePointKey :
12061217 return m .PointKeyBounds .Largest ()
12071218 case boundTypeRangeKey :
1219+ if ! m .HasRangeKeys {
1220+ return InternalKey {}
1221+ }
12081222 return m .RangeKeyBounds .Largest ()
12091223 default :
12101224 return InternalKey {}
0 commit comments