Skip to content

Commit

Permalink
spacetimedb_table: nix spacetimedb-core dep (#767)
Browse files Browse the repository at this point in the history
Readd `BTreeIndex::name` to report unique constraint violations on sys tables.
Add a unique_violation_test
  • Loading branch information
Centril authored Jan 26, 2024
1 parent 475924d commit e395e4e
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ harness = false

[dependencies]
spacetimedb-lib = { path = "../lib", version = "0.8.1" }
spacetimedb-sats = { path = "../sats", version = "0.8.1" }
spacetimedb-vm = { path = "../vm", version = "0.8.1" }
spacetimedb-client-api-messages = { path = "../client-api-messages", version = "0.8.1" }
spacetimedb-primitives = { path = "../primitives", version = "0.8.1" }
spacetimedb-metrics = { path = "../metrics", version = "0.8.1" }
spacetimedb-primitives = { path = "../primitives", version = "0.8.1" }
spacetimedb-sats = { path = "../sats", version = "0.8.1" }
spacetimedb-table = { path = "../table", version = "0.8.1" }
spacetimedb-vm = { path = "../vm", version = "0.8.1" }

anyhow.workspace = true
async-trait.workspace = true
Expand Down
17 changes: 9 additions & 8 deletions crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ mod tests {
use spacetimedb_primitives::Constraints;
use spacetimedb_sats::db::auth::{StAccess, StTableType};
use spacetimedb_sats::product;
use spacetimedb_table::table::UniqueConstraintViolation;

/// Utility to query the system tables and return their concrete table row
pub struct SystemTableQuery<'a> {
Expand Down Expand Up @@ -1327,12 +1328,12 @@ mod tests {
datastore.insert_mut_tx(&mut tx, table_id, row.clone())?;
let result = datastore.insert_mut_tx(&mut tx, table_id, row);
match result {
Err(DBError::Index(IndexError::UniqueConstraintViolation {
Err(DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
})) => (),
}))) => (),
_ => panic!("Expected an unique constraint violation error."),
}
#[rustfmt::skip]
Expand All @@ -1349,12 +1350,12 @@ mod tests {
let mut tx = datastore.begin_mut_tx();
let result = datastore.insert_mut_tx(&mut tx, table_id, row);
match result {
Err(DBError::Index(IndexError::UniqueConstraintViolation {
Err(DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
})) => (),
}))) => (),
_ => panic!("Expected an unique constraint violation error."),
}
#[rustfmt::skip]
Expand Down Expand Up @@ -1407,12 +1408,12 @@ mod tests {
let row = u32_str_u32(0, "Bar", 18); // 0 will be ignored.
let result = datastore.insert_mut_tx(&mut tx, table_id, row);
match result {
Err(DBError::Index(IndexError::UniqueConstraintViolation {
Err(DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
})) => (),
}))) => (),
_ => panic!("Expected an unique constraint violation error."),
}
#[rustfmt::skip]
Expand Down Expand Up @@ -1450,12 +1451,12 @@ mod tests {
let row = u32_str_u32(0, "Bar", 18); // 0 will be ignored.
let result = datastore.insert_mut_tx(&mut tx, table_id, row);
match result {
Err(DBError::Index(IndexError::UniqueConstraintViolation {
Err(DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
})) => (),
}))) => (),
_ => panic!("Expected an unique constraint violation error."),
}
#[rustfmt::skip]
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use spacetimedb_sats::data_key::{DataKey, ToDataKey};
use spacetimedb_sats::db::def::*;
use spacetimedb_sats::db::error::SchemaErrors;
use spacetimedb_sats::{AlgebraicValue, ProductType, ProductValue};
use spacetimedb_table::table::UniqueConstraintViolation;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::sync::Arc;
Expand Down Expand Up @@ -983,7 +984,7 @@ impl MutTxId {
}

fn build_error_unique(index: &BTreeIndex, table: &Table, value: AlgebraicValue) -> IndexError {
IndexError::UniqueConstraintViolation {
IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: index.name.clone(),
table_name: table.schema.table_name.clone(),
cols: index
Expand All @@ -992,7 +993,7 @@ impl MutTxId {
.map(|x| table.schema.columns()[usize::from(x)].col_name.clone())
.collect(),
value,
}
})
}

pub(crate) fn get<'a>(&'a self, table_id: &TableId, row_id: &'a RowId) -> Result<Option<DataRef<'a>>> {
Expand Down
11 changes: 3 additions & 8 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;
use std::sync::{MutexGuard, PoisonError};

use hex::FromHexError;
use spacetimedb_table::table::UniqueConstraintViolation;
use thiserror::Error;

use crate::client::ClientActorId;
Expand All @@ -17,7 +18,6 @@ use spacetimedb_sats::hash::Hash;
use spacetimedb_sats::product_value::InvalidFieldError;
use spacetimedb_sats::relation::FieldName;
use spacetimedb_sats::satn::Satn;
use spacetimedb_sats::AlgebraicValue;
use spacetimedb_vm::errors::{ErrorKind, ErrorLang, ErrorVm};
use spacetimedb_vm::expr::Crud;

Expand Down Expand Up @@ -68,13 +68,8 @@ pub enum IndexError {
IndexAlreadyExists(IndexDef, String),
#[error("Column not found: {0:?}")]
ColumnNotFound(IndexDef),
#[error("Unique constraint violation '{}' in table '{}': column(s): '{:?}' value: {}", constraint_name, table_name, cols, value.to_satn())]
UniqueConstraintViolation {
constraint_name: String,
table_name: String,
cols: Vec<String>,
value: AlgebraicValue,
},
#[error(transparent)]
UniqueConstraintViolation(UniqueConstraintViolation),
#[error("Attempt to define a index with more than 1 auto_inc column: Table: {0:?}, Columns: {1:?}")]
OneAutoInc(TableId, Vec<String>),
}
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/host/instance_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use parking_lot::{Mutex, MutexGuard};
use smallvec::SmallVec;
use spacetimedb_table::table::UniqueConstraintViolation;
use std::ops::DerefMut;
use std::sync::Arc;

Expand Down Expand Up @@ -120,12 +121,12 @@ impl InstanceEnv {
let ret = stdb
.insert_bytes_as_row(tx, table_id, buffer)
.inspect_err_(|e| match e {
crate::error::DBError::Index(IndexError::UniqueConstraintViolation {
crate::error::DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
}) => {}
})) => {}
_ => {
let res = stdb.table_name_from_id(ctx, tx, table_id);
if let Ok(Some(table_name)) = res {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/host/wasm_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::time::Instant;
use super::AbiCall;
use crate::error::{DBError, IndexError, NodesError};
use spacetimedb_sats::typespace::TypeRefError;
use spacetimedb_table::table::UniqueConstraintViolation;

pub const CALL_REDUCER_DUNDER: &str = "__call_reducer__";

Expand Down Expand Up @@ -353,12 +354,12 @@ pub fn err_to_errno(err: &NodesError) -> Option<u16> {
}
NodesError::AlreadyExists(_) => Some(errnos::UNIQUE_ALREADY_EXISTS),
NodesError::Internal(internal) => match **internal {
DBError::Index(IndexError::UniqueConstraintViolation {
DBError::Index(IndexError::UniqueConstraintViolation(UniqueConstraintViolation {
constraint_name: _,
table_name: _,
cols: _,
value: _,
}) => Some(errnos::UNIQUE_ALREADY_EXISTS),
})) => Some(errnos::UNIQUE_ALREADY_EXISTS),
_ => None,
},
_ => None,
Expand Down
1 change: 0 additions & 1 deletion crates/table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ proptest = ["dep:proptest", "dep:proptest-derive"]
blake3_pure = ["blake3/pure"]

[dependencies]
spacetimedb-core = { path = "../core" }
spacetimedb-primitives = { path = "../primitives" }
spacetimedb-sats = { path = "../sats" }

Expand Down
20 changes: 11 additions & 9 deletions crates/table/src/btree_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use super::table::RowRef;
use crate::static_assert_size;
use core::ops::RangeBounds;
use multimap::{MultiMap, MultiMapRangeIter};
use spacetimedb::error::DBError;
use spacetimedb_primitives::{ColList, IndexId};
use spacetimedb_sats::{AlgebraicValue, ProductValue};
use spacetimedb_sats::{product_value::InvalidFieldError, AlgebraicValue, ProductValue};

mod multimap;

Expand Down Expand Up @@ -70,30 +69,33 @@ pub struct BTreeIndex {
pub(crate) is_unique: bool,
/// The actual index.
idx: MultiMap<IndexKey, RowPointer>,
/// The index name, used for reporting unique constraint violations.
pub(crate) name: Box<str>,
}

static_assert_size!(BTreeIndex, 32);
static_assert_size!(BTreeIndex, 48);

impl BTreeIndex {
/// Returns a new possibly unique index, with `index_id` for a set of columns.
pub fn new(index_id: IndexId, is_unique: bool) -> Self {
pub fn new(index_id: IndexId, is_unique: bool, name: impl Into<Box<str>>) -> Self {
Self {
index_id,
is_unique,
idx: MultiMap::new(),
name: name.into(),
}
}

/// Extracts from `row` the relevant column values according to what columns are indexed.
pub fn get_fields(&self, cols: &ColList, row: &ProductValue) -> Result<AlgebraicValue, DBError> {
row.project_not_empty(cols).map_err(Into::into)
pub fn get_fields(&self, cols: &ColList, row: &ProductValue) -> Result<AlgebraicValue, InvalidFieldError> {
row.project_not_empty(cols)
}

/// Inserts `ptr` with the value `row` to this index.
/// This index will extract the necessary values from `row` based on `self.cols`.
///
/// Return false if `ptr` was already indexed prior to this call.
pub fn insert(&mut self, cols: &ColList, row: &ProductValue, ptr: RowPointer) -> Result<bool, DBError> {
pub fn insert(&mut self, cols: &ColList, row: &ProductValue, ptr: RowPointer) -> Result<bool, InvalidFieldError> {
let col_value = self.get_fields(cols, row)?;
Ok(self.idx.insert(col_value, ptr))
}
Expand Down Expand Up @@ -144,7 +146,7 @@ impl BTreeIndex {
&mut self,
cols: &ColList,
rows: impl IntoIterator<Item = RowRef<'table>>,
) -> Result<bool, DBError> {
) -> Result<bool, InvalidFieldError> {
let mut all_inserted = true;
for row_ref in rows {
let row = row_ref.to_product_value();
Expand Down Expand Up @@ -190,7 +192,7 @@ mod test {
}

fn new_index(is_unique: bool) -> BTreeIndex {
BTreeIndex::new(0.into(), is_unique)
BTreeIndex::new(0.into(), is_unique, "test_index")
}

proptest! {
Expand Down
Loading

1 comment on commit e395e4e

@github-actions
Copy link

@github-actions github-actions bot commented on e395e4e Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark results

Benchmark Report

Legend:

  • load: number of rows pre-loaded into the database
  • count: number of rows touched by the transaction
  • index types:
    • unique: a single index on the id column
    • non_unique: no indexes
    • multi_index: non-unique index on every column
  • schemas:
    • person(id: u32, name: String, age: u64)
    • location(id: u32, x: u64, y: u64)

All throughputs are single-threaded.

Empty transaction

db on disk new latency old latency new throughput old throughput
sqlite 💿 441.8±1.05ns 462.6±0.85ns - -
sqlite 🧠 438.3±1.04ns 460.1±2.07ns - -
stdb_module 💿 19.8±1.11µs 19.6±0.88µs - -
stdb_module 🧠 19.2±0.97µs 19.3±0.99µs - -
stdb_raw 💿 928.6±1.51ns 932.0±1.95ns - -
stdb_raw 🧠 884.3±2.54ns 884.7±1.33ns - -

Single-row insertions

db on disk schema index type load new latency old latency new throughput old throughput
sqlite 💿 location multi_index 0 14.5±0.16µs 15.1±4.08µs 67.1 Ktx/sec 64.6 Ktx/sec
sqlite 💿 location multi_index 1000 15.9±0.14µs 15.7±0.37µs 61.5 Ktx/sec 62.1 Ktx/sec
sqlite 💿 location non_unique 0 7.1±0.05µs 7.1±0.05µs 137.4 Ktx/sec 137.2 Ktx/sec
sqlite 💿 location non_unique 1000 7.1±0.06µs 6.9±0.05µs 137.8 Ktx/sec 140.6 Ktx/sec
sqlite 💿 location unique 0 7.1±0.02µs 7.1±0.05µs 137.9 Ktx/sec 138.1 Ktx/sec
sqlite 💿 location unique 1000 7.1±0.04µs 7.0±0.03µs 137.8 Ktx/sec 139.6 Ktx/sec
sqlite 💿 person multi_index 0 14.3±0.05µs 14.3±0.05µs 68.3 Ktx/sec 68.4 Ktx/sec
sqlite 💿 person multi_index 1000 16.1±0.19µs 16.0±0.11µs 60.8 Ktx/sec 61.1 Ktx/sec
sqlite 💿 person non_unique 0 7.2±0.55µs 7.3±0.27µs 135.4 Ktx/sec 134.6 Ktx/sec
sqlite 💿 person non_unique 1000 7.2±0.04µs 7.2±0.05µs 135.2 Ktx/sec 136.2 Ktx/sec
sqlite 💿 person unique 0 7.3±0.20µs 7.2±0.38µs 134.5 Ktx/sec 135.2 Ktx/sec
sqlite 💿 person unique 1000 7.3±0.06µs 7.2±0.05µs 134.7 Ktx/sec 135.7 Ktx/sec
sqlite 🧠 location multi_index 0 4.1±0.02µs 4.0±0.01µs 239.6 Ktx/sec 245.6 Ktx/sec
sqlite 🧠 location multi_index 1000 5.3±0.04µs 5.2±0.04µs 183.5 Ktx/sec 188.9 Ktx/sec
sqlite 🧠 location non_unique 0 1869.0±6.12ns 1789.9±3.90ns 522.5 Ktx/sec 545.6 Ktx/sec
sqlite 🧠 location non_unique 1000 1940.4±11.54ns 1839.4±6.50ns 503.3 Ktx/sec 530.9 Ktx/sec
sqlite 🧠 location unique 0 1862.2±7.85ns 1764.5±3.76ns 524.4 Ktx/sec 553.4 Ktx/sec
sqlite 🧠 location unique 1000 1983.5±10.53ns 1896.8±10.97ns 492.4 Ktx/sec 514.8 Ktx/sec
sqlite 🧠 person multi_index 0 3.7±0.01µs 3.6±0.01µs 263.5 Ktx/sec 271.0 Ktx/sec
sqlite 🧠 person multi_index 1000 5.4±0.02µs 5.4±0.03µs 180.2 Ktx/sec 181.3 Ktx/sec
sqlite 🧠 person non_unique 0 1931.2±6.02ns 1871.0±8.37ns 505.7 Ktx/sec 522.0 Ktx/sec
sqlite 🧠 person non_unique 1000 2.0±0.01µs 1985.5±14.66ns 481.2 Ktx/sec 491.9 Ktx/sec
sqlite 🧠 person unique 0 1937.4±3.05ns 1847.0±4.55ns 504.1 Ktx/sec 528.7 Ktx/sec
sqlite 🧠 person unique 1000 2.1±0.02µs 1984.2±25.19ns 471.2 Ktx/sec 492.2 Ktx/sec
stdb_module 💿 location multi_index 0 58.0±4.62µs 55.5±6.13µs 16.8 Ktx/sec 17.6 Ktx/sec
stdb_module 💿 location multi_index 1000 124.9±3.28µs 216.1±17.46µs 7.8 Ktx/sec 4.5 Ktx/sec
stdb_module 💿 location non_unique 0 44.9±5.72µs 48.1±3.32µs 21.7 Ktx/sec 20.3 Ktx/sec
stdb_module 💿 location non_unique 1000 81.0±33.29µs 115.5±40.19µs 12.1 Ktx/sec 8.5 Ktx/sec
stdb_module 💿 location unique 0 51.3±4.36µs 50.5±4.76µs 19.0 Ktx/sec 19.3 Ktx/sec
stdb_module 💿 location unique 1000 111.9±10.91µs 135.0±10.91µs 8.7 Ktx/sec 7.2 Ktx/sec
stdb_module 💿 person multi_index 0 68.0±4.18µs 68.5±5.48µs 14.4 Ktx/sec 14.3 Ktx/sec
stdb_module 💿 person multi_index 1000 125.6±13.29µs 173.2±3.20µs 7.8 Ktx/sec 5.6 Ktx/sec
stdb_module 💿 person non_unique 0 53.2±6.06µs 53.4±5.32µs 18.4 Ktx/sec 18.3 Ktx/sec
stdb_module 💿 person non_unique 1000 63.8±8.27µs 122.5±21.96µs 15.3 Ktx/sec 8.0 Ktx/sec
stdb_module 💿 person unique 0 59.6±5.06µs 61.6±5.20µs 16.4 Ktx/sec 15.9 Ktx/sec
stdb_module 💿 person unique 1000 71.1±17.70µs 177.1±11.20µs 13.7 Ktx/sec 5.5 Ktx/sec
stdb_module 🧠 location multi_index 0 41.4±3.52µs 42.1±4.86µs 23.6 Ktx/sec 23.2 Ktx/sec
stdb_module 🧠 location multi_index 1000 82.8±11.26µs 137.9±15.81µs 11.8 Ktx/sec 7.1 Ktx/sec
stdb_module 🧠 location non_unique 0 34.3±2.52µs 34.9±2.90µs 28.5 Ktx/sec 28.0 Ktx/sec
stdb_module 🧠 location non_unique 1000 173.0±11.87µs 135.2±34.67µs 5.6 Ktx/sec 7.2 Ktx/sec
stdb_module 🧠 location unique 0 40.5±3.20µs 40.0±3.42µs 24.1 Ktx/sec 24.4 Ktx/sec
stdb_module 🧠 location unique 1000 123.0±19.83µs 91.5±55.48µs 7.9 Ktx/sec 10.7 Ktx/sec
stdb_module 🧠 person multi_index 0 50.3±3.19µs 46.5±3.86µs 19.4 Ktx/sec 21.0 Ktx/sec
stdb_module 🧠 person multi_index 1000 148.9±1.77µs 274.6±2.51µs 6.6 Ktx/sec 3.6 Ktx/sec
stdb_module 🧠 person non_unique 0 36.2±3.19µs 39.3±2.94µs 27.0 Ktx/sec 24.9 Ktx/sec
stdb_module 🧠 person non_unique 1000 144.9±77.79µs 204.1±12.27µs 6.7 Ktx/sec 4.8 Ktx/sec
stdb_module 🧠 person unique 0 38.2±4.17µs 44.4±4.07µs 25.5 Ktx/sec 22.0 Ktx/sec
stdb_module 🧠 person unique 1000 46.3±14.77µs 55.2±6.92µs 21.1 Ktx/sec 17.7 Ktx/sec
stdb_raw 💿 location multi_index 0 7.0±0.04µs 7.0±0.03µs 138.9 Ktx/sec 138.9 Ktx/sec
stdb_raw 💿 location multi_index 1000 9.9±0.16µs 34.6±248.56µs 99.1 Ktx/sec 28.2 Ktx/sec
stdb_raw 💿 location non_unique 0 4.8±0.01µs 4.8±0.01µs 204.8 Ktx/sec 202.1 Ktx/sec
stdb_raw 💿 location non_unique 1000 6.5±0.17µs 6.5±0.16µs 150.1 Ktx/sec 150.4 Ktx/sec
stdb_raw 💿 location unique 0 6.1±0.07µs 6.1±0.02µs 160.7 Ktx/sec 160.5 Ktx/sec
stdb_raw 💿 location unique 1000 8.6±0.14µs 8.4±0.16µs 114.1 Ktx/sec 115.7 Ktx/sec
stdb_raw 💿 person multi_index 0 11.4±0.03µs 11.2±0.02µs 85.8 Ktx/sec 86.9 Ktx/sec
stdb_raw 💿 person multi_index 1000 56.0±413.27µs 14.8±0.16µs 17.4 Ktx/sec 66.2 Ktx/sec
stdb_raw 💿 person non_unique 0 5.9±0.36µs 5.9±0.01µs 165.6 Ktx/sec 166.0 Ktx/sec
stdb_raw 💿 person non_unique 1000 23.7±156.03µs 23.6±157.77µs 41.2 Ktx/sec 41.4 Ktx/sec
stdb_raw 💿 person unique 0 8.2±0.24µs 8.3±0.40µs 118.8 Ktx/sec 118.2 Ktx/sec
stdb_raw 💿 person unique 1000 10.8±0.13µs 11.0±0.19µs 90.1 Ktx/sec 88.5 Ktx/sec
stdb_raw 🧠 location multi_index 0 4.5±0.01µs 4.5±0.02µs 216.2 Ktx/sec 217.0 Ktx/sec
stdb_raw 🧠 location multi_index 1000 6.1±0.03µs 6.3±0.04µs 159.1 Ktx/sec 155.9 Ktx/sec
stdb_raw 🧠 location non_unique 0 2.3±0.00µs 2.3±0.01µs 422.2 Ktx/sec 417.6 Ktx/sec
stdb_raw 🧠 location non_unique 1000 2.9±0.02µs 3.0±0.02µs 333.6 Ktx/sec 325.3 Ktx/sec
stdb_raw 🧠 location unique 0 3.6±0.01µs 3.5±0.01µs 272.7 Ktx/sec 275.3 Ktx/sec
stdb_raw 🧠 location unique 1000 4.7±0.03µs 4.9±0.03µs 206.8 Ktx/sec 200.9 Ktx/sec
stdb_raw 🧠 person multi_index 0 8.2±0.02µs 8.1±0.01µs 119.1 Ktx/sec 119.9 Ktx/sec
stdb_raw 🧠 person multi_index 1000 10.2±0.07µs 10.3±0.08µs 96.2 Ktx/sec 94.9 Ktx/sec
stdb_raw 🧠 person non_unique 0 2.9±0.01µs 2.9±0.03µs 341.3 Ktx/sec 336.4 Ktx/sec
stdb_raw 🧠 person non_unique 1000 3.6±0.02µs 3.7±0.02µs 268.4 Ktx/sec 264.1 Ktx/sec
stdb_raw 🧠 person unique 0 5.1±0.02µs 5.1±0.01µs 189.9 Ktx/sec 190.1 Ktx/sec
stdb_raw 🧠 person unique 1000 6.5±0.04µs 6.6±0.06µs 150.1 Ktx/sec 148.8 Ktx/sec

Multi-row insertions

db on disk schema index type load count new latency old latency new throughput old throughput
sqlite 💿 location multi_index 0 100 133.1±3.50µs 128.5±0.28µs 7.3 Ktx/sec 7.6 Ktx/sec
sqlite 💿 location multi_index 1000 100 203.9±2.38µs 200.5±5.80µs 4.8 Ktx/sec 4.9 Ktx/sec
sqlite 💿 location non_unique 0 100 49.1±0.94µs 47.8±1.29µs 19.9 Ktx/sec 20.4 Ktx/sec
sqlite 💿 location non_unique 1000 100 51.5±0.30µs 50.5±0.28µs 19.0 Ktx/sec 19.3 Ktx/sec
sqlite 💿 location unique 0 100 50.6±1.31µs 50.7±1.39µs 19.3 Ktx/sec 19.3 Ktx/sec
sqlite 💿 location unique 1000 100 55.1±0.25µs 54.4±0.28µs 17.7 Ktx/sec 17.9 Ktx/sec
sqlite 💿 person multi_index 0 100 118.8±3.75µs 116.4±0.61µs 8.2 Ktx/sec 8.4 Ktx/sec
sqlite 💿 person multi_index 1000 100 230.8±20.82µs 238.4±59.44µs 4.2 Ktx/sec 4.1 Ktx/sec
sqlite 💿 person non_unique 0 100 46.7±1.47µs 46.6±0.54µs 20.9 Ktx/sec 21.0 Ktx/sec
sqlite 💿 person non_unique 1000 100 59.2±0.32µs 58.2±0.36µs 16.5 Ktx/sec 16.8 Ktx/sec
sqlite 💿 person unique 0 100 49.7±1.38µs 48.0±1.40µs 19.6 Ktx/sec 20.4 Ktx/sec
sqlite 💿 person unique 1000 100 54.0±0.23µs 54.7±0.22µs 18.1 Ktx/sec 17.9 Ktx/sec
sqlite 🧠 location multi_index 0 100 121.3±0.59µs 117.4±0.35µs 8.1 Ktx/sec 8.3 Ktx/sec
sqlite 🧠 location multi_index 1000 100 172.1±0.45µs 166.3±0.31µs 5.7 Ktx/sec 5.9 Ktx/sec
sqlite 🧠 location non_unique 0 100 42.6±0.27µs 41.7±0.22µs 22.9 Ktx/sec 23.4 Ktx/sec
sqlite 🧠 location non_unique 1000 100 44.7±0.24µs 42.9±0.40µs 21.9 Ktx/sec 22.8 Ktx/sec
sqlite 🧠 location unique 0 100 45.2±0.30µs 44.0±0.50µs 21.6 Ktx/sec 22.2 Ktx/sec
sqlite 🧠 location unique 1000 100 48.8±0.33µs 47.0±0.37µs 20.0 Ktx/sec 20.8 Ktx/sec
sqlite 🧠 person multi_index 0 100 107.0±0.44µs 105.2±0.29µs 9.1 Ktx/sec 9.3 Ktx/sec
sqlite 🧠 person multi_index 1000 100 189.0±0.29µs 187.9±0.32µs 5.2 Ktx/sec 5.2 Ktx/sec
sqlite 🧠 person non_unique 0 100 41.0±0.36µs 39.9±0.31µs 23.8 Ktx/sec 24.4 Ktx/sec
sqlite 🧠 person non_unique 1000 100 44.1±0.34µs 44.0±0.28µs 22.2 Ktx/sec 22.2 Ktx/sec
sqlite 🧠 person unique 0 100 43.4±0.30µs 42.7±0.47µs 22.5 Ktx/sec 22.9 Ktx/sec
sqlite 🧠 person unique 1000 100 46.6±0.51µs 46.6±0.29µs 20.9 Ktx/sec 21.0 Ktx/sec
stdb_module 💿 location multi_index 0 100 865.3±2.08µs 653.7±119.26µs 1155 tx/sec 1529 tx/sec
stdb_module 💿 location multi_index 1000 100 1009.2±16.90µs 858.5±14.86µs 990 tx/sec 1164 tx/sec
stdb_module 💿 location non_unique 0 100 445.3±3.01µs 389.1±19.18µs 2.2 Ktx/sec 2.5 Ktx/sec
stdb_module 💿 location non_unique 1000 100 575.7±6.08µs 441.1±13.85µs 1736 tx/sec 2.2 Ktx/sec
stdb_module 💿 location unique 0 100 663.4±5.95µs 495.0±27.44µs 1507 tx/sec 2020 tx/sec
stdb_module 💿 location unique 1000 100 886.1±5.75µs 697.0±10.60µs 1128 tx/sec 1434 tx/sec
stdb_module 💿 person multi_index 0 100 1152.4±332.13µs 1009.8±117.38µs 867 tx/sec 990 tx/sec
stdb_module 💿 person multi_index 1000 100 1150.3±8.62µs 1290.7±61.81µs 869 tx/sec 774 tx/sec
stdb_module 💿 person non_unique 0 100 658.0±112.20µs 524.2±70.38µs 1519 tx/sec 1907 tx/sec
stdb_module 💿 person non_unique 1000 100 601.1±78.72µs 780.9±64.91µs 1663 tx/sec 1280 tx/sec
stdb_module 💿 person unique 0 100 651.7±42.05µs 825.0±121.44µs 1534 tx/sec 1212 tx/sec
stdb_module 💿 person unique 1000 100 734.4±49.87µs 909.3±93.27µs 1361 tx/sec 1099 tx/sec
stdb_module 🧠 location multi_index 0 100 733.1±73.28µs 545.3±49.27µs 1363 tx/sec 1833 tx/sec
stdb_module 🧠 location multi_index 1000 100 657.7±29.78µs 867.5±100.99µs 1520 tx/sec 1152 tx/sec
stdb_module 🧠 location non_unique 0 100 238.4±27.56µs 317.6±28.14µs 4.1 Ktx/sec 3.1 Ktx/sec
stdb_module 🧠 location non_unique 1000 100 371.5±32.24µs 485.4±4.75µs 2.6 Ktx/sec 2.0 Ktx/sec
stdb_module 🧠 location unique 0 100 346.1±17.84µs 419.9±1.49µs 2.8 Ktx/sec 2.3 Ktx/sec
stdb_module 🧠 location unique 1000 100 387.4±3.45µs 740.5±9.68µs 2.5 Ktx/sec 1350 tx/sec
stdb_module 🧠 person multi_index 0 100 918.6±5.27µs 934.6±15.44µs 1088 tx/sec 1069 tx/sec
stdb_module 🧠 person multi_index 1000 100 1012.6±9.36µs 1100.3±4.60µs 987 tx/sec 908 tx/sec
stdb_module 🧠 person non_unique 0 100 428.3±76.62µs 407.1±47.91µs 2.3 Ktx/sec 2.4 Ktx/sec
stdb_module 🧠 person non_unique 1000 100 636.3±22.90µs 796.4±4.60µs 1571 tx/sec 1255 tx/sec
stdb_module 🧠 person unique 0 100 507.3±21.27µs 615.2±8.50µs 1971 tx/sec 1625 tx/sec
stdb_module 🧠 person unique 1000 100 589.3±13.41µs 817.8±18.27µs 1697 tx/sec 1222 tx/sec
stdb_raw 💿 location multi_index 0 100 343.6±1.27µs 334.3±0.59µs 2.8 Ktx/sec 2.9 Ktx/sec
stdb_raw 💿 location multi_index 1000 100 393.8±277.82µs 358.7±1.36µs 2.5 Ktx/sec 2.7 Ktx/sec
stdb_raw 💿 location non_unique 0 100 120.2±0.11µs 121.0±0.15µs 8.1 Ktx/sec 8.1 Ktx/sec
stdb_raw 💿 location non_unique 1000 100 122.7±0.99µs 131.8±86.86µs 8.0 Ktx/sec 7.4 Ktx/sec
stdb_raw 💿 location unique 0 100 242.0±0.35µs 241.9±0.32µs 4.0 Ktx/sec 4.0 Ktx/sec
stdb_raw 💿 location unique 1000 100 259.5±1.24µs 274.0±142.77µs 3.8 Ktx/sec 3.6 Ktx/sec
stdb_raw 💿 person multi_index 0 100 703.6±15.79µs 703.3±0.78µs 1421 tx/sec 1421 tx/sec
stdb_raw 💿 person multi_index 1000 100 781.5±485.57µs 781.3±480.07µs 1279 tx/sec 1279 tx/sec
stdb_raw 💿 person non_unique 0 100 219.8±0.23µs 221.0±0.17µs 4.4 Ktx/sec 4.4 Ktx/sec
stdb_raw 💿 person non_unique 1000 100 222.8±0.29µs 223.4±0.33µs 4.4 Ktx/sec 4.4 Ktx/sec
stdb_raw 💿 person unique 0 100 426.4±4.20µs 428.1±0.40µs 2.3 Ktx/sec 2.3 Ktx/sec
stdb_raw 💿 person unique 1000 100 443.9±0.93µs 446.6±0.70µs 2.2 Ktx/sec 2.2 Ktx/sec
stdb_raw 🧠 location multi_index 0 100 295.1±0.30µs 291.2±0.57µs 3.3 Ktx/sec 3.4 Ktx/sec
stdb_raw 🧠 location multi_index 1000 100 318.6±1.16µs 315.8±0.74µs 3.1 Ktx/sec 3.1 Ktx/sec
stdb_raw 🧠 location non_unique 0 100 73.7±0.62µs 74.4±0.10µs 13.3 Ktx/sec 13.1 Ktx/sec
stdb_raw 🧠 location non_unique 1000 100 75.3±0.11µs 75.8±0.10µs 13.0 Ktx/sec 12.9 Ktx/sec
stdb_raw 🧠 location unique 0 100 197.1±0.23µs 196.4±0.34µs 5.0 Ktx/sec 5.0 Ktx/sec
stdb_raw 🧠 location unique 1000 100 213.7±0.34µs 213.6±0.27µs 4.6 Ktx/sec 4.6 Ktx/sec
stdb_raw 🧠 person multi_index 0 100 607.1±0.71µs 606.9±0.76µs 1647 tx/sec 1647 tx/sec
stdb_raw 🧠 person multi_index 1000 100 634.8±0.99µs 635.1±0.75µs 1575 tx/sec 1574 tx/sec
stdb_raw 🧠 person non_unique 0 100 125.0±0.20µs 126.3±1.37µs 7.8 Ktx/sec 7.7 Ktx/sec
stdb_raw 🧠 person non_unique 1000 100 127.5±0.27µs 128.4±0.38µs 7.7 Ktx/sec 7.6 Ktx/sec
stdb_raw 🧠 person unique 0 100 331.5±0.23µs 333.9±0.26µs 2.9 Ktx/sec 2.9 Ktx/sec
stdb_raw 🧠 person unique 1000 100 347.8±0.36µs 351.1±0.39µs 2.8 Ktx/sec 2.8 Ktx/sec

Full table iterate

db on disk schema index type new latency old latency new throughput old throughput
sqlite 💿 location unique 8.8±0.08µs 8.4±0.04µs 111.3 Ktx/sec 115.8 Ktx/sec
sqlite 💿 person unique 9.4±0.13µs 8.6±0.11µs 103.9 Ktx/sec 113.5 Ktx/sec
sqlite 🧠 location unique 7.7±0.16µs 7.3±0.11µs 127.2 Ktx/sec 133.9 Ktx/sec
sqlite 🧠 person unique 8.0±0.14µs 7.5±0.11µs 122.1 Ktx/sec 130.4 Ktx/sec
stdb_module 💿 location unique 45.6±9.54µs 54.2±8.35µs 21.4 Ktx/sec 18.0 Ktx/sec
stdb_module 💿 person unique 60.2±10.64µs 67.0±11.83µs 16.2 Ktx/sec 14.6 Ktx/sec
stdb_module 🧠 location unique 48.2±7.44µs 56.9±6.04µs 20.3 Ktx/sec 17.1 Ktx/sec
stdb_module 🧠 person unique 53.3±9.54µs 58.0±11.25µs 18.3 Ktx/sec 16.8 Ktx/sec
stdb_raw 💿 location unique 9.0±0.01µs 8.9±0.02µs 108.2 Ktx/sec 109.1 Ktx/sec
stdb_raw 💿 person unique 9.0±0.01µs 8.9±0.02µs 108.2 Ktx/sec 109.4 Ktx/sec
stdb_raw 🧠 location unique 9.0±0.02µs 8.9±0.03µs 108.7 Ktx/sec 109.8 Ktx/sec
stdb_raw 🧠 person unique 9.0±0.10µs 8.9±0.02µs 108.7 Ktx/sec 109.9 Ktx/sec

Find unique key

db on disk key type load new latency old latency new throughput old throughput
sqlite 💿 u32 1000 2.3±0.01µs 2.3±0.00µs 417.1 Ktx/sec 430.6 Ktx/sec
sqlite 🧠 u32 1000 1120.9±3.81ns 1130.3±4.25ns 871.3 Ktx/sec 864.0 Ktx/sec
stdb_module 💿 u32 1000 29.5±2.76µs 31.0±2.58µs 33.1 Ktx/sec 31.5 Ktx/sec
stdb_module 🧠 u32 1000 29.3±2.01µs 30.2±2.13µs 33.3 Ktx/sec 32.4 Ktx/sec
stdb_raw 💿 u32 1000 2.2±0.01µs 2.2±0.00µs 442.3 Ktx/sec 438.7 Ktx/sec
stdb_raw 🧠 u32 1000 2.1±0.01µs 2.2±0.00µs 455.8 Ktx/sec 451.6 Ktx/sec

Filter

db on disk key type index strategy load count new latency old latency new throughput old throughput
sqlite 💿 string indexed 1000 10 5.6±0.01µs 5.6±0.06µs 173.0 Ktx/sec 173.5 Ktx/sec
sqlite 💿 string non_indexed 1000 10 49.0±0.29µs 53.3±0.10µs 19.9 Ktx/sec 18.3 Ktx/sec
sqlite 💿 u64 indexed 1000 10 5.5±0.01µs 5.3±0.01µs 178.7 Ktx/sec 184.9 Ktx/sec
sqlite 💿 u64 non_indexed 1000 10 33.4±0.06µs 32.9±0.07µs 29.2 Ktx/sec 29.7 Ktx/sec
sqlite 🧠 string indexed 1000 10 4.2±0.01µs 4.3±0.01µs 231.2 Ktx/sec 229.0 Ktx/sec
sqlite 🧠 string non_indexed 1000 10 48.1±0.33µs 52.1±0.13µs 20.3 Ktx/sec 18.7 Ktx/sec
sqlite 🧠 u64 indexed 1000 10 4.0±0.01µs 4.0±0.01µs 241.4 Ktx/sec 244.9 Ktx/sec
sqlite 🧠 u64 non_indexed 1000 10 31.6±0.06µs 31.7±0.26µs 30.9 Ktx/sec 30.8 Ktx/sec
stdb_module 💿 string indexed 1000 10 39.4±2.45µs 39.8±2.94µs 24.8 Ktx/sec 24.6 Ktx/sec
stdb_module 💿 string non_indexed 1000 10 163.7±2.01µs 163.6±0.56µs 6.0 Ktx/sec 6.0 Ktx/sec
stdb_module 💿 u64 indexed 1000 10 35.3±2.60µs 35.8±3.41µs 27.6 Ktx/sec 27.3 Ktx/sec
stdb_module 💿 u64 non_indexed 1000 10 132.9±0.72µs 138.8±21.40µs 7.3 Ktx/sec 7.0 Ktx/sec
stdb_module 🧠 string indexed 1000 10 39.0±3.69µs 37.2±3.18µs 25.0 Ktx/sec 26.3 Ktx/sec
stdb_module 🧠 string non_indexed 1000 10 164.9±1.82µs 162.4±1.40µs 5.9 Ktx/sec 6.0 Ktx/sec
stdb_module 🧠 u64 indexed 1000 10 34.9±3.21µs 34.9±2.31µs 28.0 Ktx/sec 28.0 Ktx/sec
stdb_module 🧠 u64 non_indexed 1000 10 132.6±0.21µs 131.2±8.48µs 7.4 Ktx/sec 7.4 Ktx/sec
stdb_raw 💿 string indexed 1000 10 4.7±0.01µs 4.7±0.01µs 208.6 Ktx/sec 206.8 Ktx/sec
stdb_raw 💿 string non_indexed 1000 10 122.5±0.28µs 128.7±1.10µs 8.0 Ktx/sec 7.6 Ktx/sec
stdb_raw 💿 u64 indexed 1000 10 4.6±0.02µs 4.6±0.01µs 213.5 Ktx/sec 212.0 Ktx/sec
stdb_raw 💿 u64 non_indexed 1000 10 103.7±0.10µs 107.7±0.65µs 9.4 Ktx/sec 9.1 Ktx/sec
stdb_raw 🧠 string indexed 1000 10 4.6±0.01µs 4.6±0.01µs 211.3 Ktx/sec 211.2 Ktx/sec
stdb_raw 🧠 string non_indexed 1000 10 122.5±0.41µs 127.7±0.32µs 8.0 Ktx/sec 7.6 Ktx/sec
stdb_raw 🧠 u64 indexed 1000 10 4.5±0.02µs 4.6±0.02µs 217.3 Ktx/sec 213.8 Ktx/sec
stdb_raw 🧠 u64 non_indexed 1000 10 103.6±0.10µs 107.9±0.65µs 9.4 Ktx/sec 9.0 Ktx/sec

Serialize

schema format count new latency old latency new throughput old throughput
location bsatn 100 1905.1±47.89ns 1899.3±21.74ns 50.1 Mtx/sec 50.2 Mtx/sec
location json 100 3.1±0.09µs 3.1±0.03µs 30.6 Mtx/sec 30.4 Mtx/sec
location product_value 100 548.5±0.59ns 550.3±0.35ns 173.9 Mtx/sec 173.3 Mtx/sec
person bsatn 100 2.7±0.06µs 2.6±0.03µs 35.0 Mtx/sec 36.4 Mtx/sec
person json 100 5.1±0.02µs 4.9±0.06µs 18.8 Mtx/sec 19.3 Mtx/sec
person product_value 100 662.0±1.71ns 635.0±1.24ns 144.1 Mtx/sec 150.2 Mtx/sec

Module: invoke with large arguments

arg size new latency old latency new throughput old throughput
64KiB 60.0±11.10µs 57.9±9.11µs - -

Module: print bulk

line count new latency old latency new throughput old throughput
1 30.5±2.18µs 29.6±1.80µs - -
100 203.4±1.09µs 201.7±1.53µs - -
1000 1874.6±66.56µs 1953.3±738.75µs - -

Remaining benchmarks

name new latency old latency new throughput old throughput

Please sign in to comment.