-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up expression and rules modules
- Loading branch information
1 parent
c41cf41
commit f96f771
Showing
13 changed files
with
99 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
//! Types for logical and physical expressions in the optimizer. | ||
use crate::memo::GroupId; | ||
use crate::memo::{GroupId, ScalarGroupId}; | ||
use crate::operator::relational::logical::LogicalOperator; | ||
use crate::operator::relational::physical::PhysicalOperator; | ||
|
||
/// A logical expression in the memo table. | ||
/// | ||
/// References children using [`GroupId`]s for expression sharing | ||
/// and memoization. | ||
pub type LogicalExpression = LogicalOperator<GroupId, GroupId>; | ||
/// References children using [`GroupId`]s for expression sharing and memoization. | ||
pub type LogicalExpression = LogicalOperator<GroupId, ScalarGroupId>; | ||
|
||
/// A physical expression in the memo table. | ||
/// | ||
/// Like [`LogicalExpression`] but with specific implementation | ||
/// strategies. | ||
pub type PhysicalExpression = PhysicalOperator<GroupId, GroupId>; | ||
/// Like [`LogicalExpression`] but with specific implementation strategies. | ||
pub type PhysicalExpression = PhysicalOperator<GroupId, ScalarGroupId>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
//! The rule for implementing `Join` as a `HashJoin`. | ||
//! | ||
//! See [`HashJoinRule`] for more information. | ||
use super::*; | ||
use crate::operator::relational::{ | ||
logical::LogicalOperator, | ||
logical::{join::Join, LogicalOperator}, | ||
physical::{join::hash_join::HashJoin, PhysicalOperator}, | ||
}; | ||
|
||
/// Implementation rule that converts a logical join into a hash join physical operator | ||
/// A unit / marker struct for implementing `HashJoin`. | ||
/// | ||
/// This implementation rule converts a logical `Join` into a physical `HashJoin` operator. | ||
pub struct HashJoinRule; | ||
|
||
// TODO: rule may fail, need to check join condition | ||
// https://github.com/cmu-db/optd/issues/15 | ||
impl ImplementationRule for HashJoinRule { | ||
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> { | ||
if let LogicalOperator::Join(join) = expr { | ||
return Some(PhysicalOperator::HashJoin(HashJoin { | ||
join_type: join.join_type, | ||
probe_side: join.left, | ||
build_side: join.right, | ||
condition: join.condition, | ||
})); | ||
} | ||
None | ||
let LogicalOperator::Join(Join { | ||
join_type, | ||
left, | ||
right, | ||
condition, | ||
}) = expr | ||
else { | ||
return None; | ||
}; | ||
|
||
Some(PhysicalOperator::HashJoin(HashJoin { | ||
join_type, | ||
probe_side: left, | ||
build_side: right, | ||
condition, | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
//! The rule for implementing a logical `Filter` as a physical `Filter`. | ||
//! | ||
//! See [`PhysicalFilterRule`] for more information. | ||
use super::*; | ||
use crate::operator::relational::{ | ||
logical::LogicalOperator, | ||
physical::{filter::filter::Filter, PhysicalOperator}, | ||
logical::{filter::Filter as LogicalFilter, LogicalOperator}, | ||
physical::{filter::filter::PhysicalFilter, PhysicalOperator}, | ||
}; | ||
|
||
/// Implementation rule that converts a logical filter into a filter physical operator. | ||
/// A unit / marker struct for implementing `PhysicalFilterRule`. | ||
/// | ||
/// This mplementation rule converts a logical `Filter` into a physical `Filter` operator. | ||
pub struct PhysicalFilterRule; | ||
|
||
impl ImplementationRule for PhysicalFilterRule { | ||
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> { | ||
if let LogicalOperator::Filter(filter) = expr { | ||
return Some(PhysicalOperator::Filter(Filter { | ||
child: filter.child, | ||
predicate: filter.predicate, | ||
})); | ||
} | ||
let LogicalOperator::Filter(LogicalFilter { child, predicate }) = expr else { | ||
return None; | ||
}; | ||
|
||
None | ||
Some(PhysicalOperator::Filter(PhysicalFilter { child, predicate })) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
//! The rule for implementing `Scan` as a `TableScan`. | ||
//! | ||
//! See [`TableScanRule`] for more information. | ||
use crate::operator::relational::{ | ||
logical::LogicalOperator, | ||
logical::{scan::Scan, LogicalOperator}, | ||
physical::{scan::table_scan::TableScan, PhysicalOperator}, | ||
}; | ||
|
||
use super::*; | ||
|
||
// Implementation rule that converts a logical scan into a table scan physical operator. | ||
/// A unit / marker struct for implementing `TableScan`. | ||
/// | ||
/// This implementation rule converts a logical `Scan` into a physical `TableScan` operator. | ||
pub struct TableScanRule; | ||
|
||
impl ImplementationRule for TableScanRule { | ||
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> { | ||
if let LogicalOperator::Scan(scan) = expr { | ||
return Some(PhysicalOperator::TableScan(TableScan { | ||
table_name: scan.table_name, | ||
predicate: scan.predicate, | ||
})); | ||
} | ||
let LogicalOperator::Scan(Scan { | ||
table_name, | ||
predicate, | ||
}) = expr | ||
else { | ||
return None; | ||
}; | ||
|
||
None | ||
Some(PhysicalOperator::TableScan(TableScan { | ||
table_name, | ||
predicate, | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
//! This module contains all rules that the optimizer has available, including both transformation | ||
//! and implementation rules. | ||
mod implementation; | ||
mod transformation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters