Skip to content

Commit e2eda15

Browse files
committed
sql: make Catalog a supertrait of Transaction
1 parent c64c3e6 commit e2eda15

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/sql/engine/engine.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::storage::mvcc;
1313
pub trait Engine<'a>: Sized {
1414
/// The engine's transaction type. This provides both row-level CRUD operations and
1515
/// transactional access to the schema catalog.
16-
type Transaction: Transaction + Catalog + 'a;
16+
type Transaction: Transaction + 'a;
1717

1818
/// Begins a read-write transaction.
1919
fn begin(&'a self) -> Result<Self::Transaction>;
@@ -34,7 +34,7 @@ pub trait Engine<'a>: Sized {
3434
/// All methods operate on row batches rather than single rows to amortize the
3535
/// cost. With the Raft engine, each call results in a Raft roundtrip, and we'd
3636
/// rather not have to do that for every single row that's modified.
37-
pub trait Transaction {
37+
pub trait Transaction: Catalog {
3838
/// The transaction's internal MVCC state.
3939
fn state(&self) -> &mvcc::TransactionState;
4040

@@ -58,13 +58,9 @@ pub trait Transaction {
5858
}
5959

6060
/// The catalog stores table schema information. It must be implemented for
61-
/// Engine::Transaction, and is fully transactional. For simplicity, it only
61+
/// Transaction, and is thus fully transactional. For simplicity, it only
6262
/// supports creating and dropping tables -- there are no ALTER TABLE schema
6363
/// changes, nor CREATE INDEX.
64-
///
65-
/// This type is separate from Transaction, even though Engine::Transaction
66-
/// requires transactions to implement it. This allows better control of when
67-
/// catalog access can be used (i.e. during planning, not execution).
6864
pub trait Catalog {
6965
/// Creates a new table. Errors if it already exists.
7066
fn create_table(&self, table: Table) -> Result<()>;

src/sql/execution/execute.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
use super::{aggregate, join, source, transform, write};
22
use crate::error::Result;
3-
use crate::sql::engine::{Catalog, Transaction};
3+
use crate::sql::engine::Transaction;
44
use crate::sql::planner::{Node, Plan};
55
use crate::sql::types::{Label, Rows};
66

77
/// Executes a plan, returning an execution result.
8-
///
9-
/// Takes the transaction and catalog separately, even though Transaction must
10-
/// implement Catalog, to ensure the catalog is primarily used during planning.
11-
pub fn execute_plan(
12-
plan: Plan,
13-
txn: &impl Transaction,
14-
catalog: &impl Catalog,
15-
) -> Result<ExecutionResult> {
8+
pub fn execute_plan(plan: Plan, txn: &impl Transaction) -> Result<ExecutionResult> {
169
Ok(match plan {
1710
Plan::CreateTable { schema } => {
1811
let name = schema.name.clone();
19-
catalog.create_table(schema)?;
12+
txn.create_table(schema)?;
2013
ExecutionResult::CreateTable { name }
2114
}
2215

2316
Plan::DropTable { table, if_exists } => {
24-
let existed = catalog.drop_table(&table, if_exists)?;
17+
let existed = txn.drop_table(&table, if_exists)?;
2518
ExecutionResult::DropTable { name: table, existed }
2619
}
2720

src/sql/planner/plan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl Plan {
6767
}
6868

6969
/// Executes the plan, consuming it.
70-
pub fn execute(self, txn: &(impl Transaction + Catalog)) -> Result<ExecutionResult> {
71-
execution::execute_plan(self, txn, txn)
70+
pub fn execute(self, txn: &impl Transaction) -> Result<ExecutionResult> {
71+
execution::execute_plan(self, txn)
7272
}
7373

7474
/// Optimizes the plan, consuming it. See OPTIMIZERS for the list of

0 commit comments

Comments
 (0)