-
-
Notifications
You must be signed in to change notification settings - Fork 238
Add Wrapper values #2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Wrapper values #2893
Conversation
zachmu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only real comment is about perf implications, which I assume you'll be measuring in Dolt
sql/expression/comparison.go
Outdated
| return 0, ErrNilOperand.New() | ||
| } | ||
|
|
||
| if wrapperLeft, isWrapperLeft := left.(sql.AnyWrapper); isWrapperLeft { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we profiled this? Type casts to an interface can be relatively expensive, not sure where this is on the hot path but I would expect it to leave a dent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about it, there's probably not much benefit to this "comparison short-circuit", since (for address types and toast types at least) can't be used to conclude that two values are different, only that they're the same. I'll remove it.
We still need to unwrap values before passing them totypes.TypesEqual. I'll monitor how that affects Dolt performance before I submit.
| "context" | ||
| ) | ||
|
|
||
| // This file introduces interfaces for encapsulating values that may be expensive to load or deserialize. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good docs
…firm it has a real performance benefit, and not a performance penalty.
3bf5e3c to
56c0371
Compare
fa07a76 to
e5862b5
Compare
This PR adds support for
Wrappervalues, a new type of value that the storage layer can provide to the engine. This is a generalization of the existingJsonWrapperinterface, but is not limited to JSON values.Wrapper types are useful because they can represent a value in storage without needing to fully deserialize that value for the engine. The primary use case is for "out-of-band" storage values, such as large
BLOBorTEXTvalues that aren't stored directly in tables.The Wrapper interface has the following methods:
Unwrap/UnwrapAny- These methods both deserialize the wrapped value and return it.UnwrapAnyreturns aninterface{}, whileUnwraphas a parameterized return type. The implementation is encouraged to cache this value.IsExactLength- Returns true if the size of the value can be known without deserializing it.MaxByteLength- The length of the value in bytes. IfIsExactLengthis true, this is the exact length of the value. Otherwise, it's an upper bound on the length of the value, determined by the schema of the table the value was read from.Compare- Some Wrapper implementations may be able to compare wrapped values without needing to deserialize them. This method returns a boolean indicating whether or not this "short-circuit" comparison is possible, and an int indicating the result of the comparison.