diff --git a/src/common/src/row/mod.rs b/src/common/src/row/mod.rs index 6cd43e7d25b89..ce2f9e2744996 100644 --- a/src/common/src/row/mod.rs +++ b/src/common/src/row/mod.rs @@ -78,7 +78,11 @@ pub trait Row: Sized + std::fmt::Debug + PartialEq + Eq { /// Serializes the row with value encoding and returns the bytes. #[inline] fn value_serialize(&self) -> Vec { - let mut buf = Vec::with_capacity(self.len()); // each datum is at least 1 byte + let estimate_size = self + .iter() + .map(value_encoding::estimate_serialize_datum_size) + .sum(); + let mut buf = Vec::with_capacity(estimate_size); self.value_serialize_into(&mut buf); buf } @@ -86,7 +90,11 @@ pub trait Row: Sized + std::fmt::Debug + PartialEq + Eq { /// Serializes the row with value encoding and returns the bytes. #[inline] fn value_serialize_bytes(&self) -> Bytes { - let mut buf = BytesMut::with_capacity(self.len()); // each datum is at least 1 byte + let estimate_size = self + .iter() + .map(value_encoding::estimate_serialize_datum_size) + .sum(); + let mut buf = BytesMut::with_capacity(estimate_size); self.value_serialize_into(&mut buf); buf.freeze() }