Skip to content

Commit

Permalink
sql: remove Engine::scan_index()
Browse files Browse the repository at this point in the history
This was only used for tests.
  • Loading branch information
erikgrinaker committed Jul 1, 2024
1 parent 926438d commit 21814af
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 47 deletions.
7 changes: 0 additions & 7 deletions src/sql/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,8 @@ pub trait Transaction {
fn scan(&self, table: &str, filter: Option<Expression>) -> Result<Rows>;
/// Updates table rows by primary key. Uses a BTreeMap for test determinism.
fn update(&self, table: &str, rows: BTreeMap<Value, Row>) -> Result<()>;

/// Scans a column's index entries.
/// TODO: this is only used for tests, remove it.
fn scan_index(&self, table: &str, column: &str) -> Result<IndexScan>;
}

/// An index scan iterator.
pub type IndexScan = Box<dyn Iterator<Item = Result<(Value, BTreeSet<Value>)>>>;

/// The catalog stores table schema information. It is required for
/// Engine::Transaction, and thus fully transactional. For simplicity, it only
/// supports very simple operations: creating and dropping tables. There are no
Expand Down
18 changes: 1 addition & 17 deletions src/sql/engine/local.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::Catalog;
use crate::encoding::{self, Key as _, Value as _};
use crate::errinput;
use crate::error::Result;
use crate::sql::types::{Expression, Row, Rows, Table, Value};
use crate::storage::{self, mvcc};
use crate::{errdata, errinput};

use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down Expand Up @@ -268,22 +268,6 @@ impl<E: storage::Engine> super::Transaction for Transaction<E> {
))
}

fn scan_index(&self, table: &str, column: &str) -> Result<super::IndexScan> {
debug_assert!(self.has_index(table, column)?, "index scan without index");
Ok(Box::new(
self.txn.scan_prefix(&KeyPrefix::Index(table.into(), column.into()).encode()).map(
|r| {
r.and_then(|(k, v)| {
let Key::Index(_, _, value) = Key::decode(&k)? else {
return errdata!("invalid index key");
};
Ok((value.into_owned(), BTreeSet::decode(&v)?))
})
},
),
))
}

fn update(&self, table: &str, rows: BTreeMap<Value, Row>) -> Result<()> {
let table = self.must_get_table(table)?;

Expand Down
2 changes: 1 addition & 1 deletion src/sql/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod local;
mod raft;
mod session;

pub use engine::{Catalog, Engine, IndexScan, Transaction};
pub use engine::{Catalog, Engine, Transaction};
pub use local::{Key, Local};
pub use raft::{Raft, Status};
pub use session::{Session, StatementResult};
23 changes: 1 addition & 22 deletions src/sql/engine/raft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Catalog, Engine as _, IndexScan, Transaction as _};
use super::{Catalog, Engine as _, Transaction as _};
use crate::encoding::{self, bincode, Value as _};
use crate::errdata;
use crate::error::Result;
Expand Down Expand Up @@ -187,15 +187,6 @@ impl<'a> super::Transaction for Transaction<'a> {
Ok(Box::new(scan.into_iter().map(Ok)))
}

fn scan_index(&self, table: &str, column: &str) -> Result<IndexScan> {
let scan: Vec<_> = self.engine.read(Read::ScanIndex {
txn: (&self.state).into(),
table: table.into(),
column: column.into(),
})?;
Ok(Box::new(scan.into_iter().map(Ok)))
}

fn update(&self, table: &str, rows: BTreeMap<Value, Row>) -> Result<()> {
self.engine.write(Write::Update { txn: (&self.state).into(), table: table.into(), rows })
}
Expand Down Expand Up @@ -338,13 +329,6 @@ impl<E: storage::Engine> raft::State for State<E> {
.collect::<Result<Vec<_>>>()?
.encode()
}
Read::ScanIndex { txn, table, column } => self
.local
.resume(txn.into_owned())?
.scan_index(&table, &column)?
.collect::<Result<Vec<_>>>()?
.encode(),

Read::GetTable { txn, table } => {
self.local.resume(txn.into_owned())?.get_table(&table)?.encode()
}
Expand Down Expand Up @@ -380,11 +364,6 @@ enum Read<'a> {
table: Cow<'a, str>,
filter: Option<Expression>,
},
ScanIndex {
txn: Cow<'a, mvcc::TransactionState>,
table: Cow<'a, str>,
column: Cow<'a, str>,
},

GetTable {
txn: Cow<'a, mvcc::TransactionState>,
Expand Down

0 comments on commit 21814af

Please sign in to comment.