-
Notifications
You must be signed in to change notification settings - Fork 7
First PR cleanup #18
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
Merged
Merged
First PR cleanup #18
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 +1,15 @@ | ||
//! A logical filter. | ||
|
||
/// Logical filter operator that selects rows matching a condition. | ||
/// | ||
/// Takes input relation (`Relation`) and filters rows using a boolean predicate (`Scalar`). | ||
#[derive(Clone)] | ||
pub struct Filter<Relation, Scalar> { | ||
/// The input relation. | ||
pub child: Relation, | ||
/// The filter expression denoting the predicate condition for this filter operation. | ||
/// | ||
/// For example, a filter predicate could be `column_a > 42`, or it could be something like | ||
/// `column_b < 100 AND column_c > 1000`. | ||
pub predicate: Scalar, | ||
} |
This file contains hidden or 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,11 +1,19 @@ | ||
//! A logical join. | ||
|
||
/// Logical join operator that combines rows from two relations. | ||
/// | ||
/// Takes left and right relations (`Relation`) and joins their rows using a join condition | ||
/// (`Scalar`). | ||
#[derive(Clone)] | ||
pub struct Join<Relation, Scalar> { | ||
/// TODO(alexis) Mocked for now. | ||
pub join_type: String, | ||
/// The left input relation. | ||
pub left: Relation, | ||
/// The right input relation. | ||
pub right: Relation, | ||
/// The join expression denoting the join condition that links the two input relations. | ||
connortsui20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// For example, a join operation could have a condition on `t1.id = t2.id` (an equijoin). | ||
pub condition: Scalar, | ||
} |
This file contains hidden or 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 hidden or 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,9 +1,13 @@ | ||
//! A logical projection. | ||
|
||
/// Logical project operator that specifies output columns. | ||
/// | ||
/// Takes input relation (`Relation`) and defines output columns/expressions | ||
/// (`Scalar`). | ||
#[derive(Clone)] | ||
pub struct Project<Relation, Scalar> { | ||
/// The input relation. | ||
pub child: Relation, | ||
/// TODO(everyone): What exactly is going on here? | ||
pub fields: Vec<Scalar>, | ||
} |
This file contains hidden or 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,9 +1,16 @@ | ||
//! A logical scan. | ||
|
||
/// Logical scan operator that reads from a base table. | ||
/// | ||
/// Reads from table (`String`) and optionally filters rows using a pushdown predicate | ||
/// (`Scalar`). | ||
#[derive(Clone)] | ||
pub struct Scan<Scalar> { | ||
pub table_name: String, // TODO(alexis): Mocked for now. | ||
/// TODO(alexis) Mocked for now. | ||
pub table_name: String, | ||
/// An optional filter expression for predicate pushdown into scan operators. | ||
/// | ||
/// For example, a `Filter(Scan(A), column_a < 42)` can be converted into a predicate pushdown | ||
/// `Scan(A, column < 42)` to prevent having to materialize many tuples. | ||
pub predicate: Option<Scalar>, | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 +1,13 @@ | ||
use std::sync::Arc; | ||
//! TODO(everyone): Figure out what exactly a `ScalarPlan` is (tree? DAG? always materialized?) | ||
|
||
use crate::operator::scalar::ScalarOperator; | ||
use std::sync::Arc; | ||
|
||
/// A representation of a scalar query plan DAG (directed acyclic graph). | ||
#[derive(Clone)] | ||
pub struct ScalarPlan { | ||
/// Represents the current scalar operator that is the root of the current scalar subtree. | ||
/// | ||
/// TODO(connor): Figure out if scalar plans can be a DAG | ||
pub node: Arc<ScalarOperator<ScalarPlan>>, | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.