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

Perf/issue 155 #250

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ run `cargo run -p tpcc --release` to run tpcc
- Tips: TPCC currently only supports single thread
```shell
<90th Percentile RT (MaxRT)>
New-Order : 0.005 (0.007)
Payment : 0.084 (0.141)
Order-Status : 0.492 (0.575)
Delivery : 6.109 (6.473)
Stock-Level : 0.001 (0.001)
New-Order : 0.003 (0.006)
Payment : 0.001 (0.003)
Order-Status : 0.062 (0.188)
Delivery : 0.022 (0.052)
Stock-Level : 0.004 (0.006)
<TpmC>
98 Tpmc
6669 Tpmc
```
#### PG Wire Service
run `cargo run --features="net"` to start server
Expand Down
17 changes: 17 additions & 0 deletions src/catalog/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,28 @@ impl TableCatalog {
}
})
.clone();

let mut val_tys = Vec::with_capacity(column_ids.len());
for column_id in column_ids.iter() {
let val_ty = self
.get_column_by_id(column_id)
.ok_or_else(|| DatabaseError::ColumnNotFound(column_id.to_string()))?
.datatype()
.clone();
val_tys.push(val_ty)
}
let value_ty = if val_tys.len() == 1 {
val_tys.pop().unwrap()
} else {
LogicalType::Tuple(val_tys)
};

let index = IndexMeta {
id: index_id,
column_ids,
table_name: self.name.clone(),
pk_ty,
value_ty,
name,
ty,
};
Expand Down
4 changes: 1 addition & 3 deletions src/execution/ddl/add_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::Pin;
use std::slice;

pub struct AddColumn {
op: AddColumnOperator,
Expand Down Expand Up @@ -80,8 +79,7 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for AddColumn {
.cloned(),
) {
for (tuple_id, value) in unique_values {
let index =
Index::new(unique_meta.id, slice::from_ref(&value), IndexType::Unique);
let index = Index::new(unique_meta.id, &value, IndexType::Unique);
throw!(transaction.add_index(table_name, index, &tuple_id));
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/execution/ddl/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::throw;
use crate::types::index::Index;
use crate::types::tuple::Tuple;
use crate::types::tuple_builder::TupleBuilder;
use crate::types::value::DataValue;
use crate::types::ColumnId;
use std::ops::Coroutine;
use std::ops::CoroutineState;
Expand Down Expand Up @@ -86,7 +87,10 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for CreateIndex {
}
drop(coroutine);
for (tuple_id, values) in index_values {
let index = Index::new(index_id, &values, ty);
let Some(value) = DataValue::values_to_tuple(values) else {
continue;
};
let index = Index::new(index_id, &value, ty);
throw!(transaction.add_index(table_name.as_str(), index, &tuple_id));
}
yield Ok(TupleBuilder::build_result("1".to_string()));
Expand Down
4 changes: 3 additions & 1 deletion src/execution/dml/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Analyze {
if values.len() == 1 {
throw!(builder.append(&values[0]));
} else {
throw!(builder.append(&Arc::new(DataValue::Tuple(Some(values)))));
throw!(
builder.append(&Arc::new(DataValue::Tuple(Some((values, false)))))
);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/execution/dml/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Delete {
) in indexes
{
for (i, values) in value_rows.into_iter().enumerate() {
let Some(value) = DataValue::values_to_tuple(values) else {
continue;
};

throw!(transaction.del_index(
&table_name,
&Index::new(index_id, &values, index_ty),
&Index::new(index_id, &value, index_ty),
Some(&tuple_ids[i]),
));
}
Expand Down
7 changes: 5 additions & 2 deletions src/execution/dml/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Insert {
id: Some(if primary_keys.len() == 1 {
tuple_id.pop().unwrap()
} else {
DataValue::Tuple(Some(tuple_id))
DataValue::Tuple(Some((tuple_id, false)))
}),
values,
});
Expand All @@ -142,7 +142,10 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Insert {

for tuple in tuples.iter() {
let values = throw!(Projection::projection(tuple, &exprs, &schema));
let index = Index::new(index_meta.id, &values, index_meta.ty);
let Some(value) = DataValue::values_to_tuple(values) else {
continue;
};
let index = Index::new(index_meta.id, &value, index_meta.ty);

throw!(transaction.add_index(
&table_name,
Expand Down
11 changes: 9 additions & 2 deletions src/execution/dml/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::types::index::Index;
use crate::types::tuple::types;
use crate::types::tuple::Tuple;
use crate::types::tuple_builder::{TupleBuilder, TupleIdBuilder};
use crate::types::value::DataValue;
use std::collections::HashMap;
use std::ops::Coroutine;
use std::ops::CoroutineState;
Expand Down Expand Up @@ -82,7 +83,10 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Update {
for tuple in tuples.iter() {
let values =
throw!(Projection::projection(tuple, &exprs, &input_schema));
let index = Index::new(index_meta.id, &values, index_meta.ty);
let Some(value) = DataValue::values_to_tuple(values) else {
continue;
};
let index = Index::new(index_meta.id, &value, index_meta.ty);
throw!(transaction.del_index(
&table_name,
&index,
Expand Down Expand Up @@ -116,7 +120,10 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Update {
for (index_meta, exprs) in index_metas.iter() {
let values =
throw!(Projection::projection(&tuple, exprs, &input_schema));
let index = Index::new(index_meta.id, &values, index_meta.ty);
let Some(value) = DataValue::values_to_tuple(values) else {
continue;
};
let index = Index::new(index_meta.id, &value, index_meta.ty);
throw!(transaction.add_index(
&table_name,
index,
Expand Down
4 changes: 3 additions & 1 deletion src/expression/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ impl ScalarExpression {
for expr in exprs {
values.push(expr.eval(tuple, schema)?);
}
Ok(DataValue::Tuple((!values.is_empty()).then_some(values)))
Ok(DataValue::Tuple(
(!values.is_empty()).then_some((values, false)),
))
}
ScalarExpression::ScalaFunction(ScalarFunction { inner, args, .. }) => {
inner.eval(args, tuple, schema)?.cast(inner.return_type())
Expand Down
Loading
Loading