Skip to content

Commit

Permalink
tree: fix DatumPrev for collated string
Browse files Browse the repository at this point in the history
This commit removes the support of collated strings from `DatumPrev`. As
it turns out, the comparison of collated strings is done by comparing
their collation keys, and the current method of generating the previous
string (simply subtracting 1 from the last non-zero byte) doesn't work.
Similar bug in `DatumNext` was fixed in
1902d3d (which added the collated
strings into randomly generated types), but I didn't stress the test to
catch this bug. The impact of the bug is minor since it's only used in
`debut statement-bundle recreate` command.

Epic: None

Release note: None
  • Loading branch information
yuzefovich committed Feb 22, 2023
1 parent 58297f3 commit 7af77d4
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions pkg/sql/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -6144,16 +6144,6 @@ func DatumPrev(
return nil, false
}
return NewDString(prev), true
case *DCollatedString:
prev, ok := prevString(d.Contents)
if !ok {
return nil, false
}
c, err := NewDCollatedString(prev, d.Locale, collationEnv)
if err != nil {
return nil, false
}
return c, true
case *DBytes:
prev, ok := prevString(string(*d))
if !ok {
Expand All @@ -6166,8 +6156,8 @@ func DatumPrev(
return NewDInterval(prev, types.DefaultIntervalTypeMetadata), true
default:
// TODO(yuzefovich): consider adding support for other datums that don't
// have Datum.Prev implementation (DBitArray, DGeography, DGeometry,
// DBox2D, DJSON, DArray).
// have Datum.Prev implementation (DCollatedString, DBitArray,
// DGeography, DGeometry, DBox2D, DJSON, DArray).
return datum.Prev(cmpCtx)
}
}
Expand Down

0 comments on commit 7af77d4

Please sign in to comment.