Skip to content

Commit

Permalink
sql: use shared txn borrows during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jun 18, 2024
1 parent 9e6ace8 commit a5e12fd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/sql/execution/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::sql::plan::{Node, Plan};
use crate::sql::types::{Columns, Row, Rows};

/// Executes a plan, returning an execution result.
pub fn execute_plan(plan: Plan, txn: &mut impl Transaction) -> Result<ExecutionResult> {
pub fn execute_plan(plan: Plan, txn: &impl Transaction) -> Result<ExecutionResult> {
Ok(match plan {
Plan::CreateTable { schema } => {
let name = schema.name.clone();
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn execute_plan(plan: Plan, txn: &mut impl Transaction) -> Result<ExecutionR
///
/// TODO: since iterators are lazy, make this infallible and move all catalog
/// lookups to planning.
pub fn execute(node: Node, txn: &mut impl Transaction) -> Result<QueryIterator> {
pub fn execute(node: Node, txn: &impl Transaction) -> Result<QueryIterator> {
match node {
Node::Aggregation { source, aggregates } => {
let source = execute(*source, txn)?;
Expand Down
4 changes: 2 additions & 2 deletions src/sql/execution/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::sql::engine::Transaction;
use crate::sql::types::schema::Table;

// Creates a table (i.e. CREATE TABLE).
pub(super) fn create_table(txn: &mut impl Transaction, schema: Table) -> Result<()> {
pub(super) fn create_table(txn: &impl Transaction, schema: Table) -> Result<()> {
txn.create_table(schema)
}

/// Deletes a table (i.e. DROP TABLE). Returns true if the table existed.
pub(super) fn drop_table(txn: &mut impl Transaction, table: &str, if_exists: bool) -> Result<bool> {
pub(super) fn drop_table(txn: &impl Transaction, table: &str, if_exists: bool) -> Result<bool> {
// TODO the planner should deal with this.
if if_exists && txn.get_table(table)?.is_none() {
return Ok(false);
Expand Down
6 changes: 3 additions & 3 deletions src/sql/execution/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::sql::types::{Column, Expression, Row, Value};

/// A table scan source.
pub(super) fn scan(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
filter: Option<Expression>,
) -> Result<QueryIterator> {
Expand All @@ -19,7 +19,7 @@ pub(super) fn scan(

/// A primary key lookup source.
pub(super) fn lookup_key(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
keys: Vec<Value>,
) -> Result<QueryIterator> {
Expand All @@ -40,7 +40,7 @@ pub(super) fn lookup_key(

/// An index lookup source.
pub(super) fn lookup_index(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
column: &str,
values: Vec<Value>,
Expand Down
6 changes: 3 additions & 3 deletions src/sql/execution/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::sql::types::{Expression, Row, Value};
/// Deletes rows, taking primary keys from the source (i.e. DELETE).
/// Returns the number of rows deleted.
pub(super) fn delete(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
mut source: QueryIterator,
) -> Result<u64> {
Expand All @@ -26,7 +26,7 @@ pub(super) fn delete(
///
/// TODO: this should take rows from a values source.
pub(super) fn insert(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
columns: Vec<String>,
values: Vec<Vec<Expression>>,
Expand All @@ -50,7 +50,7 @@ pub(super) fn insert(
/// Updates rows passed in from the source (i.e. UPDATE). Returns the number of
/// rows updated.
pub(super) fn update(
txn: &mut impl Transaction,
txn: &impl Transaction,
table: &str,
mut source: QueryIterator,
expressions: Vec<(usize, Expression)>,
Expand Down

0 comments on commit a5e12fd

Please sign in to comment.