Skip to content

Commit

Permalink
move physical planner
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Jan 28, 2024
1 parent cc23bf3 commit 1935a90
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 37 deletions.
5 changes: 2 additions & 3 deletions bustubx/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use tracing::span;

use crate::error::{BustubxError, BustubxResult};
use crate::planner::logical_plan::LogicalPlan;
use crate::planner::physical_planner::PhysicalPlanner;
use crate::{
buffer::buffer_pool::BufferPoolManager,
catalog::catalog::Catalog,
common::config::TABLE_HEAP_BUFFER_POOL_SIZE,
execution::{ExecutionContext, ExecutionEngine},
optimizer::Optimizer,
planner::{Planner, PlannerContext},
storage::{tuple::Tuple, DiskManager},
};
Expand Down Expand Up @@ -55,8 +55,7 @@ impl Database {
println!("{:?}", logical_plan);

// logical plan -> physical plan
let mut optimizer = Optimizer::new();
let physical_plan = optimizer.find_best(logical_plan);
let physical_plan = PhysicalPlanner::new().create_physical_plan(logical_plan);
// println!("{:?}", physical_plan);

let execution_ctx = ExecutionContext::new(&mut self.catalog);
Expand Down
2 changes: 1 addition & 1 deletion bustubx/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::span;

use crate::{
catalog::{catalog::Catalog, Schema},
optimizer::physical_plan::PhysicalPlan,
planner::physical_plan::PhysicalPlan,
storage::tuple::Tuple,
};

Expand Down
4 changes: 3 additions & 1 deletion bustubx/src/optimizer/logical_optimizer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::BustubxResult;
use crate::optimizer::rule::PushDownLimit;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

Expand Down Expand Up @@ -35,7 +36,8 @@ pub struct LogicalOptimizer {

impl LogicalOptimizer {
pub fn new() -> Self {
let rules: Vec<Arc<dyn LogicalOptimizerRule + Sync + Send>> = vec![];
let rules: Vec<Arc<dyn LogicalOptimizerRule + Sync + Send>> =
vec![Arc::new(PushDownLimit {})];

Self { rules }
}
Expand Down
28 changes: 1 addition & 27 deletions bustubx/src/optimizer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
use tracing::span;

use crate::planner::logical_plan::LogicalPlan;

use self::{physical_optimizer::PhysicalOptimizer, physical_plan::PhysicalPlan};

mod logical_optimizer;
pub mod physical_optimizer;
pub mod physical_plan;
mod rule;

pub use logical_optimizer::{LogicalOptimizer, LogicalOptimizerRule};

Check warning on line 4 in bustubx/src/optimizer/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `LogicalOptimizer`

pub struct Optimizer {
physical_optimizer: PhysicalOptimizer,
}
impl Optimizer {
pub fn new() -> Self {
Self {
physical_optimizer: PhysicalOptimizer {},
}
}

pub fn find_best(&mut self, logical_plan: LogicalPlan) -> PhysicalPlan {
let _find_best_span = span!(tracing::Level::INFO, "optimizer.find_best").entered();
// TODO optimize logical plan

// optimize physical plan
self.physical_optimizer.find_best(logical_plan)
}
}
3 changes: 3 additions & 0 deletions bustubx/src/optimizer/rule/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod push_down_limit;

pub use push_down_limit::PushDownLimit;
15 changes: 15 additions & 0 deletions bustubx/src/optimizer/rule/push_down_limit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::error::BustubxResult;
use crate::optimizer::LogicalOptimizerRule;
use crate::planner::logical_plan::LogicalPlan;

pub struct PushDownLimit;

impl LogicalOptimizerRule for PushDownLimit {
fn try_optimize(&self, plan: &LogicalPlan) -> BustubxResult<Option<LogicalPlan>> {
todo!()
}

fn name(&self) -> &str {
"PushDownLimit"
}
}
2 changes: 2 additions & 0 deletions bustubx/src/planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub mod logical_plan;
pub mod logical_plan_v2;
pub mod operator;
pub mod order_by;
pub mod physical_plan;
pub mod physical_planner;
pub mod plan_create_index;
pub mod table_ref;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use crate::planner::logical_plan::LogicalPlan;

use super::physical_plan::{build_plan, PhysicalPlan};

pub struct PhysicalOptimizer {}
impl PhysicalOptimizer {
// output optimized physical plan
pub fn find_best(&self, logical_plan: LogicalPlan) -> PhysicalPlan {
// TODO optimization
pub struct PhysicalPlanner;

impl PhysicalPlanner {
pub fn new() -> Self {
Self {}
}

pub fn create_physical_plan(&self, logical_plan: LogicalPlan) -> PhysicalPlan {
let logical_plan = Arc::new(logical_plan);
build_plan(logical_plan.clone())
}
Expand Down

0 comments on commit 1935a90

Please sign in to comment.