diff --git a/src/binder/aggregate.rs b/src/binder/aggregate.rs index 9a5ccef..90ad617 100644 --- a/src/binder/aggregate.rs +++ b/src/binder/aggregate.rs @@ -3,18 +3,18 @@ use itertools::Itertools; use sqlparser::ast::{Expr, OrderByExpr}; use std::collections::HashSet; +use super::{Binder, QueryBindStep}; use crate::errors::DatabaseError; use crate::expression::function::scala::ScalarFunction; use crate::planner::LogicalPlan; use crate::storage::Transaction; +use crate::types::value::DataValue; use crate::{ expression::ScalarExpression, planner::operator::{aggregate::AggregateOperator, sort::SortField}, }; -use super::{Binder, QueryBindStep}; - -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub fn bind_aggregate( &mut self, children: LogicalPlan, diff --git a/src/binder/alter_table.rs b/src/binder/alter_table.rs index 8d21a3b..1c0ff2a 100644 --- a/src/binder/alter_table.rs +++ b/src/binder/alter_table.rs @@ -11,8 +11,9 @@ use crate::planner::operator::table_scan::TableScanOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_alter_table( &mut self, name: &ObjectName, diff --git a/src/binder/analyze.rs b/src/binder/analyze.rs index ce9d269..6aaafe7 100644 --- a/src/binder/analyze.rs +++ b/src/binder/analyze.rs @@ -5,10 +5,11 @@ use crate::planner::operator::table_scan::TableScanOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::ObjectName; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_analyze(&mut self, name: &ObjectName) -> Result { let table_name = Arc::new(lower_case_name(name)?); diff --git a/src/binder/copy.rs b/src/binder/copy.rs index f757b5e..05966bc 100644 --- a/src/binder/copy.rs +++ b/src/binder/copy.rs @@ -64,7 +64,7 @@ impl FromStr for ExtSource { } } -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(super) fn bind_copy( &mut self, source: CopySource, diff --git a/src/binder/create_index.rs b/src/binder/create_index.rs index 06660aa..69a0b10 100644 --- a/src/binder/create_index.rs +++ b/src/binder/create_index.rs @@ -7,10 +7,11 @@ use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; use crate::types::index::IndexType; +use crate::types::value::DataValue; use sqlparser::ast::{ObjectName, OrderByExpr}; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_create_index( &mut self, table_name: &ObjectName, diff --git a/src/binder/create_table.rs b/src/binder/create_table.rs index b8bcd9d..54c9d84 100644 --- a/src/binder/create_table.rs +++ b/src/binder/create_table.rs @@ -12,9 +12,10 @@ use crate::planner::operator::create_table::CreateTableOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use crate::types::LogicalType; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { // TODO: TableConstraint pub(crate) fn bind_create_table( &mut self, @@ -157,7 +158,6 @@ mod tests { use crate::types::LogicalType; use crate::utils::lru::SharedLruCache; use sqlparser::ast::CharLengthUnits; - use std::cell::RefCell; use std::hash::RandomState; use std::sync::atomic::AtomicUsize; use tempfile::TempDir; @@ -173,7 +173,6 @@ mod tests { let table_functions = Default::default(); let sql = "create table t1 (id int primary key, name varchar(10) null)"; - let args = RefCell::new(Vec::new()); let mut binder = Binder::new( BinderContext::new( &table_cache, @@ -183,7 +182,7 @@ mod tests { &table_functions, Arc::new(AtomicUsize::new(0)), ), - &args, + &[], None, ); let stmt = crate::parser::parse_sql(sql).unwrap(); diff --git a/src/binder/create_view.rs b/src/binder/create_view.rs index c48d1db..2d99b0b 100644 --- a/src/binder/create_view.rs +++ b/src/binder/create_view.rs @@ -7,12 +7,13 @@ use crate::planner::operator::create_view::CreateViewOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use itertools::Itertools; use sqlparser::ast::{Ident, ObjectName, Query}; use std::sync::Arc; use ulid::Ulid; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_create_view( &mut self, or_replace: &bool, diff --git a/src/binder/delete.rs b/src/binder/delete.rs index 026c084..96971e3 100644 --- a/src/binder/delete.rs +++ b/src/binder/delete.rs @@ -5,11 +5,12 @@ use crate::planner::operator::table_scan::TableScanOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use itertools::Itertools; use sqlparser::ast::{Expr, TableAlias, TableFactor, TableWithJoins}; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_delete( &mut self, from: &TableWithJoins, diff --git a/src/binder/describe.rs b/src/binder/describe.rs index d77ecf2..e867707 100644 --- a/src/binder/describe.rs +++ b/src/binder/describe.rs @@ -4,10 +4,11 @@ use crate::planner::operator::describe::DescribeOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::ObjectName; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_describe( &mut self, name: &ObjectName, diff --git a/src/binder/distinct.rs b/src/binder/distinct.rs index fa88d1e..db431f2 100644 --- a/src/binder/distinct.rs +++ b/src/binder/distinct.rs @@ -3,8 +3,9 @@ use crate::expression::ScalarExpression; use crate::planner::operator::aggregate::AggregateOperator; use crate::planner::LogicalPlan; use crate::storage::Transaction; +use crate::types::value::DataValue; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub fn bind_distinct( &mut self, children: LogicalPlan, diff --git a/src/binder/drop_table.rs b/src/binder/drop_table.rs index 30bc13f..5666ee8 100644 --- a/src/binder/drop_table.rs +++ b/src/binder/drop_table.rs @@ -4,10 +4,11 @@ use crate::planner::operator::drop_table::DropTableOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::ObjectName; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_drop_table( &mut self, name: &ObjectName, diff --git a/src/binder/drop_view.rs b/src/binder/drop_view.rs index 4e635b7..4cb4044 100644 --- a/src/binder/drop_view.rs +++ b/src/binder/drop_view.rs @@ -4,10 +4,11 @@ use crate::planner::operator::drop_view::DropViewOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::ObjectName; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_drop_view( &mut self, name: &ObjectName, diff --git a/src/binder/explain.rs b/src/binder/explain.rs index 9119feb..48a9067 100644 --- a/src/binder/explain.rs +++ b/src/binder/explain.rs @@ -3,8 +3,9 @@ use crate::errors::DatabaseError; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_explain(&mut self, plan: LogicalPlan) -> Result { Ok(LogicalPlan::new(Operator::Explain, Childrens::Only(plan))) } diff --git a/src/binder/expr.rs b/src/binder/expr.rs index 53c4958..5fa653f 100644 --- a/src/binder/expr.rs +++ b/src/binder/expr.rs @@ -40,7 +40,7 @@ macro_rules! try_default { }; } -impl<'a, T: Transaction> Binder<'a, '_, T> { +impl<'a, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, '_, T, A> { pub(crate) fn bind_expr(&mut self, expr: &Expr) -> Result { match expr { Expr::Identifier(ident) => { @@ -50,14 +50,11 @@ impl<'a, T: Transaction> Binder<'a, '_, T> { Expr::BinaryOp { left, right, op } => self.bind_binary_op_internal(left, right, op), Expr::Value(v) => { let value = if let Value::Placeholder(name) = v { - let (i, _) = self - .args - .borrow() + self.args + .as_ref() .iter() - .enumerate() - .find(|(_, (key, _))| key == name) - .ok_or_else(|| DatabaseError::ParametersNotFound(name.to_string()))?; - self.args.borrow_mut().remove(i).1 + .find_map(|(key, value)| (key == name).then(|| value.clone())) + .ok_or_else(|| DatabaseError::ParametersNotFound(name.to_string()))? } else { v.into() }; diff --git a/src/binder/insert.rs b/src/binder/insert.rs index 56f4dce..0d9eb2b 100644 --- a/src/binder/insert.rs +++ b/src/binder/insert.rs @@ -12,7 +12,7 @@ use sqlparser::ast::{Expr, Ident, ObjectName}; use std::slice; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_insert( &mut self, name: &ObjectName, diff --git a/src/binder/mod.rs b/src/binder/mod.rs index 7e9e534..5ff832b 100644 --- a/src/binder/mod.rs +++ b/src/binder/mod.rs @@ -19,20 +19,20 @@ mod truncate; mod update; use sqlparser::ast::{Ident, ObjectName, ObjectType, SetExpr, Statement}; -use std::cell::RefCell; use std::collections::{BTreeMap, HashMap, HashSet}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use crate::catalog::view::View; use crate::catalog::{ColumnRef, TableCatalog, TableName}; -use crate::db::{Args, ScalaFunctions, TableFunctions}; +use crate::db::{ScalaFunctions, TableFunctions}; use crate::errors::DatabaseError; use crate::expression::ScalarExpression; use crate::planner::operator::join::JoinType; use crate::planner::{LogicalPlan, SchemaOutput}; use crate::storage::{TableCache, Transaction, ViewCache}; use crate::types::tuple::SchemaRef; +use crate::types::value::DataValue; pub enum InputRefType { AggCall, @@ -313,18 +313,18 @@ impl<'a, T: Transaction> BinderContext<'a, T> { } } -pub struct Binder<'a, 'b, T: Transaction> { +pub struct Binder<'a, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> { context: BinderContext<'a, T>, table_schema_buf: HashMap>, - args: &'a RefCell, - pub(crate) parent: Option<&'b Binder<'a, 'b, T>>, + args: &'a A, + pub(crate) parent: Option<&'b Binder<'a, 'b, T, A>>, } -impl<'a, 'b, T: Transaction> Binder<'a, 'b, T> { +impl<'a, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, 'b, T, A> { pub fn new( context: BinderContext<'a, T>, - args: &'a RefCell, - parent: Option<&'b Binder<'a, 'b, T>>, + args: &'a A, + parent: Option<&'b Binder<'a, 'b, T, A>>, ) -> Self { Binder { context, @@ -488,7 +488,6 @@ pub mod test { use crate::types::ColumnId; use crate::types::LogicalType::Integer; use crate::utils::lru::SharedLruCache; - use std::cell::RefCell; use std::hash::RandomState; use std::path::PathBuf; use std::sync::atomic::AtomicUsize; @@ -507,7 +506,6 @@ pub mod test { let scala_functions = Default::default(); let table_functions = Default::default(); let transaction = self.storage.transaction()?; - let args = RefCell::new(Vec::new()); let mut binder = Binder::new( BinderContext::new( &self.table_cache, @@ -517,7 +515,7 @@ pub mod test { &table_functions, Arc::new(AtomicUsize::new(0)), ), - &args, + &[], None, ); let stmt = crate::parser::parse_sql(sql)?; diff --git a/src/binder/select.rs b/src/binder/select.rs index b079eb6..ec7a4e5 100644 --- a/src/binder/select.rs +++ b/src/binder/select.rs @@ -38,7 +38,7 @@ use sqlparser::ast::{ TableWithJoins, }; -impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> { +impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, 'b, T, A> { pub(crate) fn bind_query(&mut self, query: &Query) -> Result { let origin_step = self.context.step_now(); diff --git a/src/binder/show.rs b/src/binder/show.rs index 2c49f1f..f229555 100644 --- a/src/binder/show.rs +++ b/src/binder/show.rs @@ -3,8 +3,9 @@ use crate::errors::DatabaseError; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_show_tables(&mut self) -> Result { Ok(LogicalPlan::new(Operator::Show, Childrens::None)) } diff --git a/src/binder/truncate.rs b/src/binder/truncate.rs index 3972067..ac382d4 100644 --- a/src/binder/truncate.rs +++ b/src/binder/truncate.rs @@ -4,10 +4,11 @@ use crate::planner::operator::truncate::TruncateOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::ObjectName; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_truncate( &mut self, name: &ObjectName, diff --git a/src/binder/update.rs b/src/binder/update.rs index d33bd50..dd13472 100644 --- a/src/binder/update.rs +++ b/src/binder/update.rs @@ -5,11 +5,12 @@ use crate::planner::operator::update::UpdateOperator; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::storage::Transaction; +use crate::types::value::DataValue; use sqlparser::ast::{Assignment, Expr, TableFactor, TableWithJoins}; use std::slice; use std::sync::Arc; -impl Binder<'_, '_, T> { +impl> Binder<'_, '_, T, A> { pub(crate) fn bind_update( &mut self, to: &TableWithJoins, diff --git a/src/db.rs b/src/db.rs index ce16769..a7379ad 100644 --- a/src/db.rs +++ b/src/db.rs @@ -23,7 +23,6 @@ use crate::utils::lru::SharedLruCache; use ahash::HashMap; use parking_lot::lock_api::{ArcRwLockReadGuard, ArcRwLockWriteGuard}; use parking_lot::{RawRwLock, RwLock}; -use std::cell::RefCell; use std::hash::RandomState; use std::marker::PhantomData; use std::mem; @@ -36,7 +35,6 @@ use std::sync::Arc; pub(crate) type ScalaFunctions = HashMap>; pub(crate) type TableFunctions = HashMap>; -pub type Args = Vec<(&'static str, DataValue)>; pub type Statement = sqlparser::ast::Statement; #[allow(dead_code)] @@ -130,9 +128,9 @@ impl State { } #[allow(clippy::too_many_arguments)] - pub(crate) fn build_plan( + pub(crate) fn build_plan>( stmt: &Statement, - args: &RefCell, + params: A, table_cache: &TableCache, view_cache: &ViewCache, meta_cache: &StatisticsMetaCache, @@ -149,7 +147,7 @@ impl State { table_functions, Arc::new(AtomicUsize::new(0)), ), - args, + ¶ms, None, ); /// Build a logical plan. @@ -254,17 +252,15 @@ impl State { stmts.pop().ok_or(DatabaseError::EmptyStatement) } - fn execute<'a>( + fn execute<'a, A: AsRef<[(&'static str, DataValue)]>>( &'a self, transaction: &'a mut S::TransactionType<'_>, stmt: &Statement, - args: Args, + params: A, ) -> Result<(SchemaRef, Executor<'a>), DatabaseError> { - let args = RefCell::new(args); - let mut plan = Self::build_plan( stmt, - &args, + params, self.table_cache(), self.view_cache(), self.meta_cache(), @@ -294,18 +290,18 @@ impl Database { pub fn run>(&self, sql: T) -> Result, DatabaseError> { let statement = self.prepare(sql)?; - self.execute(&statement, vec![]) + self.execute(&statement, &[]) } pub fn prepare>(&self, sql: T) -> Result { self.state.prepare(sql) } - fn execute( + fn execute>( &self, statement: &Statement, - args: Args, - ) -> Result, DatabaseError> { + params: A, + ) -> Result, DatabaseError> { let _guard = if matches!(command_type(statement)?, CommandType::DDL) { MetaDataLock::Write(self.mdl.write_arc()) } else { @@ -314,7 +310,7 @@ impl Database { let transaction = Box::into_raw(Box::new(self.storage.transaction()?)); let (schema, executor) = self.state - .execute(unsafe { &mut (*transaction) }, statement, args)?; + .execute(unsafe { &mut (*transaction) }, statement, params)?; let inner = Box::into_raw(Box::new(TransactionIter::new(schema, executor))); Ok(DatabaseIter { transaction, inner }) } @@ -388,24 +384,24 @@ impl DBTransaction<'_, S> { pub fn run>(&mut self, sql: T) -> Result, DatabaseError> { let statement = self.state.prepare(sql)?; - self.execute(&statement, vec![]) + self.execute(&statement, &[]) } pub fn prepare>(&self, sql: T) -> Result { self.state.prepare(sql) } - pub fn execute( + pub fn execute>( &mut self, statement: &Statement, - args: Args, + params: A, ) -> Result { if matches!(command_type(statement)?, CommandType::DDL) { return Err(DatabaseError::UnsupportedStmt( "`DDL` is not allowed to execute within a transaction".to_string(), )); } - let (schema, executor) = self.state.execute(&mut self.inner, statement, args)?; + let (schema, executor) = self.state.execute(&mut self.inner, statement, params)?; Ok(TransactionIter::new(schema, executor)) } @@ -587,7 +583,7 @@ pub(crate) mod test { { let statement = fnck_sql.prepare("explain select * from t1 where b > ?1")?; - let mut iter = fnck_sql.execute(&statement, vec![("?1", DataValue::Int32(Some(0)))])?; + let mut iter = fnck_sql.execute(&statement, &[("?1", DataValue::Int32(Some(0)))])?; assert_eq!( iter.next().unwrap()?.values[0].utf8().unwrap(), @@ -604,7 +600,7 @@ pub(crate) mod test { let mut iter = fnck_sql.execute( &statement, - vec![ + &[ ("?1", DataValue::Int32(Some(0))), ("?2", DataValue::Int32(Some(0))), ("?3", DataValue::Int32(Some(1))), @@ -624,7 +620,7 @@ pub(crate) mod test { let mut iter = fnck_sql.execute( &statement, - vec![ + &[ ("?1", DataValue::Int32(Some(9))), ("?2", DataValue::Int32(Some(0))), ("?3", DataValue::Int32(Some(1))), diff --git a/src/optimizer/core/memo.rs b/src/optimizer/core/memo.rs index 82aa132..43dbe26 100644 --- a/src/optimizer/core/memo.rs +++ b/src/optimizer/core/memo.rs @@ -97,7 +97,6 @@ mod tests { use crate::types::value::DataValue; use crate::types::LogicalType; use petgraph::stable_graph::NodeIndex; - use std::cell::RefCell; use std::ops::Bound; use std::sync::atomic::AtomicUsize; use std::sync::Arc; @@ -131,7 +130,6 @@ mod tests { }; let scala_functions = Default::default(); let table_functions = Default::default(); - let args = RefCell::new(Vec::new()); let mut binder = Binder::new( BinderContext::new( database.state.table_cache(), @@ -141,7 +139,7 @@ mod tests { &table_functions, Arc::new(AtomicUsize::new(0)), ), - &args, + &[], None, ); // where: c1 => 2, (40, +inf) diff --git a/tpcc/src/delivery.rs b/tpcc/src/delivery.rs index 10a1b7e..0e13710 100644 --- a/tpcc/src/delivery.rs +++ b/tpcc/src/delivery.rs @@ -37,7 +37,7 @@ impl TpccTransaction for Delivery { let tuple = tx .execute( &statements[0], - vec![ + &[ ("?1", DataValue::Int8(Some(d_id as i8))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ], @@ -52,7 +52,7 @@ impl TpccTransaction for Delivery { // "DELETE FROM new_orders WHERE no_o_id = ? AND no_d_id = ? AND no_w_id = ?" tx.execute( &statements[1], - vec![ + &[ ("?1", DataValue::Int32(Some(no_o_id))), ("?2", DataValue::Int8(Some(d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), @@ -63,7 +63,7 @@ impl TpccTransaction for Delivery { let tuple = tx .execute( &statements[2], - vec![ + &[ ("?1", DataValue::Int32(Some(no_o_id))), ("?2", DataValue::Int8(Some(d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), @@ -75,7 +75,7 @@ impl TpccTransaction for Delivery { // "UPDATE orders SET o_carrier_id = ? WHERE o_id = ? AND o_d_id = ? AND o_w_id = ?" tx.execute( &statements[3], - vec![ + &[ ("?1", DataValue::Int8(Some(args.o_carrier_id as i8))), ("?2", DataValue::Int32(Some(no_o_id))), ("?3", DataValue::Int8(Some(d_id as i8))), @@ -86,7 +86,7 @@ impl TpccTransaction for Delivery { // "UPDATE order_line SET ol_delivery_d = ? WHERE ol_o_id = ? AND ol_d_id = ? AND ol_w_id = ?" tx.execute( &statements[4], - vec![ + &[ ("?1", DataValue::from(&now)), ("?2", DataValue::Int32(Some(no_o_id))), ("?3", DataValue::Int8(Some(d_id as i8))), @@ -98,7 +98,7 @@ impl TpccTransaction for Delivery { let tuple = tx .execute( &statements[5], - vec![ + &[ ("?1", DataValue::Int32(Some(no_o_id))), ("?2", DataValue::Int8(Some(d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), @@ -110,7 +110,7 @@ impl TpccTransaction for Delivery { // "UPDATE customer SET c_balance = c_balance + ? , c_delivery_cnt = c_delivery_cnt + 1 WHERE c_id = ? AND c_d_id = ? AND c_w_id = ?" tx.execute( &statements[6], - vec![ + &[ ("?1", DataValue::Decimal(Some(ol_total))), ("?2", DataValue::Int32(Some(c_id))), ("?3", DataValue::Int8(Some(d_id as i8))), diff --git a/tpcc/src/load.rs b/tpcc/src/load.rs index 8122393..f3c837c 100644 --- a/tpcc/src/load.rs +++ b/tpcc/src/load.rs @@ -16,7 +16,6 @@ pub(crate) const DIST_PER_WARE: usize = 10; pub(crate) const ORD_PER_DIST: usize = 3000; pub(crate) static MAX_NUM_ITEMS: usize = 15; -pub(crate) static MAX_ITEM_LEN: usize = 24; fn generate_string(rng: &mut ThreadRng, min: usize, max: usize) -> String { let chars: Vec = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" diff --git a/tpcc/src/main.rs b/tpcc/src/main.rs index 3ab4864..5c3f369 100644 --- a/tpcc/src/main.rs +++ b/tpcc/src/main.rs @@ -321,7 +321,6 @@ pub enum TpccError { #[ignore] #[test] fn explain_tpcc() -> Result<(), DatabaseError> { - use fnck_sql::db::ResultIter; use fnck_sql::types::tuple::create_table; let database = DataBaseBuilder::path("./fnck_sql_tpcc").build()?; diff --git a/tpcc/src/new_ord.rs b/tpcc/src/new_ord.rs index 9af9c22..b1ece09 100644 --- a/tpcc/src/new_ord.rs +++ b/tpcc/src/new_ord.rs @@ -71,7 +71,7 @@ impl TpccTransaction for NewOrd { let tuple = tx .execute( &statements[0], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ("?3", DataValue::Int8(Some(args.d_id as i8))), @@ -91,7 +91,7 @@ impl TpccTransaction for NewOrd { let tuple = tx .execute( &statements[1], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int32(Some(args.c_id as i32))), @@ -106,7 +106,7 @@ impl TpccTransaction for NewOrd { let tuple = tx .execute( &statements[2], - vec![("?1", DataValue::Int16(Some(args.w_id as i16)))], + &[("?1", DataValue::Int16(Some(args.w_id as i16)))], )? .next() .unwrap()?; @@ -118,7 +118,7 @@ impl TpccTransaction for NewOrd { let tuple = tx .execute( &statements[3], - vec![ + &[ ("?1", DataValue::Int8(Some(args.d_id as i8))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ], @@ -130,7 +130,7 @@ impl TpccTransaction for NewOrd { // "UPDATE district SET d_next_o_id = ? + 1 WHERE d_id = ? AND d_w_id = ?" tx.execute( &statements[4], - vec![ + &[ ("?1", DataValue::Int32(Some(d_next_o_id))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), @@ -141,7 +141,7 @@ impl TpccTransaction for NewOrd { // "INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) VALUES(?, ?, ?, ?, ?, ?, ?)" tx.execute( &statements[5], - vec![ + &[ ("?1", DataValue::Int32(Some(o_id))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), @@ -155,7 +155,7 @@ impl TpccTransaction for NewOrd { // "INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) VALUES (?,?,?) tx.execute( &statements[6], - vec![ + &[ ("?1", DataValue::Int32(Some(o_id))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int16(Some(args.w_id as i16))), diff --git a/tpcc/src/order_stat.rs b/tpcc/src/order_stat.rs index 5f81e07..47f3e02 100644 --- a/tpcc/src/order_stat.rs +++ b/tpcc/src/order_stat.rs @@ -50,7 +50,7 @@ impl TpccTransaction for OrderStat { let tuple = tx .execute( &statements[0], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::from(args.c_last.clone())), @@ -62,7 +62,7 @@ impl TpccTransaction for OrderStat { // SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_first" let mut tuple_iter = tx.execute( &statements[1], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::from(args.c_last.clone())), @@ -91,7 +91,7 @@ impl TpccTransaction for OrderStat { let tuple = tx .execute( &statements[2], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int32(Some(args.c_id as i32))), @@ -110,7 +110,7 @@ impl TpccTransaction for OrderStat { let tuple = tx .execute( &statements[3], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int32(Some(args.c_id as i32))), @@ -131,7 +131,7 @@ impl TpccTransaction for OrderStat { let tuple = tx .execute( &statements[4], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int32(Some(o_id))), diff --git a/tpcc/src/payment.rs b/tpcc/src/payment.rs index 449e940..f1edf10 100644 --- a/tpcc/src/payment.rs +++ b/tpcc/src/payment.rs @@ -61,7 +61,7 @@ impl TpccTransaction for Payment { // "UPDATE warehouse SET w_ytd = w_ytd + ? WHERE w_id = ?" tx.execute( &statements[0], - vec![ + &[ ("?1", DataValue::Decimal(Some(args.h_amount))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ], @@ -71,7 +71,7 @@ impl TpccTransaction for Payment { let tuple = tx .execute( &statements[1], - vec![("?1", DataValue::Int16(Some(args.w_id as i16)))], + &[("?1", DataValue::Int16(Some(args.w_id as i16)))], )? .next() .unwrap()?; @@ -85,7 +85,7 @@ impl TpccTransaction for Payment { // "UPDATE district SET d_ytd = d_ytd + ? WHERE d_w_id = ? AND d_id = ?" tx.execute( &statements[2], - vec![ + &[ ("?1", DataValue::Decimal(Some(args.h_amount))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ("?3", DataValue::Int8(Some(args.d_id as i8))), @@ -97,7 +97,7 @@ impl TpccTransaction for Payment { let tuple = tx .execute( &statements[3], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ], @@ -117,7 +117,7 @@ impl TpccTransaction for Payment { let tuple = tx .execute( &statements[4], - vec![ + &[ ("?1", DataValue::Int16(Some(args.c_w_id as i16))), ("?2", DataValue::Int8(Some(args.c_d_id as i8))), ("?3", DataValue::from(args.c_last.clone())), @@ -130,7 +130,7 @@ impl TpccTransaction for Payment { // "SELECT c_id FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_first" let mut tuple_iter = tx.execute( &statements[5], - vec![ + &[ ("?1", DataValue::Int16(Some(args.c_w_id as i16))), ("?2", DataValue::Int8(Some(args.c_d_id as i8))), ("?3", DataValue::from(args.c_last.clone())), @@ -148,7 +148,7 @@ impl TpccTransaction for Payment { let tuple = tx .execute( &statements[6], - vec![ + &[ ("?1", DataValue::Int16(Some(args.c_w_id as i16))), ("?2", DataValue::Int8(Some(args.c_d_id as i8))), ("?3", DataValue::Int32(Some(c_id))), @@ -178,7 +178,7 @@ impl TpccTransaction for Payment { let tuple = tx .execute( &statements[7], - vec![ + &[ ("?1", DataValue::Int16(Some(args.c_w_id as i16))), ("?2", DataValue::Int8(Some(args.c_d_id as i8))), ("?3", DataValue::Int32(Some(c_id))), @@ -194,7 +194,7 @@ impl TpccTransaction for Payment { // "UPDATE customer SET c_balance = ?, c_data = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?" tx.execute( &statements[8], - vec![ + &[ ("?1", DataValue::Decimal(Some(c_balance))), ("?2", DataValue::from(c_data)), ("?3", DataValue::Int16(Some(args.c_w_id as i16))), @@ -207,7 +207,7 @@ impl TpccTransaction for Payment { // "UPDATE customer SET c_balance = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?" tx.execute( &statements[9], - vec![ + &[ ("?1", DataValue::Decimal(Some(c_balance))), ("?2", DataValue::Int16(Some(args.c_w_id as i16))), ("?3", DataValue::Int8(Some(args.c_d_id as i8))), @@ -220,7 +220,7 @@ impl TpccTransaction for Payment { // "UPDATE customer SET c_balance = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?" tx.execute( &statements[9], - vec![ + &[ ("?1", DataValue::Decimal(Some(c_balance))), ("?2", DataValue::Int16(Some(args.c_w_id as i16))), ("?3", DataValue::Int8(Some(args.c_d_id as i8))), @@ -233,7 +233,7 @@ impl TpccTransaction for Payment { // "INSERT INTO history(h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES(?, ?, ?, ?, ?, ?, ?, ?)" tx.execute( &statements[10], - vec![ + &[ ("?1", DataValue::Int8(Some(args.c_d_id as i8))), ("?2", DataValue::Int16(Some(args.c_w_id as i16))), ("?3", DataValue::Int32(Some(c_id))), diff --git a/tpcc/src/slev.rs b/tpcc/src/slev.rs index 55b7565..76d69a8 100644 --- a/tpcc/src/slev.rs +++ b/tpcc/src/slev.rs @@ -34,7 +34,7 @@ impl TpccTransaction for Slev { let tuple = tx .execute( &statements[0], - vec![ + &[ ("?1", DataValue::Int8(Some(args.d_id as i8))), ("?2", DataValue::Int16(Some(args.w_id as i16))), ], @@ -46,7 +46,7 @@ impl TpccTransaction for Slev { let tuple = tx .execute( &statements[1], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(args.d_id as i8))), ("?3", DataValue::Int32(Some(d_next_o_id))), @@ -60,7 +60,7 @@ impl TpccTransaction for Slev { let tuple = tx .execute( &statements[2], - vec![ + &[ ("?1", DataValue::Int16(Some(args.w_id as i16))), ("?2", DataValue::Int8(Some(ol_i_id as i8))), ("?3", DataValue::Int16(Some(args.level as i16))),