Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable query engine v2 by default #729

Merged
merged 9 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use query engine v2 by default and bump version
Signed-off-by: Runji Wang <wangrunji0408@163.com>
  • Loading branch information
wangrunji0408 committed Nov 9, 2022
commit 5232534bfc6c22f758abda37f38dc18b1fc0ebca
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "risinglight"
version = "0.1.3"
version = "0.2.0-alpha"
description = "An OLAP database system for educational purpose"
license = "Apache-2.0"
readme = "README.md"
Expand Down
58 changes: 30 additions & 28 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::v1::optimizer::Optimizer;
pub struct Database {
catalog: RootCatalogRef,
storage: StorageImpl,
use_v2: AtomicBool,
use_v1: AtomicBool,
}

impl Database {
Expand All @@ -37,7 +37,7 @@ impl Database {
Database {
catalog: storage.catalog().clone(),
storage: StorageImpl::InMemoryStorage(Arc::new(storage)),
use_v2: AtomicBool::new(false),
use_v1: AtomicBool::new(false),
}
}

Expand All @@ -48,7 +48,7 @@ impl Database {
Database {
catalog: storage.catalog().clone(),
storage: StorageImpl::SecondaryStorage(storage),
use_v2: AtomicBool::new(false),
use_v1: AtomicBool::new(false),
}
}

Expand Down Expand Up @@ -156,46 +156,48 @@ impl Database {
} else if cmd == "dt" {
self.run_dt()
} else if cmd == "v1" || cmd == "v2" {
self.use_v2.store(cmd == "v2", Ordering::Relaxed);
println!("switched to planner {cmd}");
self.use_v1.store(cmd == "v1", Ordering::Relaxed);
println!("switched to query engine {cmd}");
Ok(vec![])
} else {
Err(Error::InternalError("unsupported command".to_string()))
}
}

/// Run SQL queries and return the outputs.

pub async fn run(&self, sql: &str) -> Result<Vec<Chunk>, Error> {
if let Some(cmdline) = sql.trim().strip_prefix('\\') {
return self.run_internal(cmdline).await;
}
if self.use_v1.load(Ordering::Relaxed) {
return self.run_v1(sql).await;
}

// parse
let stmts = parse(sql)?;

if self.use_v2.load(Ordering::Relaxed) {
let mut outputs: Vec<Chunk> = vec![];
for stmt in stmts {
let mut binder = crate::binder_v2::Binder::new(self.catalog.clone());
let bound = binder.bind(stmt)?;
let optimized = crate::planner::optimize(&bound);
let executor = match self.storage.clone() {
StorageImpl::InMemoryStorage(s) => {
crate::executor_v2::build(self.catalog.clone(), s, &optimized)
}
StorageImpl::SecondaryStorage(s) => {
crate::executor_v2::build(self.catalog.clone(), s, &optimized)
}
};
let output = executor.try_collect().await?;
let chunk = Chunk::new(output);
// TODO: set name
outputs.push(chunk);
}
return Ok(outputs);
let mut outputs: Vec<Chunk> = vec![];
for stmt in stmts {
let mut binder = crate::binder_v2::Binder::new(self.catalog.clone());
let bound = binder.bind(stmt)?;
let optimized = crate::planner::optimize(&bound);
let executor = match self.storage.clone() {
StorageImpl::InMemoryStorage(s) => {
crate::executor_v2::build(self.catalog.clone(), s, &optimized)
}
StorageImpl::SecondaryStorage(s) => {
crate::executor_v2::build(self.catalog.clone(), s, &optimized)
}
};
let output = executor.try_collect().await?;
let chunk = Chunk::new(output);
// TODO: set name
outputs.push(chunk);
}
Ok(outputs)
}

/// Run SQL queries using query engine v1.
async fn run_v1(&self, sql: &str) -> Result<Vec<Chunk>, Error> {
let stmts = parse(sql)?;
let mut binder = Binder::new(self.catalog.clone());
let logical_planner = LogicalPlaner::default();
let mut optimizer = Optimizer {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ async fn main() -> Result<()> {
.with(fmt_layer)
.init();

info!("using query engine v2. type '\\v1' to use the legacy engine");

let db = if args.memory {
info!("using memory engine");
Database::new_in_memory()
Expand Down
6 changes: 3 additions & 3 deletions tests/sqllogictest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl Display for Engine {
}
}

pub async fn test(filename: impl AsRef<Path>, engine: Engine, v2: bool) -> Result<()> {
pub async fn test(filename: impl AsRef<Path>, engine: Engine, v1: bool) -> Result<()> {
let db = match engine {
Engine::Disk => Database::new_on_disk(SecondaryStorageOptions::default_for_test()).await,
Engine::Mem => Database::new_in_memory(),
};
if v2 {
db.run_internal("v2").await.unwrap();
if v1 {
db.run_internal("v1").await.unwrap();
}

let db = DatabaseWrapper(db);
Expand Down
6 changes: 3 additions & 3 deletions tests/sqllogictest/tests/sqllogictest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
let mut tests = vec![];

for version in ["v1", "v2"] {
let v2 = version == "v2";
let v1 = version == "v1";
let paths = glob::glob(PATTERN).expect("failed to find test files");
for entry in paths {
let path = entry.expect("failed to read glob entry");
Expand All @@ -28,14 +28,14 @@ fn main() {
let engine = Engine::Mem;
tests.push(Trial::test(
format!("{}::{}::{}", version, engine, subpath),
move || Ok(build_runtime().block_on(test(&path, engine, v2))?),
move || Ok(build_runtime().block_on(test(&path, engine, v1))?),
));
}
if !DISK_BLOCKLIST.iter().any(|p| subpath.contains(p)) {
let engine = Engine::Disk;
tests.push(Trial::test(
format!("{}::{}::{}", version, engine, subpath),
move || Ok(build_runtime().block_on(test(&path, engine, v2))?),
move || Ok(build_runtime().block_on(test(&path, engine, v1))?),
));
}
}
Expand Down