diff --git a/README.md b/README.md index 5f7f2219..b9c56efd 100755 --- a/README.md +++ b/README.md @@ -54,6 +54,21 @@ let fnck_sql = DataBaseBuilder::path("./data").build()?; let tuples = fnck_sql.run("select * from t1")?; ``` +### TPCC +run `cargo run -p tpcc --release` to run tpcc + +- i9-13900HX +- 32.0 GB +- YMTC PC411-1024GB-B +```shell +<90th Percentile RT (MaxRT)> + New-Order : 0.882 (0.947) + Payment : 0.080 (0.095) +Order-Status : 0.235 (0.255) + Delivery : 5.386 (5.658) + Stock-Level : 0.001 (0.002) +``` + #### PG Wire Service run `cargo run --features="net"` to start server ![start](./static/images/start.gif) @@ -138,8 +153,8 @@ table_function!(MyTableFunction::test_numbers(LogicalType::Integer) -> [c1: Logi .map(|i| Ok(Tuple { id: None, values: vec![ - Arc::new(DataValue::Int32(Some(i))), - Arc::new(DataValue::Int32(Some(i))), + DataValue::Int32(Some(i)), + DataValue::Int32(Some(i)), ] }))) as Box>>) })); diff --git a/src/binder/update.rs b/src/binder/update.rs index 0cd5f00e..b2cc49f6 100644 --- a/src/binder/update.rs +++ b/src/binder/update.rs @@ -40,7 +40,7 @@ impl Binder<'_, '_, T> { Some(table_name.to_string()), )? { ScalarExpression::ColumnRef(column) => { - let expr = if matches!(expression, ScalarExpression::Empty) { + let mut expr = if matches!(expression, ScalarExpression::Empty) { let default_value = column .default_value()? .ok_or(DatabaseError::DefaultNotExist)?; @@ -48,6 +48,12 @@ impl Binder<'_, '_, T> { } else { expression.clone() }; + if &expr.return_type() != column.datatype() { + expr = ScalarExpression::TypeCast { + expr: Box::new(expr), + ty: column.datatype().clone(), + } + } value_exprs.push((column, expr)); } _ => return Err(DatabaseError::InvalidColumn(ident.to_string())), diff --git a/src/macros/mod.rs b/src/macros/mod.rs index 7efc77a0..e6bb0b47 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -25,20 +25,20 @@ macro_rules! implement_from_tuple { ($struct_name:ident, ($($field_name:ident : $field_type:ty => $closure:expr),+)) => { impl From<(&::fnck_sql::types::tuple::SchemaRef, ::fnck_sql::types::tuple::Tuple)> for $struct_name { - fn from((schema, tuple): (&::fnck_sql::types::tuple::SchemaRef, ::fnck_sql::types::tuple::Tuple)) -> Self { - fn try_get(tuple: &::fnck_sql::types::tuple::Tuple, schema: &::fnck_sql::types::tuple::SchemaRef, field_name: &str) -> Option<::fnck_sql::types::value::DataValue> { + fn from((schema, mut tuple): (&::fnck_sql::types::tuple::SchemaRef, ::fnck_sql::types::tuple::Tuple)) -> Self { + fn try_get(tuple: &mut ::fnck_sql::types::tuple::Tuple, schema: &::fnck_sql::types::tuple::SchemaRef, field_name: &str) -> Option<::fnck_sql::types::value::DataValue> { let ty = ::fnck_sql::types::LogicalType::type_trans::()?; let (idx, _) = schema .iter() .enumerate() .find(|(_, col)| col.name() == field_name)?; - tuple.values[idx].cast(&ty).ok() + std::mem::replace(&mut tuple.values[idx], ::fnck_sql::types::value::DataValue::Null).cast(&ty).ok() } let mut struct_instance = $struct_name::default(); $( - if let Some(value) = try_get::<$field_type>(&tuple, schema, stringify!($field_name)) { + if let Some(value) = try_get::<$field_type>(&mut tuple, schema, stringify!($field_name)) { $closure( &mut struct_instance, value diff --git a/src/types/value.rs b/src/types/value.rs index 08bbac10..01e2eb89 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -563,7 +563,6 @@ impl DataValue { } Utf8Type::Fixed(len) => match unit { CharLengthUnits::Characters => { - debug_assert!((*len as usize) >= v.len()); let chars_len = *len as usize; let string_bytes = format!("{:len$}", v, len = chars_len).into_bytes(); diff --git a/tpcc/src/load.rs b/tpcc/src/load.rs index b9f22abe..0e1a6d54 100644 --- a/tpcc/src/load.rs +++ b/tpcc/src/load.rs @@ -430,8 +430,8 @@ impl Load { } #[allow(unused_assignments)] - fn gen_orig(rng: &mut ThreadRng) -> [i32; 100001] { - let mut orig = [0; MAX_ITEMS + 1]; + fn gen_orig(rng: &mut ThreadRng) -> Vec { + let mut orig = vec![0; MAX_ITEMS + 1]; for _ in 0..MAX_ITEMS / 10 { let mut pos = 0; diff --git a/tpcc/src/main.rs b/tpcc/src/main.rs index 13567875..03881bdf 100644 --- a/tpcc/src/main.rs +++ b/tpcc/src/main.rs @@ -67,9 +67,9 @@ fn main() -> Result<(), TpccError> { let database = DataBaseBuilder::path(&args.path).build()?; Load::load_items(&mut rng, &database)?; - Load::load_warehouses(&mut rng, &database, 1)?; - Load::load_custs(&mut rng, &database, 1)?; - Load::load_ord(&mut rng, &database, 1)?; + Load::load_warehouses(&mut rng, &database, args.num_ware)?; + Load::load_custs(&mut rng, &database, args.num_ware)?; + Load::load_ord(&mut rng, &database, args.num_ware)?; let mut rt_hist = RtHist::new(); let tests = vec![