Skip to content

Commit 36aa42f

Browse files
committed
chore: remove ValueRef to reduce Arc usage
1 parent fe88322 commit 36aa42f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+762
-927
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ implement_from_tuple!(
116116
```
117117
- User-Defined Function: `features = ["macros"]`
118118
```rust
119-
scala_function!(TestFunction::test(LogicalType::Integer, LogicalType::Integer) -> LogicalType::Integer => |v1: ValueRef, v2: ValueRef| {
119+
scala_function!(TestFunction::test(LogicalType::Integer, LogicalType::Integer) -> LogicalType::Integer => |v1: DataValue, v2: DataValue| {
120120
let plus_binary_evaluator = EvaluatorFactory::binary_create(LogicalType::Integer, BinaryOperator::Plus)?;
121121
let value = plus_binary_evaluator.binary_eval(&v1, &v2);
122122

@@ -130,7 +130,7 @@ let fnck_sql = DataBaseBuilder::path("./data")
130130
```
131131
- User-Defined Table Function: `features = ["macros"]`
132132
```rust
133-
table_function!(MyTableFunction::test_numbers(LogicalType::Integer) -> [c1: LogicalType::Integer, c2: LogicalType::Integer] => (|v1: ValueRef| {
133+
table_function!(MyTableFunction::test_numbers(LogicalType::Integer) -> [c1: LogicalType::Integer, c2: LogicalType::Integer] => (|v1: DataValue| {
134134
let num = v1.i32().unwrap();
135135

136136
Ok(Box::new((0..num)

src/binder/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a, T: Transaction> Binder<'a, '_, T> {
4848
}
4949
Expr::CompoundIdentifier(idents) => self.bind_column_ref_from_identifiers(idents, None),
5050
Expr::BinaryOp { left, right, op } => self.bind_binary_op_internal(left, right, op),
51-
Expr::Value(v) => Ok(ScalarExpression::Constant(Arc::new(v.into()))),
51+
Expr::Value(v) => Ok(ScalarExpression::Constant(v.into())),
5252
Expr::Function(func) => self.bind_function(func),
5353
Expr::Nested(expr) => self.bind_expr(expr),
5454
Expr::UnaryOp { expr, op } => self.bind_unary_op_internal(expr, op),
@@ -77,7 +77,7 @@ impl<'a, T: Transaction> Binder<'a, '_, T> {
7777
}
7878
.cast(&logical_type)?;
7979

80-
Ok(ScalarExpression::Constant(Arc::new(value)))
80+
Ok(ScalarExpression::Constant(value))
8181
}
8282
Expr::Between {
8383
expr,
@@ -672,10 +672,10 @@ impl<'a, T: Transaction> Binder<'a, '_, T> {
672672
}
673673

674674
fn wildcard_expr() -> ScalarExpression {
675-
ScalarExpression::Constant(Arc::new(DataValue::Utf8 {
675+
ScalarExpression::Constant(DataValue::Utf8 {
676676
value: Some("*".to_string()),
677677
ty: Utf8Type::Variable(None),
678678
unit: CharLengthUnits::Characters,
679-
}))
679+
})
680680
}
681681
}

src/binder/insert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::planner::operator::Operator;
77
use crate::planner::LogicalPlan;
88
use crate::storage::Transaction;
99
use crate::types::tuple::SchemaRef;
10-
use crate::types::value::{DataValue, ValueRef};
10+
use crate::types::value::DataValue;
1111
use sqlparser::ast::{Expr, Ident, ObjectName};
1212
use std::slice;
1313
use std::sync::Arc;
@@ -78,7 +78,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
7878
value.check_len(ty)?;
7979

8080
if value.logical_type() != *ty {
81-
value = Arc::new(DataValue::clone(&value).cast(ty)?);
81+
value = value.cast(ty)?;
8282
}
8383
row.push(value);
8484
}
@@ -108,7 +108,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
108108

109109
pub(crate) fn bind_values(
110110
&mut self,
111-
rows: Vec<Vec<ValueRef>>,
111+
rows: Vec<Vec<DataValue>>,
112112
schema_ref: SchemaRef,
113113
) -> LogicalPlan {
114114
LogicalPlan::new(

src/binder/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> {
697697
if let Some(expr) = limit_expr {
698698
let expr = self.bind_expr(expr)?;
699699
match expr {
700-
ScalarExpression::Constant(dv) => match dv.as_ref() {
700+
ScalarExpression::Constant(dv) => match &dv {
701701
DataValue::Int32(Some(v)) if *v >= 0 => limit = Some(*v as usize),
702702
DataValue::Int64(Some(v)) if *v >= 0 => limit = Some(*v as usize),
703703
_ => return Err(DatabaseError::InvalidType),
@@ -713,7 +713,7 @@ impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> {
713713
if let Some(expr) = offset_expr {
714714
let expr = self.bind_expr(&expr.value)?;
715715
match expr {
716-
ScalarExpression::Constant(dv) => match dv.as_ref() {
716+
ScalarExpression::Constant(dv) => match &dv {
717717
DataValue::Int32(Some(v)) if *v > 0 => offset = Some(*v as usize),
718718
DataValue::Int64(Some(v)) if *v > 0 => offset = Some(*v as usize),
719719
_ => return Err(DatabaseError::InvalidType),

src/binder/update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::planner::operator::update::UpdateOperator;
55
use crate::planner::operator::Operator;
66
use crate::planner::LogicalPlan;
77
use crate::storage::Transaction;
8-
use crate::types::value::DataValue;
98
use sqlparser::ast::{Assignment, Expr, TableFactor, TableWithJoins};
109
use std::slice;
1110
use std::sync::Arc;
@@ -47,10 +46,11 @@ impl<T: Transaction> Binder<'_, '_, T> {
4746
// Check if the value length is too long
4847
value.check_len(ty)?;
4948

49+
let mut value = value.clone();
5050
if value.logical_type() != *ty {
51-
row.push(Arc::new(DataValue::clone(value).cast(ty)?));
51+
value = value.cast(ty)?;
5252
}
53-
row.push(value.clone());
53+
row.push(value);
5454
}
5555
ScalarExpression::Empty => {
5656
let default_value = column

src/catalog/column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::catalog::TableName;
22
use crate::errors::DatabaseError;
33
use crate::expression::ScalarExpression;
44
use crate::types::tuple::EMPTY_TUPLE;
5-
use crate::types::value::ValueRef;
5+
use crate::types::value::DataValue;
66
use crate::types::{ColumnId, LogicalType};
77
use fnck_sql_serde_macros::ReferenceSerialization;
88
use sqlparser::ast::CharLengthUnits;
@@ -166,7 +166,7 @@ impl ColumnCatalog {
166166
&self.desc.column_datatype
167167
}
168168

169-
pub(crate) fn default_value(&self) -> Result<Option<ValueRef>, DatabaseError> {
169+
pub(crate) fn default_value(&self) -> Result<Option<DataValue>, DatabaseError> {
170170
self.desc
171171
.default
172172
.as_ref()

src/db.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ pub(crate) mod test {
396396
tuples,
397397
vec![Tuple {
398398
id: None,
399-
values: vec![Arc::new(DataValue::Date32(Some(
400-
Local::now().num_days_from_ce()
401-
)))],
399+
values: vec![DataValue::Date32(Some(Local::now().num_days_from_ce()))],
402400
}]
403401
);
404402
Ok(())
@@ -428,11 +426,11 @@ pub(crate) mod test {
428426
vec![
429427
Tuple {
430428
id: None,
431-
values: vec![Arc::new(DataValue::Int32(Some(3)))],
429+
values: vec![DataValue::Int32(Some(3))],
432430
},
433431
Tuple {
434432
id: None,
435-
values: vec![Arc::new(DataValue::Int32(Some(4)))],
433+
values: vec![DataValue::Int32(Some(4))],
436434
},
437435
]
438436
);
@@ -463,32 +461,20 @@ pub(crate) mod test {
463461

464462
debug_assert_eq!(
465463
tuples_1[0].values,
466-
vec![
467-
Arc::new(DataValue::Int32(Some(0))),
468-
Arc::new(DataValue::Int32(Some(0)))
469-
]
464+
vec![DataValue::Int32(Some(0)), DataValue::Int32(Some(0))]
470465
);
471466
debug_assert_eq!(
472467
tuples_1[1].values,
473-
vec![
474-
Arc::new(DataValue::Int32(Some(1))),
475-
Arc::new(DataValue::Int32(Some(1)))
476-
]
468+
vec![DataValue::Int32(Some(1)), DataValue::Int32(Some(1))]
477469
);
478470

479471
debug_assert_eq!(
480472
tuples_2[0].values,
481-
vec![
482-
Arc::new(DataValue::Int32(Some(0))),
483-
Arc::new(DataValue::Int32(Some(0)))
484-
]
473+
vec![DataValue::Int32(Some(0)), DataValue::Int32(Some(0))]
485474
);
486475
debug_assert_eq!(
487476
tuples_2[1].values,
488-
vec![
489-
Arc::new(DataValue::Int32(Some(3))),
490-
Arc::new(DataValue::Int32(Some(3)))
491-
]
477+
vec![DataValue::Int32(Some(3)), DataValue::Int32(Some(3))]
492478
);
493479

494480
tx_1.commit()?;

src/execution/ddl/add_column.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::ops::Coroutine;
1212
use std::ops::CoroutineState;
1313
use std::pin::Pin;
1414
use std::slice;
15-
use std::sync::Arc;
1615

1716
pub struct AddColumn {
1817
op: AddColumnOperator,
@@ -61,7 +60,7 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for AddColumn {
6160
}
6261
tuple.values.push(value);
6362
} else {
64-
tuple.values.push(Arc::new(DataValue::Null));
63+
tuple.values.push(DataValue::Null);
6564
}
6665
tuples.push(tuple);
6766
}

src/execution/dml/analyze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Analyze {
116116
let meta = StatisticsMeta::new(histogram, sketch);
117117

118118
throw!(meta.to_file(&temp_path));
119-
values.push(Arc::new(DataValue::Utf8 {
119+
values.push(DataValue::Utf8 {
120120
value: Some(path_str.clone()),
121121
ty: Utf8Type::Variable(None),
122122
unit: CharLengthUnits::Characters,
123-
}));
123+
});
124124
throw!(transaction.save_table_meta(cache.2, &table_name, path_str, meta));
125125
throw!(fs::rename(&temp_path, &path).map_err(DatabaseError::IO));
126126

src/execution/dml/delete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::throw;
1010
use crate::types::index::{Index, IndexId, IndexType};
1111
use crate::types::tuple::Tuple;
1212
use crate::types::tuple_builder::TupleBuilder;
13-
use crate::types::value::ValueRef;
13+
use crate::types::value::DataValue;
1414
use std::collections::HashMap;
1515
use std::ops::Coroutine;
1616
use std::ops::CoroutineState;
@@ -106,6 +106,6 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Delete {
106106

107107
struct Value {
108108
exprs: Vec<ScalarExpression>,
109-
value_rows: Vec<Vec<ValueRef>>,
109+
value_rows: Vec<Vec<DataValue>>,
110110
index_ty: IndexType,
111111
}

0 commit comments

Comments
 (0)