Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ PYO3_PYTHON ?= /usr/bin/python3.12
TPCC_MEASURE_TIME ?= 15
TPCC_NUM_WARE ?= 1
TPCC_PPROF_OUTPUT ?= /tmp/tpcc_lmdb.svg
TPCC_HEAPTRACK_MEASURE_TIME ?= 300
TPCC_HEAPTRACK_OUTPUT ?= /tmp/tpcc_lmdb_heaptrack
TPCC_SQLITE_PROFILE ?= balanced

.PHONY: test test-python test-wasm test-slt test-all wasm-build check tpcc tpcc-kitesql-rocksdb tpcc-kitesql-lmdb tpcc-lmdb-flamegraph tpcc-sqlite tpcc-sqlite-practical tpcc-sqlite-balanced tpcc-dual cargo-check build wasm-examples native-examples fmt clippy
.PHONY: test test-python test-wasm test-slt test-all wasm-build check tpcc tpcc-kitesql-rocksdb tpcc-kitesql-lmdb tpcc-lmdb-flamegraph tpcc-lmdb-heaptrack tpcc-sqlite tpcc-sqlite-practical tpcc-sqlite-balanced tpcc-dual cargo-check build wasm-examples native-examples fmt clippy

## Run default Rust tests in the current environment (non-WASM).
test:
Expand Down Expand Up @@ -66,6 +68,16 @@ tpcc-kitesql-lmdb:
tpcc-lmdb-flamegraph:
CARGO_PROFILE_RELEASE_DEBUG=true $(CARGO) run -p tpcc --release --features pprof -- --backend kitesql-lmdb --measure-time $(TPCC_MEASURE_TIME) --num-ware $(TPCC_NUM_WARE) --pprof-output $(TPCC_PPROF_OUTPUT)

## Execute TPCC on LMDB under heaptrack and emit a heap profile.
tpcc-lmdb-heaptrack:
@command -v heaptrack >/dev/null || { echo "heaptrack is not installed"; exit 1; }
$(CARGO) build -p tpcc --release
@mkdir -p $(dir $(TPCC_HEAPTRACK_OUTPUT))
heaptrack -o $(TPCC_HEAPTRACK_OUTPUT) ./target/release/tpcc --backend kitesql-lmdb --measure-time $(TPCC_HEAPTRACK_MEASURE_TIME) --num-ware $(TPCC_NUM_WARE)
@echo "heaptrack output:"
@ls -1 $(TPCC_HEAPTRACK_OUTPUT)*
@echo "open gui: heaptrack_gui $$(ls -1 $(TPCC_HEAPTRACK_OUTPUT)* | tail -n 1)"

## Execute the TPCC workload on SQLite with the practical profile.
tpcc-sqlite:
$(CARGO) run -p tpcc --release -- --backend sqlite --sqlite-profile $(TPCC_SQLITE_PROFILE) --path kite_sql_tpcc.sqlite
Expand Down
43 changes: 22 additions & 21 deletions src/binder/alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use sqlparser::ast::{AlterColumnOperation, AlterTableOperation, ColumnOption, ObjectName};

use std::borrow::Cow;
use std::sync::Arc;

use super::{attach_span_if_absent, is_valid_identifier, Binder};
use crate::binder::lower_case_name;
use crate::binder::{lower_case_name, lower_ident};
use crate::catalog::TableName;
use crate::errors::DatabaseError;
use crate::expression::ScalarExpression;
use crate::planner::operator::alter_table::add_column::AddColumnOperator;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
name: &ObjectName,
operation: &AlterTableOperation,
) -> Result<LogicalPlan, DatabaseError> {
let table_name: Arc<str> = lower_case_name(name)?.into();
let table_name: TableName = lower_case_name(name)?.into();
let table = self
.context
.table(table_name.clone())?
Expand Down Expand Up @@ -137,11 +137,11 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
old_column_name,
new_column_name,
} => {
let old_column_name = old_column_name.value.to_lowercase();
let new_column_name = new_column_name.value.to_lowercase();
let old_column_name = lower_ident(old_column_name);
let new_column_name = lower_ident(new_column_name).into_owned();
let old_column = table
.get_column_by_name(&old_column_name)
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.clone()))?;
.get_column_by_name(old_column_name.as_ref())
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.to_string()))?;

if !is_valid_identifier(&new_column_name) {
return Err(DatabaseError::invalid_column(
Expand All @@ -152,7 +152,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
LogicalPlan::new(
Operator::ChangeColumn(ChangeColumnOperator {
table_name,
old_column_name,
old_column_name: old_column_name.into_owned(),
new_column_name,
data_type: old_column.datatype().clone(),
default_change: DefaultChange::NoChange,
Expand All @@ -162,10 +162,10 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
)
}
AlterTableOperation::AlterColumn { column_name, op } => {
let old_column_name = column_name.value.to_lowercase();
let old_column_name = lower_ident(column_name);
let old_column = table
.get_column_by_name(&old_column_name)
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.clone()))?;
.get_column_by_name(old_column_name.as_ref())
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.to_string()))?;
let old_data_type = old_column.datatype().clone();

let (data_type, default_change, not_null_change) = match op {
Expand Down Expand Up @@ -213,8 +213,8 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
LogicalPlan::new(
Operator::ChangeColumn(ChangeColumnOperator {
table_name,
new_column_name: old_column_name.clone(),
old_column_name,
new_column_name: old_column_name.to_string(),
old_column_name: old_column_name.into_owned(),
data_type,
default_change,
not_null_change,
Expand All @@ -233,10 +233,11 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
"MODIFY COLUMN does not currently support column positions".to_string(),
));
}
let old_column_name = col_name.value.to_lowercase();
let old_column_name = lower_ident(col_name);
let _ = table
.get_column_by_name(&old_column_name)
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.clone()))?;
.get_column_by_name(old_column_name.as_ref())
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.to_string()))?;
let old_column_name = old_column_name.into_owned();
let data_type = LogicalType::try_from(data_type.clone())?;
let (default_change, not_null_change) =
self.bind_change_column_options(options, &data_type)?;
Expand Down Expand Up @@ -265,11 +266,11 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
"CHANGE COLUMN does not currently support column positions".to_string(),
));
}
let old_column_name = old_name.value.to_lowercase();
let new_column_name = new_name.value.to_lowercase();
let old_column_name = lower_ident(old_name);
let new_column_name = lower_ident(new_name).into_owned();
let _ = table
.get_column_by_name(&old_column_name)
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.clone()))?;
.get_column_by_name(old_column_name.as_ref())
.ok_or_else(|| DatabaseError::column_not_found(old_column_name.to_string()))?;

if !is_valid_identifier(&new_column_name) {
return Err(DatabaseError::invalid_column(
Expand All @@ -283,7 +284,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
LogicalPlan::new(
Operator::ChangeColumn(ChangeColumnOperator {
table_name,
old_column_name,
old_column_name: old_column_name.into_owned(),
new_column_name,
data_type,
default_change,
Expand Down
4 changes: 2 additions & 2 deletions src/binder/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::binder::{lower_case_name, Binder, Source};
use crate::catalog::TableName;
use crate::errors::DatabaseError;
use crate::planner::operator::analyze::AnalyzeOperator;
use crate::planner::operator::table_scan::TableScanOperator;
Expand All @@ -21,11 +22,10 @@ use crate::planner::{Childrens, LogicalPlan};
use crate::storage::Transaction;
use crate::types::value::DataValue;
use sqlparser::ast::ObjectName;
use std::sync::Arc;

impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
pub(crate) fn bind_analyze(&mut self, name: &ObjectName) -> Result<LogicalPlan, DatabaseError> {
let table_name: Arc<str> = lower_case_name(name)?.into();
let table_name: TableName = lower_case_name(name)?.into();

let table = self
.context
Expand Down
4 changes: 2 additions & 2 deletions src/binder/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;

use super::*;
use crate::catalog::TableName;
use crate::errors::DatabaseError;
use crate::planner::operator::copy_from_file::CopyFromFileOperator;
use crate::planner::operator::copy_to_file::CopyToFileOperator;
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
));
}
};
let table_name: Arc<str> = lower_case_name(&table_name)?.into();
let table_name: TableName = lower_case_name(&table_name)?.into();

if let Some(table) = self.context.table(table_name.clone())? {
let schema_ref = table.schema_ref().clone();
Expand Down
6 changes: 3 additions & 3 deletions src/binder/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::binder::{lower_case_name, Binder, Source};
use crate::catalog::TableName;
use crate::errors::DatabaseError;
use crate::expression::ScalarExpression;
use crate::planner::operator::create_index::CreateIndexOperator;
Expand All @@ -23,7 +24,6 @@ use crate::storage::Transaction;
use crate::types::index::IndexType;
use crate::types::value::DataValue;
use sqlparser::ast::{IndexColumn, ObjectName};
use std::sync::Arc;

impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
pub(crate) fn bind_create_index(
Expand All @@ -34,7 +34,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
if_not_exists: bool,
is_unique: bool,
) -> Result<LogicalPlan, DatabaseError> {
let table_name: Arc<str> = lower_case_name(table_name)?.into();
let table_name: TableName = lower_case_name(table_name)?.into();
let index_name = name
.ok_or(DatabaseError::InvalidIndex)
.and_then(lower_case_name)?;
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
Operator::CreateIndex(CreateIndexOperator {
table_name,
columns,
index_name,
index_name: index_name.into_owned(),
if_not_exists,
ty,
}),
Expand Down
14 changes: 7 additions & 7 deletions src/binder/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.

use super::{attach_span_if_absent, is_valid_identifier, Binder};
use crate::binder::lower_case_name;
use crate::catalog::{ColumnCatalog, ColumnDesc};
use crate::binder::{lower_case_name, lower_ident};
use crate::catalog::{ColumnCatalog, ColumnDesc, TableName};
use crate::errors::DatabaseError;
use crate::expression::ScalarExpression;
use crate::planner::operator::create_table::CreateTableOperator;
Expand All @@ -27,7 +27,6 @@ use itertools::Itertools;
use sqlparser::ast::{ColumnDef, ColumnOption, Expr, IndexColumn, ObjectName, TableConstraint};
use std::borrow::Cow;
use std::collections::HashSet;
use std::sync::Arc;

impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
// TODO: TableConstraint
Expand All @@ -38,7 +37,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
constraints: &[TableConstraint],
if_not_exists: bool,
) -> Result<LogicalPlan, DatabaseError> {
let table_name: Arc<str> = lower_case_name(name)?.into();
let table_name: TableName = lower_case_name(name)?.into();

if !is_valid_identifier(&table_name) {
return Err(attach_span_if_absent(
Expand Down Expand Up @@ -117,11 +116,11 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
"only identifier columns are supported in `PRIMARY KEY/UNIQUE`".to_string(),
));
};
let column_name = ident.value.to_lowercase();
let column_name = lower_ident(ident);

if let Some(column) = table_columns
.iter_mut()
.find(|column| column.name() == column_name)
.find(|column| column.name() == column_name.as_ref())
{
fn_constraint(i, column.desc_mut())
}
Expand All @@ -134,7 +133,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
column_def: &ColumnDef,
column_index: Option<usize>,
) -> Result<ColumnCatalog, DatabaseError> {
let column_name = column_def.name.value.to_lowercase();
let column_name = lower_ident(&column_def.name).into_owned();
let mut column_desc = ColumnDesc::new(
LogicalType::try_from(column_def.data_type.clone())?,
None,
Expand Down Expand Up @@ -192,6 +191,7 @@ mod tests {
use crate::utils::lru::SharedLruCache;
use std::hash::RandomState;
use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
use tempfile::TempDir;

#[test]
Expand Down
11 changes: 6 additions & 5 deletions src/binder/create_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::binder::{lower_case_name, lower_ident, Binder};
use crate::catalog::view::View;
use crate::catalog::{ColumnCatalog, ColumnRef};
use crate::catalog::{ColumnCatalog, ColumnRef, TableName};
use crate::errors::DatabaseError;
use crate::expression::{AliasType, ScalarExpression};
use crate::planner::operator::create_view::CreateViewOperator;
Expand All @@ -24,7 +24,6 @@ use crate::storage::Transaction;
use crate::types::value::DataValue;
use itertools::Itertools;
use sqlparser::ast::{ObjectName, Query, ViewColumnDef};
use std::sync::Arc;
use ulid::Ulid;

impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
Expand All @@ -36,7 +35,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
query: &Query,
) -> Result<LogicalPlan, DatabaseError> {
fn projection_exprs(
view_name: &Arc<str>,
view_name: &TableName,
mapping_schema: &[ColumnRef],
column_names: impl Iterator<Item = String>,
) -> Vec<ScalarExpression> {
Expand All @@ -62,7 +61,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
.collect_vec()
}

let view_name: Arc<str> = lower_case_name(name)?.into();
let view_name: TableName = lower_case_name(name)?.into();
let mut plan = self.bind_query(query)?;

let mapping_schema = plan.output_schema();
Expand All @@ -79,7 +78,9 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
projection_exprs(
&view_name,
mapping_schema,
columns.iter().map(|column| lower_ident(&column.name)),
columns
.iter()
.map(|column| lower_ident(&column.name).into_owned()),
)
};
plan = self.bind_project(plan, exprs)?;
Expand Down
4 changes: 2 additions & 2 deletions src/binder/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::binder::{lower_case_name, Binder};
use crate::catalog::TableName;
use crate::errors::DatabaseError;
use crate::planner::operator::delete::DeleteOperator;
use crate::planner::operator::Operator;
Expand All @@ -21,7 +22,6 @@ use crate::storage::Transaction;
use crate::types::value::DataValue;
use itertools::Itertools;
use sqlparser::ast::{Expr, TableFactor, TableWithJoins};
use std::sync::Arc;

impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
pub(crate) fn bind_delete(
Expand All @@ -30,7 +30,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
selection: &Option<Expr>,
) -> Result<LogicalPlan, DatabaseError> {
if let TableFactor::Table { name, .. } = &from.relation {
let table_name: Arc<str> = lower_case_name(name)?.into();
let table_name: TableName = lower_case_name(name)?.into();
let table = self
.context
.table(table_name.clone())?
Expand Down
4 changes: 2 additions & 2 deletions src/binder/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
// limitations under the License.

use crate::binder::{lower_case_name, Binder};
use crate::catalog::TableName;
use crate::errors::DatabaseError;
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<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A> {
pub(crate) fn bind_describe(
&mut self,
name: &ObjectName,
) -> Result<LogicalPlan, DatabaseError> {
let table_name: Arc<str> = lower_case_name(name)?.into();
let table_name: TableName = lower_case_name(name)?.into();

Ok(LogicalPlan::new(
Operator::Describe(DescribeOperator { table_name }),
Expand Down
2 changes: 1 addition & 1 deletion src/binder/drop_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
Ok(LogicalPlan::new(
Operator::DropIndex(DropIndexOperator {
table_name,
index_name,
index_name: index_name.into_owned(),
if_exists: *if_exists,
}),
Childrens::None,
Expand Down
Loading
Loading