Skip to content

Commit 87b4c56

Browse files
authored
REP-6503 Avoid $type in partition queries unless needed (#129)
The $type checks that REP-6129 (PR #118) added to fix type bracketing have impeded performance against 4.4 clusters. This changeset makes partition queries use $type only when the range requires it, which should only be true for a handful of partitions anyhow. The queries are simplified, too, so that instead of ANDing together predicates like `_id >= 12 OR $type in ["string", "symbol", ...])` and `id <= 99 OR $type in ["null", "minkey"]` we just have a single $type invocation (if it’s even there, which it usually won’t be now). The existing checks for type-bracketing accommodation are expanded a bit here as well.
1 parent 1f1a5a1 commit 87b4c56

File tree

7 files changed

+572
-503
lines changed

7 files changed

+572
-503
lines changed

internal/partitions/bson.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ var bsonTypeString = map[bsontype.Type]string{
8585
// This returns BSON types that the server’s type bracketing excludes from
8686
// query results when matching against the given value.
8787
//
88-
// The returned slices are types before & after, respectively. They are
89-
// strings rather than bsontype.Type to facilitate easy insertion into queries.
88+
// The returned slices are types before & after, respectively. They require
89+
// transformation (e.g., via typesToStrings()) before insertion into queries.
9090
//
9191
// This is kind of like strings.Cut() but against the sort-ordered list of BSON
9292
// types, except that if the given value is a number or string-like, then other
9393
// “like” types will not be in the returned slices.
94-
func getTypeBracketExcludedBSONTypes(val any) ([]string, []string, error) {
94+
func getTypeBracketExcludedBSONTypes(val any) ([]bsontype.Type, []bsontype.Type, error) {
9595
bsonType, _, err := bson.MarshalValue(val)
9696
if err != nil {
9797
return nil, nil, errors.Wrapf(err, "marshaling min value (%v)", val)
@@ -120,7 +120,7 @@ func getTypeBracketExcludedBSONTypes(val any) ([]string, []string, error) {
120120
later = lo.Without(later, stringTypes...)
121121
}
122122

123-
return typesToStrings(earlier), typesToStrings(later), nil
123+
return earlier, later, nil
124124
}
125125

126126
func typesToStrings(in []bsontype.Type) []string {

0 commit comments

Comments
 (0)