@@ -46,10 +46,10 @@ func (ki KeyInfo) String() string {
46
46
// Schema stands for the row schema and unique key information get from input.
47
47
type Schema struct {
48
48
Columns []* Column
49
- Keys []KeyInfo
50
- // UniqueKeys stores those unique indexes that allow null values, but Keys does not allow null values.
51
- // since equivalence conditions can filter out null values, in this case a unique index with null values can be a Key.
52
- UniqueKeys []KeyInfo
49
+ PKOrUK []KeyInfo // this fields stores the primary key or unique key.
50
+ // NullableUK stores those unique indexes that allow null values, but PKOrUK does not allow null values.
51
+ // Since equivalence conditions can filter out null values, in this case a unique index with null values can be a Key.
52
+ NullableUK []KeyInfo
53
53
}
54
54
55
55
// String implements fmt.Stringer interface.
@@ -58,17 +58,17 @@ func (s *Schema) String() string {
58
58
for _ , col := range s .Columns {
59
59
colStrs = append (colStrs , col .String ())
60
60
}
61
- strs := make ([]string , 0 , len (s .Keys ))
62
- for _ , key := range s .Keys {
61
+ strs := make ([]string , 0 , len (s .PKOrUK ))
62
+ for _ , key := range s .PKOrUK {
63
63
strs = append (strs , key .String ())
64
64
}
65
- ukStrs := make ([]string , 0 , len (s .Keys ))
66
- for _ , key := range s .UniqueKeys {
65
+ ukStrs := make ([]string , 0 , len (s .PKOrUK ))
66
+ for _ , key := range s .NullableUK {
67
67
ukStrs = append (ukStrs , key .String ())
68
68
}
69
69
return "Column: [" + strings .Join (colStrs , "," ) +
70
- "] Key : [" + strings .Join (strs , "," ) +
71
- "] Unique key : [" + strings .Join (ukStrs , "," ) + "]"
70
+ "] PKOrUK : [" + strings .Join (strs , "," ) +
71
+ "] NullableUK : [" + strings .Join (ukStrs , "," ) + "]"
72
72
}
73
73
74
74
// Clone copies the total schema.
@@ -77,18 +77,18 @@ func (s *Schema) Clone() *Schema {
77
77
return nil
78
78
}
79
79
cols := make ([]* Column , 0 , s .Len ())
80
- keys := make ([]KeyInfo , 0 , len (s .Keys ))
80
+ keys := make ([]KeyInfo , 0 , len (s .PKOrUK ))
81
81
for _ , col := range s .Columns {
82
82
cols = append (cols , col .Clone ().(* Column ))
83
83
}
84
- for _ , key := range s .Keys {
84
+ for _ , key := range s .PKOrUK {
85
85
keys = append (keys , key .Clone ())
86
86
}
87
87
schema := NewSchema (cols ... )
88
88
schema .SetKeys (keys )
89
- if s .UniqueKeys != nil {
90
- uniqueKeys := make ([]KeyInfo , 0 , len (s .UniqueKeys ))
91
- for _ , key := range s .UniqueKeys {
89
+ if s .NullableUK != nil {
90
+ uniqueKeys := make ([]KeyInfo , 0 , len (s .NullableUK ))
91
+ for _ , key := range s .NullableUK {
92
92
uniqueKeys = append (uniqueKeys , key .Clone ())
93
93
}
94
94
schema .SetUniqueKeys (uniqueKeys )
@@ -145,9 +145,9 @@ func (s *Schema) RetrieveColumn(col *Column) *Column {
145
145
// Pass strong=true to check strong contraint: unique && notnull.
146
146
// Pass strong=false to check weak contraint: unique && nullable.
147
147
func (s * Schema ) IsUnique (strong bool , cols ... * Column ) bool {
148
- slicesToBeIterated := s .UniqueKeys
148
+ slicesToBeIterated := s .NullableUK
149
149
if strong {
150
- slicesToBeIterated = s .Keys
150
+ slicesToBeIterated = s .PKOrUK
151
151
}
152
152
for _ , key := range slicesToBeIterated {
153
153
if len (key ) > len (cols ) {
@@ -210,12 +210,12 @@ func (s *Schema) Append(col ...*Column) {
210
210
211
211
// SetKeys will set the value of Schema.Keys.
212
212
func (s * Schema ) SetKeys (keys []KeyInfo ) {
213
- s .Keys = keys
213
+ s .PKOrUK = keys
214
214
}
215
215
216
216
// SetUniqueKeys will set the value of Schema.UniqueKeys.
217
217
func (s * Schema ) SetUniqueKeys (keys []KeyInfo ) {
218
- s .UniqueKeys = keys
218
+ s .NullableUK = keys
219
219
}
220
220
221
221
// ColumnsIndices will return a slice which contains the position of each column in schema.
@@ -269,18 +269,18 @@ func (s *Schema) MemoryUsage() (sum int64) {
269
269
return
270
270
}
271
271
272
- sum = emptySchemaSize + int64 (cap (s .Columns ))* size .SizeOfPointer + int64 (cap (s .Keys )+ cap (s .UniqueKeys ))* size .SizeOfSlice
272
+ sum = emptySchemaSize + int64 (cap (s .Columns ))* size .SizeOfPointer + int64 (cap (s .PKOrUK )+ cap (s .NullableUK ))* size .SizeOfSlice
273
273
274
274
for _ , col := range s .Columns {
275
275
sum += col .MemoryUsage ()
276
276
}
277
- for _ , cols := range s .Keys {
277
+ for _ , cols := range s .PKOrUK {
278
278
sum += int64 (cap (cols )) * size .SizeOfPointer
279
279
for _ , col := range cols {
280
280
sum += col .MemoryUsage ()
281
281
}
282
282
}
283
- for _ , cols := range s .UniqueKeys {
283
+ for _ , cols := range s .NullableUK {
284
284
sum += int64 (cap (cols )) * size .SizeOfPointer
285
285
for _ , col := range cols {
286
286
sum += col .MemoryUsage ()
0 commit comments