-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unnesting arbitrary subqueries (likely broken) (#180)
Somewhere between a proof of concept and a draft—work still heavily in progress. Will already successfully parse and fully unnest a subset of correlated and uncorrelated subqueries (although I am uncertain about correctness). **TODO**: - [ ] Formal testing - [ ] EXISTS clauses - [ ] IN clauses - [ ] ANY/ALL clauses - [ ] Correctness issue with COUNT(*) (requires adding left outer join to plan) - [x] Move some/all of this to rewriting stage to support multiple subqueries/ordering operations - [x] “Sideways information passing” (subplans are duplicated now instead of making a DAG) - It seems that a DAG representation is only supported by looking for groups that appear the same. It looks to me that the cloned branches generated by this PR are indeed marked with the same group ID. I marked this bullet point as completed with this in mind. - [ ] Support more pushdowns (e.g. limit, joins) - [ ] Optimizations from the paper are all missing (Out of scope?) --------- Signed-off-by: Alex Chi <[email protected]> Co-authored-by: Alex Chi <[email protected]>
- Loading branch information
Showing
14 changed files
with
898 additions
and
72 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use optd_core::rel_node::{RelNode, RelNodeMetaMap, Value}; | ||
use pretty_xmlish::Pretty; | ||
|
||
use super::macros::define_plan_node; | ||
use super::{Expr, ExprList, JoinType, OptRelNode, OptRelNodeRef, OptRelNodeTyp, PlanNode}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct RawDependentJoin(pub PlanNode); | ||
|
||
define_plan_node!( | ||
RawDependentJoin : PlanNode, | ||
RawDepJoin, [ | ||
{ 0, left: PlanNode }, | ||
{ 1, right: PlanNode } | ||
], [ | ||
{ 2, cond: Expr }, | ||
{ 3, extern_cols: ExprList } | ||
], { join_type: JoinType } | ||
); | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct DependentJoin(pub PlanNode); | ||
|
||
define_plan_node!( | ||
DependentJoin : PlanNode, | ||
DepJoin, [ | ||
{ 0, left: PlanNode }, | ||
{ 1, right: PlanNode } | ||
], [ | ||
{ 2, cond: Expr }, | ||
{ 3, extern_cols: ExprList } | ||
], { join_type: JoinType } | ||
); | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ExternColumnRefExpr(pub Expr); | ||
|
||
impl ExternColumnRefExpr { | ||
/// Creates a new `DepExternColumnRef` expression. | ||
pub fn new(column_idx: usize) -> ExternColumnRefExpr { | ||
// this conversion is always safe since usize is at most u64 | ||
let u64_column_idx = column_idx as u64; | ||
ExternColumnRefExpr(Expr( | ||
RelNode { | ||
typ: OptRelNodeTyp::ExternColumnRef, | ||
children: vec![], | ||
data: Some(Value::UInt64(u64_column_idx)), | ||
} | ||
.into(), | ||
)) | ||
} | ||
|
||
fn get_data_usize(&self) -> usize { | ||
self.0 .0.data.as_ref().unwrap().as_u64() as usize | ||
} | ||
|
||
/// Gets the column index. | ||
pub fn index(&self) -> usize { | ||
self.get_data_usize() | ||
} | ||
} | ||
|
||
impl OptRelNode for ExternColumnRefExpr { | ||
fn into_rel_node(self) -> OptRelNodeRef { | ||
self.0.into_rel_node() | ||
} | ||
|
||
fn from_rel_node(rel_node: OptRelNodeRef) -> Option<Self> { | ||
if rel_node.typ != OptRelNodeTyp::ExternColumnRef { | ||
return None; | ||
} | ||
Expr::from_rel_node(rel_node).map(Self) | ||
} | ||
|
||
fn dispatch_explain(&self, _meta_map: Option<&RelNodeMetaMap>) -> Pretty<'static> { | ||
Pretty::display(&format!("Extern(#{})", self.index())) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod depjoin_pushdown; | ||
|
||
pub use depjoin_pushdown::{ | ||
DepInitialDistinct, DepJoinEliminateAtScan, DepJoinPastAgg, DepJoinPastFilter, DepJoinPastProj, | ||
}; |
Oops, something went wrong.