Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/sql/schemachanger/rel/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ func compareNotNil(a, b interface{}) (less, eq bool) {
return true, false
}
return false, *a == *b
case *bool:
b := b.(*bool)
// false < true
if !*a && *b {
return true, false
}
return false, *a == *b
case reflect.Type:
return compareTypes(a, b.(reflect.Type))

Expand Down Expand Up @@ -138,8 +145,9 @@ var (
}

kindTypeMap = func() kindMap {
m := make(kindMap, len(intKindMap)+len(uintKindMap)+1)
m := make(kindMap, len(intKindMap)+len(uintKindMap)+2)
m[reflect.String] = reflect.TypeOf((*string)(nil)).Elem()
m[reflect.Bool] = reflect.TypeOf((*bool)(nil)).Elem()
for _, src := range []kindMap{uintKindMap, intKindMap} {
for k, t := range src {
m[k] = t
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/schemachanger/rel/database_entity_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (t *entitySet) insert(v interface{}, es entityStore) (int, error) {
if !ok {
continue
}
case field.isBool():
var ok bool
val, ok = field.inline(vp)
if !ok {
continue
}
case field.isString():
s, ok := field.comparableValue(vp).(*string)
if !ok {
Expand Down
25 changes: 23 additions & 2 deletions pkg/sql/schemachanger/rel/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ type fieldInfo struct {
type fieldFlags int8

func (f fieldFlags) isPtr() bool { return f&pointerField != 0 }
func (f fieldFlags) isScalar() bool { return f&(intField|stringField|uintField) != 0 }
func (f fieldFlags) isScalar() bool { return f&(intField|stringField|uintField|boolField) != 0 }
func (f fieldFlags) isStruct() bool { return f&structField != 0 }
func (f fieldFlags) isInt() bool { return f&intField != 0 }
func (f fieldFlags) isUint() bool { return f&uintField != 0 }
func (f fieldFlags) isIntLike() bool { return f&(intField|uintField) != 0 }
func (f fieldFlags) isString() bool { return f&stringField != 0 }
func (f fieldFlags) isBool() bool { return f&boolField != 0 }
func (f fieldFlags) isSlice() bool { return f&sliceField != 0 }

const (
intField fieldFlags = 1 << iota
uintField
stringField
boolField
structField
pointerField
sliceField
Expand Down Expand Up @@ -189,7 +191,17 @@ func checkType(typ, exp reflect.Type) error {
return errors.Errorf("%v does not implement %v", typ, exp)
}
default:
if typ != exp {
// For scalar kinds (int, uint, string, bool), compare by the
// comparable base type rather than the named type. This allows
// different named types of the same kind (e.g. Function_Volatility
// and Function_NullInputBehavior, both int32) to share a single
// attribute. The rel system already normalizes values to their base
// kind type for storage and comparison.
if _, ok := kindTypeMap[typ.Kind()]; ok {
if getComparableType(typ) != getComparableType(exp) {
return errors.Errorf("%v is not %v", typ, exp)
}
} else if typ != exp {
return errors.Errorf("%v is not %v", typ, exp)
}
}
Expand Down Expand Up @@ -254,6 +266,8 @@ func makeFieldFlags(t reflect.Type) (fieldFlags, bool) {
f |= structField
case kind == reflect.String:
f |= stringField
case kind == reflect.Bool:
f |= boolField
case isIntKind(kind):
f |= intField
case isUintKind(kind):
Expand Down Expand Up @@ -406,6 +420,13 @@ func (sb *schemaBuilder) addTypeAttrMapping(
}
return uintptr(got.Elem().Elem().Uint()), true
}
case f.isBool():
f.inline = func(u unsafe.Pointer) (uintptr, bool) {
if vg(u).Elem().Bool() {
return 1, true
}
return 0, true
}
case f.isInt():
f.inline = func(u unsafe.Pointer) (uintptr, bool) {
return uintptr(vg(u).Elem().Int()), true
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/schemachanger/rel/schema_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func makeComparableValue(val interface{}) (typedValue, error) {
typ: vv.Type(),
value: vvNew.Convert(reflect.PointerTo(compType)).Interface(),
}, nil
case typ.Kind() == reflect.Bool:
compType := getComparableType(typ)
vvNew := reflect.New(vv.Type())
vvNew.Elem().Set(vv)
return typedValue{
typ: vv.Type(),
value: vvNew.Convert(reflect.PointerTo(compType)).Interface(),
}, nil
case typ.Kind() == reflect.Ptr:
switch {
case isIntKind(typ.Elem().Kind()), isUintKind(typ.Elem().Kind()):
Expand All @@ -46,6 +54,12 @@ func makeComparableValue(val interface{}) (typedValue, error) {
typ: vv.Type().Elem(),
value: vv.Convert(reflect.PointerTo(compType)).Interface(),
}, nil
case typ.Elem().Kind() == reflect.Bool:
compType := getComparableType(typ.Elem())
return typedValue{
typ: vv.Type().Elem(),
value: vv.Convert(reflect.PointerTo(compType)).Interface(),
}, nil
case typ.Elem().Kind() == reflect.Struct:
return typedValue{
typ: vv.Type(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ go_library(
"//pkg/sql/catalog/colinfo",
"//pkg/sql/catalog/descpb",
"//pkg/sql/catalog/fetchpb",
"//pkg/sql/catalog/funcdesc",
"//pkg/sql/catalog/funcinfo",
"//pkg/sql/catalog/multiregion",
"//pkg/sql/catalog/schemadesc",
Expand Down
Loading
Loading