pub trait HashKeySer<'a>: ScalarRef<'a> {
// Required method
fn serialize_into(self, buf: impl BufMut);
// Provided methods
fn exact_size() -> Option<usize> { ... }
fn estimated_size(self) -> usize { ... }
}
Expand description
Extension of scalars to be serialized into hash keys.
The exact_size
and estimated_size
methods are used to estimate the size of the serialized
hash key, so that we can pre-allocate the buffer for it.
- override
exact_size
if the serialized size is known for this scalar type; - override
estimated_size
if the serialized size varies for different values of this scalar type, but we can estimate it.
NOTE: The hash key encoding algorithm needs to respect the implementation of Hash
and Eq
on
scalar types, which is exactly the same behavior of the data types under GROUP BY
or
PARTITION BY
in PostgreSQL. For example, Decimal(1.0)
vs Decimal(1.00)
, or Interval(24 hour)
vs Interval(1 day)
are considered equal here.
This means that…
- delegating to the value encoding can be incorrect for some types, as they reflect the in-memory representation faithfully;
- delegating to the memcmp encoding should be always safe, but they put extra effort to also
preserve the property of
Ord
.
So for some scalar types we have to maintain a separate implementation here. For those that can
be delegated to other encoding algorithms, we can use macros of
impl_memcmp_encoding_hash_key_serde!
and impl_value_encoding_hash_key_serde!
here.
Required Methods§
sourcefn serialize_into(self, buf: impl BufMut)
fn serialize_into(self, buf: impl BufMut)
Serialize the scalar into the given buffer.
Provided Methods§
sourcefn exact_size() -> Option<usize>
fn exact_size() -> Option<usize>
Returns Some
if the serialized size is known for this scalar type.
sourcefn estimated_size(self) -> usize
fn estimated_size(self) -> usize
Returns the estimated serialized size for this scalar.