Skip to content

Commit

Permalink
fix: stackoverflow with TPCC release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Nov 12, 2024
1 parent 7c14309 commit 22f3bbd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<dyn Iterator<Item = Result<Tuple, DatabaseError>>>)
}));
Expand Down
8 changes: 7 additions & 1 deletion src/binder/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ impl<T: Transaction> 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)?;
ScalarExpression::Constant(default_value)
} 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())),
Expand Down
8 changes: 4 additions & 4 deletions src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: 'static>(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<T: 'static>(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::<T>()?;
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
Expand Down
1 change: 0 additions & 1 deletion src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tpcc/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ impl<S: Storage> Load<S> {
}

#[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<i32> {
let mut orig = vec![0; MAX_ITEMS + 1];

for _ in 0..MAX_ITEMS / 10 {
let mut pos = 0;
Expand Down
6 changes: 3 additions & 3 deletions tpcc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down

0 comments on commit 22f3bbd

Please sign in to comment.