-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
10 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
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,38 @@ | ||
use std::collections::HashMap; | ||
|
||
use optd_core::rules::{Rule, RuleMatcher}; | ||
use optd_core::{optimizer::Optimizer, rel_node::RelNode}; | ||
|
||
use crate::plan_nodes::{ConstantType, LogicalEmptyRelation, OptRelNode, OptRelNodeTyp}; | ||
|
||
use super::macros::define_rule; | ||
|
||
define_rule!( | ||
EliminateFilterRule, | ||
apply_eliminate_filter, | ||
(Filter, child, [cond]) | ||
); | ||
|
||
/// Transformations: | ||
/// - Filter node w/ false pred -> EmptyRelation | ||
/// - Filter node w/ true pred -> Eliminate from the tree | ||
fn apply_eliminate_filter( | ||
_optimizer: &impl Optimizer<OptRelNodeTyp>, | ||
EliminateFilterRulePicks { child, cond }: EliminateFilterRulePicks, | ||
) -> Vec<RelNode<OptRelNodeTyp>> { | ||
if let OptRelNodeTyp::Constant(ConstantType::Bool) = cond.typ { | ||
if let Some(data) = cond.data { | ||
if data.as_bool() { | ||
// If the condition is true, eliminate the filter node, as it | ||
// will yield everything from below it. | ||
return vec![child]; | ||
} else { | ||
// If the condition is false, replace this node with the empty relation, | ||
// since it will never yield tuples. | ||
let node = LogicalEmptyRelation::new(false); | ||
return vec![node.into_rel_node().as_ref().clone()]; | ||
} | ||
} | ||
} | ||
vec![] | ||
} |
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,36 @@ | ||
-- (no id or description) | ||
create table t1(t1v1 int, t1v2 int); | ||
create table t2(t2v1 int, t2v3 int); | ||
insert into t1 values (0, 0), (1, 1), (2, 2); | ||
insert into t2 values (0, 200), (1, 201), (2, 202); | ||
|
||
/* | ||
3 | ||
3 | ||
*/ | ||
|
||
-- Test EliminateFilterRule (false filter to empty relation) | ||
select * from t1 where false; | ||
|
||
/* | ||
LogicalProjection { exprs: [ #0, #1 ] } | ||
└── LogicalFilter { cond: false } | ||
└── LogicalScan { table: t1 } | ||
PhysicalProjection { exprs: [ #0, #1 ] } | ||
└── PhysicalEmptyRelation { produce_one_row: false } | ||
*/ | ||
|
||
-- Test EliminateFilterRule (replace true filter with child) | ||
select * from t1 where true; | ||
|
||
/* | ||
LogicalProjection { exprs: [ #0, #1 ] } | ||
└── LogicalFilter { cond: true } | ||
└── LogicalScan { table: t1 } | ||
PhysicalProjection { exprs: [ #0, #1 ] } | ||
└── PhysicalScan { table: t1 } | ||
0 0 | ||
1 1 | ||
2 2 | ||
*/ | ||
|
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,19 @@ | ||
- sql: | | ||
create table t1(t1v1 int, t1v2 int); | ||
create table t2(t2v1 int, t2v3 int); | ||
insert into t1 values (0, 0), (1, 1), (2, 2); | ||
insert into t2 values (0, 200), (1, 201), (2, 202); | ||
tasks: | ||
- execute | ||
- sql: | | ||
select * from t1 where false; | ||
desc: Test EliminateFilterRule (false filter to empty relation) | ||
tasks: | ||
- explain:logical_optd,physical_optd | ||
- execute | ||
- sql: | | ||
select * from t1 where true; | ||
desc: Test EliminateFilterRule (replace true filter with child) | ||
tasks: | ||
- explain:logical_optd,physical_optd | ||
- execute |
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