Skip to content

Commit c18029b

Browse files
craig[bot]mgartner
craig[bot]
andcommitted
Merge #110066
110066: sql/sem/tree: eliminate types.T allocations in collated string comparison r=mgartner a=mgartner #### sql/sem/tree: eliminate types.T allocations in collated string comparison This commit eliminates allocations of `types.T` in the `CompareError` method of `DCollatedString`. Instead of allocating a new collated string type and calling the `Equivalent` method on the type, `CompareError` simply checks that the locales of the collated string datums match. This matches the behavior of `Equivalent`. Epic: None Release note (performance improvement): Queries that compare collated strings now use less memory and may execute faster. #### sql/sem/types: more efficiently order UserDefinedTypeMetadata fields The order of fields of the `types.UserDefinedTypedMetadata` struct, which is embedded in `types.T`, has been changed to reduce padding required for word-alignment. The struct size has been reduced from 32 bytes to 24 bytes. Release note: None Co-authored-by: Marcus Gartner <[email protected]>
2 parents d1ea771 + 5607b80 commit c18029b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/sql/sem/tree/datum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ func (d *DCollatedString) CompareError(ctx CompareContext, other Datum) (int, er
14811481
return 1, nil
14821482
}
14831483
v, ok := ctx.UnwrapDatum(other).(*DCollatedString)
1484-
if !ok || !d.ResolvedType().Equivalent(other.ResolvedType()) {
1484+
if !ok || !lex.LocaleNamesAreEqual(d.Locale, v.Locale) {
14851485
return 0, makeUnsupportedComparisonMessage(d, other)
14861486
}
14871487
res := bytes.Compare(d.Key, v.Key)

pkg/sql/types/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ type UserDefinedTypeMetadata struct {
192192
// Name is the resolved name of this type.
193193
Name *UserDefinedTypeName
194194

195+
// EnumData is non-nil iff the metadata is for an ENUM type.
196+
EnumData *EnumMetadata
197+
195198
// Version is the descriptor version of the descriptor used to construct
196199
// this version of the type metadata.
197200
Version uint32
198201

199-
// EnumData is non-nil iff the metadata is for an ENUM type.
200-
EnumData *EnumMetadata
201-
202202
// ImplicitRecordType is true if the metadata is for an implicit record type
203203
// for a table. Note: this can be deleted if we migrate implicit record types
204204
// to ordinary persisted composite types.

0 commit comments

Comments
 (0)