From 7e7bb74c89d90c9cfc18d4429482109085ea1e52 Mon Sep 17 00:00:00 2001 From: kould Date: Mon, 12 Jan 2026 02:07:06 +0800 Subject: [PATCH] chore: codefmt --- .github/workflows/ci.yml | 40 +++++------------- Makefile | 34 ++++++++++++--- benchmarks/query_benchmark.rs | 24 +++++------ src/bin/server.rs | 11 +++-- src/binder/create_table.rs | 4 +- src/binder/mod.rs | 2 +- src/binder/select.rs | 18 ++++---- src/catalog/table.rs | 10 ++--- src/db.rs | 2 +- src/execution/dml/copy_from_file.rs | 2 +- src/execution/dml/copy_to_file.rs | 4 +- src/execution/dql/join/nested_loop_join.rs | 2 +- src/execution/dql/sort.rs | 2 +- src/execution/dql/top_k.rs | 26 ++++++------ src/expression/range_detacher.rs | 1 + src/optimizer/core/cm_sketch.rs | 2 +- src/optimizer/core/histogram.rs | 22 +++++----- src/optimizer/core/memo.rs | 2 +- .../rule/normalization/pushdown_predicates.rs | 2 +- .../rule/normalization/simplification.rs | 2 +- src/storage/memory.rs | 8 ++-- src/storage/mod.rs | 14 +++---- src/storage/rocksdb.rs | 11 ++--- src/storage/table_codec.rs | 28 +++++++------ src/types/tuple.rs | 2 +- src/types/value.rs | 16 +++---- tpcc/src/main.rs | 42 +++++++++++++++++++ 27 files changed, 192 insertions(+), 141 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6175e800..cc0f3e4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,22 +29,15 @@ jobs: # as it is set as an "override" for current directory - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - command: check + run: make cargo-check - name: Run cargo build - uses: actions-rs/cargo@v1 - with: - command: build + run: make build - name: Run cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --all + run: make test # 2 fmt: name: Rust fmt @@ -62,10 +55,7 @@ jobs: # as it is set as an "override" for current directory - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: make fmt # 3 e2e: name: Rust e2e sqllogictest @@ -85,11 +75,8 @@ jobs: # `cargo check` command here will use installed `nightly` # as it is set as an "override" for current directory - - name: Run cargo run sqllogictest-test - uses: actions-rs/cargo@v1 - with: - command: run - args: --bin sqllogictest-test --manifest-path ./tests/sqllogictest/Cargo.toml + - name: Run sqllogictest suite + run: make test-slt # 4 wasm-tests: name: Wasm cargo tests @@ -115,7 +102,7 @@ jobs: version: latest - name: Run wasm-bindgen tests (wasm32 target) - run: wasm-pack test --node -- --package kite_sql --lib + run: make test-wasm # 5 wasm-examples: name: Wasm examples (nodejs) @@ -141,12 +128,10 @@ jobs: version: latest - name: Build wasm package - run: wasm-pack build --release --target nodejs + run: make wasm-build - name: Run wasm example scripts - run: | - node examples/wasm_hello_world.test.mjs - node examples/wasm_index_usage.test.mjs + run: make wasm-examples # 6 native-examples: name: Native examples @@ -160,8 +145,5 @@ jobs: toolchain: stable override: true - - name: Run hello_world example - run: cargo run --example hello_world - - - name: Run transaction example - run: cargo run --example transaction + - name: Run native examples + run: make native-examples diff --git a/Makefile b/Makefile index b2ad2df3..1cfedbd4 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,19 @@ CARGO ?= cargo WASM_PACK ?= wasm-pack SQLLOGIC_PATH ?= tests/slt/**/*.slt -.PHONY: test test-wasm test-slt test-all wasm-build check tpcc +.PHONY: test test-wasm test-slt test-all wasm-build check tpcc cargo-check build wasm-examples native-examples fmt clippy ## Run default Rust tests in the current environment (non-WASM). test: - $(CARGO) test + $(CARGO) test --all + +## Perform a `cargo check` across the workspace. +cargo-check: + $(CARGO) check + +## Build the workspace artifacts (debug). +build: + $(CARGO) build ## Build the WebAssembly package (artifact goes to ./pkg). wasm-build: @@ -15,7 +23,7 @@ wasm-build: ## Execute wasm-bindgen tests under Node.js (wasm32 target). test-wasm: - $(WASM_PACK) test --node --release + $(WASM_PACK) test --node -- --package kite_sql --lib ## Run the sqllogictest harness against the configured .slt suite. test-slt: @@ -24,11 +32,27 @@ test-slt: ## Convenience target to run every suite in sequence. test-all: test test-wasm test-slt -## Run formatting (check mode) and clippy linting together. -check: +## Run formatting (check mode) across the workspace. +fmt: $(CARGO) fmt --all -- --check + +## Execute clippy across all targets/features with warnings elevated to errors. +clippy: $(CARGO) clippy --all-targets --all-features -- -D warnings +## Run formatting (check mode) and clippy linting together. +check: fmt clippy + ## Execute the TPCC workload example as a standalone command. tpcc: $(CARGO) run -p tpcc --release + +## Run JavaScript-based Wasm example scripts. +wasm-examples: + node examples/wasm_hello_world.test.mjs + node examples/wasm_index_usage.test.mjs + +## Run the native (non-Wasm) example binaries. +native-examples: + $(CARGO) run --example hello_world + $(CARGO) run --example transaction diff --git a/benchmarks/query_benchmark.rs b/benchmarks/query_benchmark.rs index 79093863..3d730b33 100644 --- a/benchmarks/query_benchmark.rs +++ b/benchmarks/query_benchmark.rs @@ -22,8 +22,8 @@ use sqlite::Error; use std::fs; use std::path::Path; -const QUERY_BENCH_KITE_SQL_PATH: &'static str = "./kitesql_bench"; -const QUERY_BENCH_SQLITE_PATH: &'static str = "./sqlite_bench"; +const QUERY_BENCH_KITE_SQL_PATH: &str = "./kitesql_bench"; +const QUERY_BENCH_SQLITE_PATH: &str = "./sqlite_bench"; const TABLE_ROW_NUM: u64 = 200_000; fn query_cases() -> Vec<(&'static str, &'static str)> { @@ -62,9 +62,9 @@ fn init_kitesql_query_bench() -> Result<(), DatabaseError> { } fn init_sqlite_query_bench() -> Result<(), Error> { - let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH.to_owned())?; + let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH)?; - let _ = connection.execute("create table t1 (c1 int primary key, c2 int)")?; + connection.execute("create table t1 (c1 int primary key, c2 int)")?; let pb = ProgressBar::new(TABLE_ROW_NUM); pb.set_style( @@ -73,7 +73,7 @@ fn init_sqlite_query_bench() -> Result<(), Error> { .unwrap(), ); for i in 0..TABLE_ROW_NUM { - let _ = connection.execute(format!("insert into t1 values({}, {})", i, i + 1))?; + connection.execute(format!("insert into t1 values({i}, {})", i + 1).as_str())?; pb.set_position(i + 1); } pb.finish_with_message("Insert completed!"); @@ -91,16 +91,14 @@ fn path_exists_and_is_directory(path: &str) -> bool { fn query_on_execute(c: &mut Criterion) { if !Path::new(QUERY_BENCH_SQLITE_PATH).exists() { println!( - "SQLITE: The table is not initialized and data insertion is started. => {}", - TABLE_ROW_NUM + "SQLITE: The table is not initialized and data insertion is started. => {TABLE_ROW_NUM}" ); init_sqlite_query_bench().unwrap(); } if !path_exists_and_is_directory(QUERY_BENCH_KITE_SQL_PATH) { println!( - "KiteSQL: The table is not initialized and data insertion is started. => {}", - TABLE_ROW_NUM + "KiteSQL: The table is not initialized and data insertion is started. => {TABLE_ROW_NUM}" ); init_kitesql_query_bench().unwrap(); @@ -111,7 +109,8 @@ fn query_on_execute(c: &mut Criterion) { println!("Table initialization completed"); for (name, case) in query_cases() { - c.bench_function(format!("KiteSQL: {} by '{}'", name, case).as_str(), |b| { + let kite_label = format!("KiteSQL: {name} by '{case}'"); + c.bench_function(&kite_label, |b| { b.iter(|| { for tuple in database.run(case).unwrap() { let _ = tuple.unwrap(); @@ -119,8 +118,9 @@ fn query_on_execute(c: &mut Criterion) { }) }); - let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH.to_owned()).unwrap(); - c.bench_function(format!("SQLite: {} by '{}'", name, case).as_str(), |b| { + let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH).unwrap(); + let sqlite_label = format!("SQLite: {name} by '{case}'"); + c.bench_function(&sqlite_label, |b| { b.iter(|| { for row in connection.prepare(case).unwrap() { let _ = row.unwrap(); diff --git a/src/bin/server.rs b/src/bin/server.rs index 1e7edc38..a83c291a 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -18,7 +18,7 @@ use futures::stream; use kite_sql::db::{DBTransaction, DataBaseBuilder, Database, ResultIter}; use kite_sql::errors::DatabaseError; use kite_sql::storage::rocksdb::RocksStorage; -use kite_sql::types::tuple::{Schema, SchemaRef, Tuple}; +use kite_sql::types::tuple::{SchemaRef, Tuple}; use kite_sql::types::LogicalType; use log::{error, info, LevelFilter}; use parking_lot::Mutex; @@ -172,7 +172,10 @@ impl SimpleQueryHandler for SessionBackend { .map_err(|e| PgWireError::ApiError(Box::new(e)))?; guard.replace(TransactionPtr( Box::leak(Box::>::new(unsafe { - transmute(transaction) + transmute::< + DBTransaction<'_, RocksStorage>, + DBTransaction<'static, RocksStorage>, + >(transaction) })) .into(), )); @@ -371,7 +374,7 @@ async fn main() { tokio::select! { res = server_run(listener,factory) => { if let Err(err) = res { - error!("[Listener][Failed To Accept]: {}", err); + error!("[Listener][Failed To Accept]: {err}"); } } _ = quit() => info!("Bye!") @@ -388,7 +391,7 @@ async fn server_run( tokio::spawn(async move { if let Err(err) = process_socket(incoming_socket.0, None, factory_ref).await { - error!("Failed To Process: {}", err); + error!("Failed To Process: {err}"); } }); } diff --git a/src/binder/create_table.rs b/src/binder/create_table.rs index dc09b002..e22ab879 100644 --- a/src/binder/create_table.rs +++ b/src/binder/create_table.rs @@ -212,13 +212,13 @@ mod tests { Operator::CreateTable(op) => { assert_eq!(op.table_name.as_ref(), "t1"); assert_eq!(op.columns[0].name(), "id"); - assert_eq!(op.columns[0].nullable(), false); + assert!(!op.columns[0].nullable()); assert_eq!( op.columns[0].desc(), &ColumnDesc::new(LogicalType::Integer, Some(0), false, None)? ); assert_eq!(op.columns[1].name(), "name"); - assert_eq!(op.columns[1].nullable(), true); + assert!(op.columns[1].nullable()); assert_eq!( op.columns[1].desc(), &ColumnDesc::new( diff --git a/src/binder/mod.rs b/src/binder/mod.rs index 96bcf0c3..e7afb0fe 100644 --- a/src/binder/mod.rs +++ b/src/binder/mod.rs @@ -581,7 +581,7 @@ pub mod test { ); let stmt = crate::parser::parse_sql(sql)?; - Ok(binder.bind(&stmt[0])?) + binder.bind(&stmt[0]) } pub(crate) fn column_id_by_name(&self, name: &str) -> &ColumnId { diff --git a/src/binder/select.rs b/src/binder/select.rs index bd4bf4b6..9d2381c5 100644 --- a/src/binder/select.rs +++ b/src/binder/select.rs @@ -1213,27 +1213,27 @@ mod tests { let table_states = build_t1_table()?; let plan_1 = table_states.plan("select * from t1")?; - println!("just_col:\n {:#?}", plan_1); + println!("just_col:\n {plan_1:#?}"); let plan_2 = table_states.plan("select t1.c1, t1.c2 from t1")?; - println!("table_with_col:\n {:#?}", plan_2); + println!("table_with_col:\n {plan_2:#?}"); let plan_3 = table_states.plan("select t1.c1, t1.c2 from t1 where c1 > 2")?; - println!("table_with_col_and_c1_compare_constant:\n {:#?}", plan_3); + println!("table_with_col_and_c1_compare_constant:\n {plan_3:#?}"); let plan_4 = table_states.plan("select t1.c1, t1.c2 from t1 where c1 > c2")?; - println!("table_with_col_and_c1_compare_c2:\n {:#?}", plan_4); + println!("table_with_col_and_c1_compare_c2:\n {plan_4:#?}"); let plan_5 = table_states.plan("select avg(t1.c1) from t1")?; - println!("table_with_col_and_c1_avg:\n {:#?}", plan_5); + println!("table_with_col_and_c1_avg:\n {plan_5:#?}"); let plan_6 = table_states.plan("select t1.c1, t1.c2 from t1 where (t1.c1 - t1.c2) > 1")?; - println!("table_with_col_nested:\n {:#?}", plan_6); + println!("table_with_col_nested:\n {plan_6:#?}"); let plan_7 = table_states.plan("select * from t1 limit 1")?; - println!("limit:\n {:#?}", plan_7); + println!("limit:\n {plan_7:#?}"); let plan_8 = table_states.plan("select * from t1 offset 2")?; - println!("offset:\n {:#?}", plan_8); + println!("offset:\n {plan_8:#?}"); let plan_9 = table_states.plan("select c1, c3 from t1 inner join t2 on c1 = c3 and c1 > 1")?; - println!("join:\n {:#?}", plan_9); + println!("join:\n {plan_9:#?}"); Ok(()) } diff --git a/src/catalog/table.rs b/src/catalog/table.rs index d5e3f05b..d024c825 100644 --- a/src/catalog/table.rs +++ b/src/catalog/table.rs @@ -309,19 +309,19 @@ mod tests { let col_catalogs = vec![col0, col1]; let table_catalog = TableCatalog::new("test".to_string().into(), col_catalogs).unwrap(); - assert_eq!(table_catalog.contains_column("a"), true); - assert_eq!(table_catalog.contains_column("b"), true); - assert_eq!(table_catalog.contains_column("c"), false); + assert!(table_catalog.contains_column("a")); + assert!(table_catalog.contains_column("b")); + assert!(!table_catalog.contains_column("c")); let col_a_id = table_catalog.get_column_id_by_name("a").unwrap(); let col_b_id = table_catalog.get_column_id_by_name("b").unwrap(); assert!(col_a_id < col_b_id); - let column_catalog = table_catalog.get_column_by_id(&col_a_id).unwrap(); + let column_catalog = table_catalog.get_column_by_id(col_a_id).unwrap(); assert_eq!(column_catalog.name(), "a"); assert_eq!(*column_catalog.datatype(), LogicalType::Integer,); - let column_catalog = table_catalog.get_column_by_id(&col_b_id).unwrap(); + let column_catalog = table_catalog.get_column_by_id(col_b_id).unwrap(); assert_eq!(column_catalog.name(), "b"); assert_eq!(*column_catalog.datatype(), LogicalType::Boolean,); } diff --git a/src/db.rs b/src/db.rs index 657a55e2..cc2c1546 100644 --- a/src/db.rs +++ b/src/db.rs @@ -544,7 +544,7 @@ pub(crate) mod test { let database = DataBaseBuilder::path(temp_dir.path()).build()?; let mut transaction = database.storage.transaction()?; - build_table(&database.state.table_cache(), &mut transaction)?; + build_table(database.state.table_cache(), &mut transaction)?; transaction.commit()?; for result in database.run("select * from t1")? { diff --git a/src/execution/dml/copy_from_file.rs b/src/execution/dml/copy_from_file.rs index 4a9797a5..e213826e 100644 --- a/src/execution/dml/copy_from_file.rs +++ b/src/execution/dml/copy_from_file.rs @@ -161,7 +161,7 @@ mod tests { let csv = "1,1.5,one\n2,2.5,two\n"; let mut file = tempfile::NamedTempFile::new().expect("failed to create temp file"); - write!(file, "{}", csv).expect("failed to write file"); + write!(file, "{csv}").expect("failed to write file"); let columns = vec![ ColumnRef::from(ColumnCatalog::direct_new( diff --git a/src/execution/dml/copy_to_file.rs b/src/execution/dml/copy_to_file.rs index ea6e3272..1ffaa000 100644 --- a/src/execution/dml/copy_to_file.rs +++ b/src/execution/dml/copy_to_file.rs @@ -190,7 +190,7 @@ mod tests { let storage = db.storage; let mut transaction = storage.transaction()?; let table = transaction - .table(&db.state.table_cache(), "t1".to_string().into())? + .table(db.state.table_cache(), "t1".to_string().into())? .unwrap(); let executor = CopyToFile { @@ -224,7 +224,7 @@ mod tests { assert!(records.next().is_none()); - assert_eq!(tuple, TupleBuilder::build_result(format!("{}", op))); + assert_eq!(tuple, TupleBuilder::build_result(format!("{op}"))); Ok(()) } diff --git a/src/execution/dql/join/nested_loop_join.rs b/src/execution/dql/join/nested_loop_join.rs index 792cbc86..587e445c 100644 --- a/src/execution/dql/join/nested_loop_join.rs +++ b/src/execution/dql/join/nested_loop_join.rs @@ -1058,7 +1058,7 @@ mod test { )?; let mut actual = Vec::new(); - while let Some(row) = iter.next() { + for row in iter.by_ref() { let tuple = row?; actual.push(tuple_to_strings(&tuple)); } diff --git a/src/execution/dql/sort.rs b/src/execution/dql/sort.rs index 0668c07d..83e1e6e1 100644 --- a/src/execution/dql/sort.rs +++ b/src/execution/dql/sort.rs @@ -519,7 +519,7 @@ mod test { fn_desc_and_nulls_last_eq(SortBy::Fast.sorted_tuples( &arena, &schema, - &&fn_sort_fields(false, false), + &fn_sort_fields(false, false), fn_tuples(), )?); diff --git a/src/execution/dql/top_k.rs b/src/execution/dql/top_k.rs index cd86649e..6f34b02a 100644 --- a/src/execution/dql/top_k.rs +++ b/src/execution/dql/top_k.rs @@ -168,6 +168,7 @@ impl<'a, T: Transaction + 'a> ReadExecutor<'a, T> for TopK { } #[cfg(all(test, not(target_arch = "wasm32")))] +#[allow(clippy::mutable_key_type)] mod test { use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRef}; use crate::errors::DatabaseError; @@ -259,7 +260,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, true), + &fn_sort_fields(true, true), &mut indices, Tuple::new(None, vec![DataValue::Null]), 2, @@ -267,7 +268,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, true), + &fn_sort_fields(true, true), &mut indices, Tuple::new(None, vec![DataValue::Int32(0)]), 2, @@ -275,12 +276,11 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, true), + &fn_sort_fields(true, true), &mut indices, Tuple::new(None, vec![DataValue::Int32(1)]), 2, )?; - println!("{:#?}", indices); fn_asc_and_nulls_first_eq(indices); let mut indices = BTreeSet::new(); @@ -288,7 +288,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, false), + &fn_sort_fields(true, false), &mut indices, Tuple::new(None, vec![DataValue::Null]), 2, @@ -296,7 +296,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, false), + &fn_sort_fields(true, false), &mut indices, Tuple::new(None, vec![DataValue::Int32(0)]), 2, @@ -304,7 +304,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(true, false), + &fn_sort_fields(true, false), &mut indices, Tuple::new(None, vec![DataValue::Int32(1)]), 2, @@ -316,7 +316,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, true), + &fn_sort_fields(false, true), &mut indices, Tuple::new(None, vec![DataValue::Null]), 2, @@ -324,7 +324,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, true), + &fn_sort_fields(false, true), &mut indices, Tuple::new(None, vec![DataValue::Int32(0)]), 2, @@ -332,7 +332,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, true), + &fn_sort_fields(false, true), &mut indices, Tuple::new(None, vec![DataValue::Int32(1)]), 2, @@ -344,7 +344,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, false), + &fn_sort_fields(false, false), &mut indices, Tuple::new(None, vec![DataValue::Null]), 2, @@ -352,7 +352,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, false), + &fn_sort_fields(false, false), &mut indices, Tuple::new(None, vec![DataValue::Int32(0)]), 2, @@ -360,7 +360,7 @@ mod test { top_sort( &arena, &schema, - &*fn_sort_fields(false, false), + &fn_sort_fields(false, false), &mut indices, Tuple::new(None, vec![DataValue::Int32(1)]), 2, diff --git a/src/expression/range_detacher.rs b/src/expression/range_detacher.rs index 0dffbbd9..edb99842 100644 --- a/src/expression/range_detacher.rs +++ b/src/expression/range_detacher.rs @@ -801,6 +801,7 @@ impl fmt::Display for Range { } #[cfg(all(test, not(target_arch = "wasm32")))] +#[allow(clippy::uninlined_format_args)] mod test { use crate::binder::test::build_t1_table; use crate::errors::DatabaseError; diff --git a/src/optimizer/core/cm_sketch.rs b/src/optimizer/core/cm_sketch.rs index 928d25a0..2f1eaa7a 100644 --- a/src/optimizer/core/cm_sketch.rs +++ b/src/optimizer/core/cm_sketch.rs @@ -246,7 +246,7 @@ mod tests { cms.increment(&DataValue::Int32(300)); } assert_eq!( - cms.collect_count(&vec![ + cms.collect_count(&[ Range::Eq(DataValue::Int32(300)), Range::Scope { min: Bound::Unbounded, diff --git a/src/optimizer/core/histogram.rs b/src/optimizer/core/histogram.rs index 5d7eff19..b0ba4c40 100644 --- a/src/optimizer/core/histogram.rs +++ b/src/optimizer/core/histogram.rs @@ -762,7 +762,7 @@ mod tests { let (histogram, sketch) = builder.build(4)?; let count_1 = histogram.collect_count( - &vec![ + &[ Range::Eq(DataValue::Int32(2)), Range::Scope { min: Bound::Included(DataValue::Int32(4)), @@ -775,7 +775,7 @@ mod tests { assert_eq!(count_1, 9); let count_2 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Included(DataValue::Int32(4)), max: Bound::Unbounded, }], @@ -785,7 +785,7 @@ mod tests { assert_eq!(count_2, 11); let count_3 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Excluded(DataValue::Int32(7)), max: Bound::Unbounded, }], @@ -795,7 +795,7 @@ mod tests { assert_eq!(count_3, 7); let count_4 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Unbounded, max: Bound::Included(DataValue::Int32(11)), }], @@ -805,7 +805,7 @@ mod tests { assert_eq!(count_4, 12); let count_5 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Unbounded, max: Bound::Excluded(DataValue::Int32(8)), }], @@ -815,7 +815,7 @@ mod tests { assert_eq!(count_5, 8); let count_6 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Included(DataValue::Int32(2)), max: Bound::Unbounded, }], @@ -825,7 +825,7 @@ mod tests { assert_eq!(count_6, 13); let count_7 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Excluded(DataValue::Int32(1)), max: Bound::Unbounded, }], @@ -835,7 +835,7 @@ mod tests { assert_eq!(count_7, 13); let count_8 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Unbounded, max: Bound::Included(DataValue::Int32(12)), }], @@ -845,7 +845,7 @@ mod tests { assert_eq!(count_8, 13); let count_9 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Unbounded, max: Bound::Excluded(DataValue::Int32(13)), }], @@ -855,7 +855,7 @@ mod tests { assert_eq!(count_9, 13); let count_10 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Excluded(DataValue::Int32(0)), max: Bound::Excluded(DataValue::Int32(3)), }], @@ -865,7 +865,7 @@ mod tests { assert_eq!(count_10, 2); let count_11 = histogram.collect_count( - &vec![Range::Scope { + &[Range::Scope { min: Bound::Included(DataValue::Int32(1)), max: Bound::Included(DataValue::Int32(2)), }], diff --git a/src/optimizer/core/memo.rs b/src/optimizer/core/memo.rs index 0543ec10..d6277182 100644 --- a/src/optimizer/core/memo.rs +++ b/src/optimizer/core/memo.rs @@ -174,7 +174,7 @@ mod tests { .done()?; for i in 0..1000 { - let _ = database + database .run(format!("insert into t1 values({}, {})", i, i + 1).as_str())? .done()?; } diff --git a/src/optimizer/rule/normalization/pushdown_predicates.rs b/src/optimizer/rule/normalization/pushdown_predicates.rs index f1ccdcb4..d934810e 100644 --- a/src/optimizer/rule/normalization/pushdown_predicates.rs +++ b/src/optimizer/rule/normalization/pushdown_predicates.rs @@ -567,7 +567,7 @@ mod tests { c1_ref.datatype().serializable(), "last serializer should align with c1" ); - let mapping = reordered_index.cover_mapping.as_ref().map(|m| m.as_slice()); + let mapping = reordered_index.cover_mapping.as_deref(); assert_eq!(mapping, Some(&[2, 0][..])); // verify the second index matches scan order exactly so mapping is omitted diff --git a/src/optimizer/rule/normalization/simplification.rs b/src/optimizer/rule/normalization/simplification.rs index 6ac9a856..8b764a7e 100644 --- a/src/optimizer/rule/normalization/simplification.rs +++ b/src/optimizer/rule/normalization/simplification.rs @@ -342,7 +342,7 @@ mod test { let filter_op = best_plan.childrens.pop_only(); if let Operator::Filter(filter_op) = filter_op.operator { - Ok(RangeDetacher::new("t1", &column_id).detach(&filter_op.predicate)?) + Ok(RangeDetacher::new("t1", column_id).detach(&filter_op.predicate)?) } else { Ok(None) } diff --git a/src/storage/memory.rs b/src/storage/memory.rs index 66fd625e..bc2848ca 100644 --- a/src/storage/memory.rs +++ b/src/storage/memory.rs @@ -160,7 +160,7 @@ mod wasm_tests { )?; transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(1)), vec![DataValue::Int32(1), DataValue::Boolean(true)], @@ -172,7 +172,7 @@ mod wasm_tests { false, )?; transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(2)), vec![DataValue::Int32(2), DataValue::Boolean(true)], @@ -293,7 +293,7 @@ mod native_tests { )?; transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(1)), vec![DataValue::Int32(1), DataValue::Boolean(true)], @@ -305,7 +305,7 @@ mod native_tests { false, )?; transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(2)), vec![DataValue::Int32(2), DataValue::Boolean(true)], diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 0be65d38..2d1aebec 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1516,7 +1516,7 @@ mod test { table_cache: &TableCache| -> Result<(), DatabaseError> { let table = transaction - .table(&table_cache, "t1".to_string().into())? + .table(table_cache, "t1".to_string().into())? .unwrap(); let c1_column_id = *table.get_column_id_by_name("c1").unwrap(); let c2_column_id = *table.get_column_id_by_name("c2").unwrap(); @@ -1538,7 +1538,7 @@ mod test { let mut column_iter = table.columns(); let c1_column = column_iter.next().unwrap(); - assert_eq!(c1_column.nullable(), false); + assert!(!c1_column.nullable()); assert_eq!( c1_column.summary(), &ColumnSummary { @@ -1556,7 +1556,7 @@ mod test { ); let c2_column = column_iter.next().unwrap(); - assert_eq!(c2_column.nullable(), false); + assert!(!c2_column.nullable()); assert_eq!( c2_column.summary(), &ColumnSummary { @@ -1574,7 +1574,7 @@ mod test { ); let c3_column = column_iter.next().unwrap(); - assert_eq!(c3_column.nullable(), false); + assert!(!c3_column.nullable()); assert_eq!( c3_column.summary(), &ColumnSummary { @@ -1715,7 +1715,7 @@ mod test { table_cache: &TableCache| -> Result<(), DatabaseError> { let table = transaction - .table(&table_cache, "t1".to_string().into())? + .table(table_cache, "t1".to_string().into())? .unwrap(); let i1_meta = table.indexes[1].clone(); @@ -1791,7 +1791,7 @@ mod test { index_column_id: ColumnId, ) -> Result>, DatabaseError> { transaction.read_by_index( - &table_cache, + table_cache, "t1".to_string().into(), (None, None), full_columns(), @@ -1835,7 +1835,7 @@ mod test { )?; let tuples = build_tuples(); - let indexes = vec![ + let indexes = [ ( Arc::new(DataValue::Int32(0)), Index::new(1, &tuples[0].values[2], IndexType::Normal), diff --git a/src/storage/rocksdb.rs b/src/storage/rocksdb.rs index 1e21ad29..33ac2340 100644 --- a/src/storage/rocksdb.rs +++ b/src/storage/rocksdb.rs @@ -278,7 +278,7 @@ mod test { let source_columns = columns .iter() - .map(|col_ref| ColumnCatalog::clone(&col_ref)) + .map(|col_ref| ColumnCatalog::clone(col_ref)) .collect_vec(); let _ = transaction.create_table( &table_cache, @@ -289,13 +289,10 @@ mod test { let table_catalog = transaction.table(&table_cache, "test".to_string().into())?; assert!(table_catalog.is_some()); - assert!(table_catalog - .unwrap() - .get_column_id_by_name(&"c1".to_string()) - .is_some()); + assert!(table_catalog.unwrap().get_column_id_by_name("c1").is_some()); transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(1)), vec![DataValue::Int32(1), DataValue::Boolean(true)], @@ -307,7 +304,7 @@ mod test { false, )?; transaction.append_tuple( - &"test".to_string(), + "test", Tuple::new( Some(DataValue::Int32(2)), vec![DataValue::Int32(2), DataValue::Boolean(true)], diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index dc14e5e4..5708461f 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -681,7 +681,7 @@ mod tests { name: "index_1".to_string(), ty: IndexType::PrimaryKey { is_multiple: false }, }; - let (_, bytes) = table_codec.encode_index_meta(&"T1".to_string(), &index_meta)?; + let (_, bytes) = table_codec.encode_index_meta("T1", &index_meta)?; assert_eq!( TableCodec::decode_index_meta::(&bytes)?, @@ -749,7 +749,7 @@ mod tests { println!("==== Subquery"); let plan = table_state .plan("select * from t1 where c1 in (select c1 from t1 where c1 > 1)")?; - println!("{:#?}", plan); + println!("{plan:#?}"); let view = View { name: "view_subquery".to_string().into(), plan: Box::new(plan), @@ -799,6 +799,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_table_codec_column_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -852,6 +853,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_table_codec_index_meta_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -864,7 +866,7 @@ mod tests { table_name: table_name.to_string().into(), pk_ty: LogicalType::Integer, value_ty: LogicalType::Integer, - name: format!("{}_index", index_id), + name: format!("{index_id}_index"), ty: IndexType::PrimaryKey { is_multiple: false }, }; @@ -886,7 +888,7 @@ mod tests { set.insert(op(1, "T2")); set.insert(op(2, "T2")); - let (min, max) = table_codec.index_meta_bound(&"T1".to_string()); + let (min, max) = table_codec.index_meta_bound("T1"); let vec = set .range::, Bound<&BumpBytes>)>(( @@ -903,6 +905,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_table_codec_index_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -940,13 +943,8 @@ mod tests { set.insert(op(DataValue::Int32(1), 2, &table_catalog.name)); set.insert(op(DataValue::Int32(2), 2, &table_catalog.name)); - println!("{:#?}", set); - let (min, max) = table_codec.index_bound(&table_catalog.name, 1).unwrap(); - println!("{:?}", min); - println!("{:?}", max); - let vec = set .range::, Bound<&BumpBytes>)>(( Bound::Included(&min), @@ -962,6 +960,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_table_codec_index_all_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -976,7 +975,7 @@ mod tests { ); table_codec - .encode_index_key(&table_name.to_string(), &index, None) + .encode_index_key(table_name, &index, None) .unwrap() }; @@ -992,7 +991,7 @@ mod tests { set.insert(op(DataValue::Int32(1), 0, "T2")); set.insert(op(DataValue::Int32(2), 0, "T2")); - let (min, max) = table_codec.all_index_bound(&"T1".to_string()); + let (min, max) = table_codec.all_index_bound("T1"); let vec = set .range::, Bound<&BumpBytes>)>(( @@ -1009,6 +1008,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_table_codec_tuple_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -1016,7 +1016,7 @@ mod tests { let mut set = BTreeSet::new(); let op = |tuple_id: DataValue, table_name: &str| { table_codec - .encode_tuple_key(&table_name.to_string(), &Arc::new(tuple_id)) + .encode_tuple_key(table_name, &Arc::new(tuple_id)) .unwrap() }; @@ -1032,7 +1032,7 @@ mod tests { set.insert(op(DataValue::Int32(1), "T2")); set.insert(op(DataValue::Int32(2), "T2")); - let (min, max) = table_codec.tuple_bound(&"T1".to_string()); + let (min, max) = table_codec.tuple_bound("T1"); let vec = set .range::, Bound<&BumpBytes>)>(( @@ -1049,6 +1049,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_root_codec_name_bound() { let table_codec = TableCodec { arena: Default::default(), @@ -1082,6 +1083,7 @@ mod tests { } #[test] + #[allow(clippy::mutable_key_type)] fn test_view_codec_name_bound() { let table_codec = TableCodec { arena: Default::default(), diff --git a/src/types/tuple.rs b/src/types/tuple.rs index f53ce442..e38e47ee 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -274,7 +274,7 @@ mod tests { )), ]); - let tuples = vec![ + let tuples = [ Tuple::new( Some(DataValue::Int32(0)), vec![ diff --git a/src/types/value.rs b/src/types/value.rs index 6077463e..a4a6bf06 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -2262,9 +2262,9 @@ mod test { value_2.memcomparable_encode(&mut key_i8_2)?; value_3.memcomparable_encode(&mut key_i8_3)?; - println!("{:?} < {:?}", key_i8_0, key_i8_1); - println!("{:?} < {:?}", key_i8_1, key_i8_2); - println!("{:?} < {:?}", key_i8_2, key_i8_3); + println!("{key_i8_0:?} < {key_i8_1:?}"); + println!("{key_i8_1:?} < {key_i8_2:?}"); + println!("{key_i8_2:?} < {key_i8_3:?}"); assert!(key_i8_0 < key_i8_1); assert!(key_i8_1 < key_i8_2); assert!(key_i8_2 < key_i8_3); @@ -2616,9 +2616,9 @@ mod test { v_decimal_2.memcomparable_encode(&mut key_decimal_2)?; v_decimal_3.memcomparable_encode(&mut key_decimal_3)?; - println!("{:?} < {:?}", key_decimal_0, key_decimal_1); - println!("{:?} < {:?}", key_decimal_1, key_decimal_2); - println!("{:?} < {:?}", key_decimal_2, key_decimal_3); + println!("{key_decimal_0:?} < {key_decimal_1:?}"); + println!("{key_decimal_1:?} < {key_decimal_2:?}"); + println!("{key_decimal_2:?} < {key_decimal_3:?}"); assert!(key_decimal_0 < key_decimal_1); assert!(key_decimal_1 < key_decimal_2); @@ -2683,8 +2683,8 @@ mod test { v_tuple_2.memcomparable_encode(&mut key_tuple_2)?; v_tuple_3.memcomparable_encode(&mut key_tuple_3)?; - println!("{:?} < {:?}", key_tuple_1, key_tuple_2); - println!("{:?} < {:?}", key_tuple_2, key_tuple_3); + println!("{key_tuple_1:?} < {key_tuple_2:?}"); + println!("{key_tuple_2:?} < {key_tuple_3:?}"); assert!(key_tuple_1 < key_tuple_2); assert!(key_tuple_2 < key_tuple_3); diff --git a/tpcc/src/main.rs b/tpcc/src/main.rs index fcf02fa9..c7aefae1 100644 --- a/tpcc/src/main.rs +++ b/tpcc/src/main.rs @@ -108,51 +108,93 @@ fn main() -> Result<(), TpccError> { Load::load_ord(&mut rng, &database, args.num_ware)?; let test_statements = vec![ + // New-Order: order creation and stock reservation. vec![ + // Hot join fetching customer credit + warehouse tax. database.prepare("SELECT c.c_discount, c.c_last, c.c_credit, w.w_tax FROM customer AS c JOIN warehouse AS w ON c.c_w_id = w_id AND w.w_id = ?1 AND c.c_w_id = ?2 AND c.c_d_id = ?3 AND c.c_id = ?4")?, + // PK lookup of customer row. database.prepare("SELECT c_discount, c_last, c_credit FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_id = ?3")?, + // Single-row warehouse tax read. database.prepare("SELECT w_tax FROM warehouse WHERE w_id = ?1")?, + // Next order id lookup; serialized per district. database.prepare("SELECT d_next_o_id, d_tax FROM district WHERE d_id = ?1 AND d_w_id = ?2")?, + // Hot-row update on d_next_o_id. database.prepare("UPDATE district SET d_next_o_id = ?1 + 1 WHERE d_id = ?2 AND d_w_id = ?3")?, + // Orders insert touches multiple indexes. database.prepare("INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7)")?, + // Append to new_orders queue. database.prepare("INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) VALUES (?1,?2,?3)")?, + // Random item lookup by PK. database.prepare("SELECT i_price, i_name, i_data FROM item WHERE i_id = ?1")?, + // Stock fetch per item/warehouse. database.prepare("SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 FROM stock WHERE s_i_id = ?1 AND s_w_id = ?2")?, + // Stock decrement; contention point. database.prepare("UPDATE stock SET s_quantity = ?1 WHERE s_i_id = ?2 AND s_w_id = ?3")?, + // Order_line insert per item. database.prepare("INSERT INTO order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)")?, ], + // Payment: apply payment and write history row. vec![ + // Warehouse w_ytd counter update. database.prepare("UPDATE warehouse SET w_ytd = w_ytd + ?1 WHERE w_id = ?2")?, + // Warehouse address projection. database.prepare("SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name FROM warehouse WHERE w_id = ?1")?, + // District d_ytd counter update. database.prepare("UPDATE district SET d_ytd = d_ytd + ?1 WHERE d_w_id = ?2 AND d_id = ?3")?, + // District address projection. database.prepare("SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name FROM district WHERE d_w_id = ?1 AND d_id = ?2")?, + // COUNT over customers sharing last name (line 129). database.prepare("SELECT count(c_id) FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_last = ?3")?, + // ORDER BY c_first to pick correct customer (line 130). database.prepare("SELECT c_id FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_last = ?3 ORDER BY c_first")?, + // Full customer row read. database.prepare("SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_id = ?3")?, + // Pull c_data LOB. database.prepare("SELECT c_data FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_id = ?3")?, + // Update balance + c_data (text concat). database.prepare("UPDATE customer SET c_balance = ?1, c_data = ?2 WHERE c_w_id = ?3 AND c_d_id = ?4 AND c_id = ?5")?, + // Balance-only update variant. database.prepare("UPDATE customer SET c_balance = ?1 WHERE c_w_id = ?2 AND c_d_id = ?3 AND c_id = ?4")?, + // History append writes long text payload. database.prepare("INSERT OVERWRITE 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(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)")?, ], + // Order-Status: inspect the most recent order of a customer. vec![ + // COUNT on customers sharing last name (line 138). database.prepare("SELECT count(c_id) FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_last = ?3")?, + // ORDER BY c_first to pick median entry (line 139). database.prepare("SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_last = ?3 ORDER BY c_first")?, + // Direct customer lookup by id. database.prepare("SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ?1 AND c_d_id = ?2 AND c_id = ?3")?, + // Correlated MAX(o_id) to find latest order. database.prepare("SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) FROM orders WHERE o_w_id = ?1 AND o_d_id = ?2 AND o_c_id = ?3 AND o_id = (SELECT MAX(o_id) FROM orders WHERE o_w_id = ?4 AND o_d_id = ?5 AND o_c_id = ?6)")?, + // Fetch all order_line rows for that order. database.prepare("SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d FROM order_line WHERE ol_w_id = ?1 AND ol_d_id = ?2 AND ol_o_id = ?3")? ], + // Delivery: finish the oldest new order per district. vec![ + // MIN(no_o_id) over new_orders (line 145). database.prepare("SELECT COALESCE(MIN(no_o_id),0) FROM new_orders WHERE no_d_id = ?1 AND no_w_id = ?2")?, + // Delete that new_orders entry. database.prepare("DELETE FROM new_orders WHERE no_o_id = ?1 AND no_d_id = ?2 AND no_w_id = ?3")?, + // Lookup the customer id from orders. database.prepare("SELECT o_c_id FROM orders WHERE o_id = ?1 AND o_d_id = ?2 AND o_w_id = ?3")?, + // Update carrier id on the order. database.prepare("UPDATE orders SET o_carrier_id = ?1 WHERE o_id = ?2 AND o_d_id = ?3 AND o_w_id = ?4")?, + // Update delivery timestamp on order_line rows. database.prepare("UPDATE order_line SET ol_delivery_d = ?1 WHERE ol_o_id = ?2 AND ol_d_id = ?3 AND ol_w_id = ?4")?, + // SUM(ol_amount) per order (line 150). database.prepare("SELECT SUM(ol_amount) FROM order_line WHERE ol_o_id = ?1 AND ol_d_id = ?2 AND ol_w_id = ?3")?, + // Customer balance + delivery_cnt increment. database.prepare("UPDATE customer SET c_balance = c_balance + ?1 , c_delivery_cnt = c_delivery_cnt + 1 WHERE c_id = ?2 AND c_d_id = ?3 AND c_w_id = ?4")?, ], + // Stock-Level: detect items that are low stock for recent orders. vec![ + // District next_o_id read. database.prepare("SELECT d_next_o_id FROM district WHERE d_id = ?1 AND d_w_id = ?2")?, + // DISTINCT item ids from last 20 orders (line 155). database.prepare("SELECT DISTINCT ol_i_id FROM order_line WHERE ol_w_id = ?1 AND ol_d_id = ?2 AND ol_o_id < ?3 AND ol_o_id >= (?4 - 20)")?, + // COUNT stock rows where s_quantity falls below threshold (line 156). database.prepare("SELECT count(*) FROM stock WHERE s_w_id = ?1 AND s_i_id = ?2 AND s_quantity < ?3")?, ], ];