Skip to content
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

Remove RC from certain Owned Value Types and look for DX friendly ways to implement Zerocopy Result Row #974

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/json/json_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ pub fn json_remove(args: &[OwnedValue]) -> crate::Result<OwnedValue> {

#[cfg(test)]
mod tests {
use std::rc::Rc;

use crate::types::Text;

Expand Down Expand Up @@ -457,7 +456,7 @@ mod tests {
#[test]
#[should_panic(expected = "blob is not supported!")]
fn test_blob_not_supported() {
let target = OwnedValue::Blob(Rc::new(vec![1, 2, 3]));
let target = OwnedValue::Blob(vec![1, 2, 3]);
let patch = create_text("{}");
json_patch(&target, &patch).unwrap();
}
Expand Down
9 changes: 4 additions & 5 deletions core/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ pub fn json_quote(value: &OwnedValue) -> crate::Result<OwnedValue> {

#[cfg(test)]
mod tests {
use std::rc::Rc;

use super::*;
use crate::types::OwnedValue;
Expand Down Expand Up @@ -815,7 +814,7 @@ mod tests {
#[test]
fn test_get_json_blob_valid_jsonb() {
let binary_json = b"\x40\0\0\x01\x10\0\0\x03\x10\0\0\x03\x61\x73\x64\x61\x64\x66".to_vec();
let input = OwnedValue::Blob(Rc::new(binary_json));
let input = OwnedValue::Blob(binary_json);
let result = get_json(&input, None).unwrap();
if let OwnedValue::Text(result_str) = result {
assert!(result_str.as_str().contains("\"asd\":\"adf\""));
Expand All @@ -828,7 +827,7 @@ mod tests {
#[test]
fn test_get_json_blob_invalid_jsonb() {
let binary_json: Vec<u8> = vec![0xA2, 0x62, 0x6B, 0x31, 0x62, 0x76]; // Incomplete binary JSON
let input = OwnedValue::Blob(Rc::new(binary_json));
let input = OwnedValue::Blob(binary_json);
let result = get_json(&input, None);
match result {
Ok(_) => panic!("Expected error for malformed JSON"),
Expand Down Expand Up @@ -877,7 +876,7 @@ mod tests {

#[test]
fn test_json_array_blob_invalid() {
let blob = OwnedValue::Blob(Rc::new("1".as_bytes().to_vec()));
let blob = OwnedValue::Blob("1".as_bytes().to_vec());

let input = vec![blob];

Expand Down Expand Up @@ -1072,7 +1071,7 @@ mod tests {

#[test]
fn test_json_error_position_blob() {
let input = OwnedValue::Blob(Rc::new(r#"["a",55,"b",72,,]"#.as_bytes().to_owned()));
let input = OwnedValue::Blob(r#"["a",55,"b",72,,]"#.as_bytes().to_owned());
let result = json_error_position(&input).unwrap();
assert_eq!(result, OwnedValue::Integer(16));
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl VirtualTable {
OwnedValue::Integer(i) => Ok(ExtValue::from_integer(*i)),
OwnedValue::Float(f) => Ok(ExtValue::from_float(*f)),
OwnedValue::Text(t) => Ok(ExtValue::from_text(t.as_str().to_string())),
OwnedValue::Blob(b) => Ok(ExtValue::from_blob((**b).clone())),
OwnedValue::Blob(b) => Ok(ExtValue::from_blob(b.clone())), // BLOB cloning here
other => Err(LimboError::ExtensionError(format!(
"Unsupported value type: {:?}",
other
Expand Down
4 changes: 2 additions & 2 deletions core/storage/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ mod tests {
let mut cursor = BTreeCursor::new(pager.clone(), root_page);
for (key, size) in sequence.iter() {
let key = OwnedValue::Integer(*key);
let value = Record::new(vec![OwnedValue::Blob(Rc::new(vec![0; *size]))]);
let value = Record::new(vec![OwnedValue::Blob(vec![0; *size])]);
log::info!("insert key:{}", key);
cursor.insert(&key, &value, false).unwrap();
log::info!(
Expand Down Expand Up @@ -2632,7 +2632,7 @@ mod tests {
insert_id
);
let key = OwnedValue::Integer(key);
let value = Record::new(vec![OwnedValue::Blob(Rc::new(vec![0; size]))]);
let value = Record::new(vec![OwnedValue::Blob(vec![0; size])]);
cursor.insert(&key, &value, false).unwrap();
}
log::info!(
Expand Down
2 changes: 1 addition & 1 deletion core/storage/sqlite3_ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ pub fn read_value(buf: &[u8], serial_type: &SerialType) -> Result<(OwnedValue, u
let bytes = buf[0..n].to_vec();
Ok((
OwnedValue::Text(Text {
value: Rc::new(bytes),
value: bytes,
subtype: TextSubtype::Text,
}),
n,
Expand Down
23 changes: 11 additions & 12 deletions core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::vdbe::sorter::Sorter;
use crate::vdbe::VTabOpaqueCursor;
use crate::Result;
use std::fmt::Display;
use std::rc::Rc;

#[derive(Debug, Clone, PartialEq)]
pub enum Value<'a> {
Expand Down Expand Up @@ -50,7 +49,7 @@ pub enum TextSubtype {

#[derive(Debug, Clone, PartialEq)]
pub struct Text {
pub value: Rc<Vec<u8>>,
pub value: Vec<u8>,
pub subtype: TextSubtype,
}

Expand All @@ -61,14 +60,14 @@ impl Text {

pub fn new(value: &str) -> Self {
Self {
value: Rc::new(value.as_bytes().to_vec()),
value: value.as_bytes().to_vec(),
subtype: TextSubtype::Text,
}
}

pub fn json(value: &str) -> Self {
Self {
value: Rc::new(value.as_bytes().to_vec()),
value: value.as_bytes().to_vec(),
subtype: TextSubtype::Json,
}
}
Expand All @@ -84,7 +83,7 @@ pub enum OwnedValue {
Integer(i64),
Float(f64),
Text(Text),
Blob(Rc<Vec<u8>>),
Blob(Vec<u8>),
Agg(Box<AggContext>), // TODO(pere): make this without Box. Currently this might cause cache miss but let's leave it for future analysis
Record(Record),
}
Expand All @@ -103,7 +102,7 @@ impl OwnedValue {
}

pub fn from_blob(data: Vec<u8>) -> Self {
OwnedValue::Blob(std::rc::Rc::new(data))
OwnedValue::Blob(data)
}

pub fn to_text(&self) -> Option<&str> {
Expand Down Expand Up @@ -248,7 +247,7 @@ impl OwnedValue {
let Some(blob) = v.to_blob() else {
return Ok(OwnedValue::Null);
};
Ok(OwnedValue::Blob(Rc::new(blob)))
Ok(OwnedValue::Blob(blob))
}
ExtValueType::Error => {
let Some(err) = v.to_error_details() else {
Expand Down Expand Up @@ -482,7 +481,7 @@ impl From<Value<'_>> for OwnedValue {
Value::Integer(i) => OwnedValue::Integer(i),
Value::Float(f) => OwnedValue::Float(f),
Value::Text(s) => OwnedValue::Text(Text::from_str(s)),
Value::Blob(b) => OwnedValue::Blob(Rc::new(b.to_owned())),
Value::Blob(b) => OwnedValue::Blob(b.to_owned()),
}
}
}
Expand Down Expand Up @@ -765,7 +764,6 @@ pub enum SeekKey<'a> {
#[cfg(test)]
mod tests {
use super::*;
use std::rc::Rc;

#[test]
fn test_serialize_null() {
Expand Down Expand Up @@ -900,8 +898,9 @@ mod tests {

#[test]
fn test_serialize_blob() {
let blob = Rc::new(vec![1, 2, 3, 4, 5]);
let record = Record::new(vec![OwnedValue::Blob(blob.clone())]);
let blob = vec![1, 2, 3, 4, 5];
let blob_len = blob.len();
let record = Record::new(vec![OwnedValue::Blob(blob)]);
let mut buf = Vec::new();
record.serialize(&mut buf);

Expand All @@ -914,7 +913,7 @@ mod tests {
// Check the actual blob bytes
assert_eq!(&buf[2..7], &[1, 2, 3, 4, 5]);
// Check that buffer length is correct
assert_eq!(buf.len(), header_length + blob.len());
assert_eq!(buf.len(), header_length + blob_len);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions core/vdbe/explain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::vdbe::builder::CursorType;

use super::{Insn, InsnReference, OwnedValue, Program};
use std::rc::Rc;

pub fn insn_to_str(
program: &Program,
Expand Down Expand Up @@ -643,7 +642,7 @@ pub fn insn_to_str(
0,
*dest as i32,
0,
OwnedValue::Blob(Rc::new(value.clone())),
OwnedValue::Blob(value.clone()), // TODO Why not owned blob here?
0,
format!(
"r[{}]={} (len={})",
Expand Down
Loading
Loading