pub struct PullUpCorrelatedExpr {
pub join_filters: Vec<Expr>,
pub correlated_subquery_cols_map: HashMap<LogicalPlan, BTreeSet<Column>>,
pub in_predicate_opt: Option<Expr>,
pub exists_sub_query: bool,
pub can_pull_up: bool,
pub need_handle_count_bug: bool,
pub collected_count_expr_map: HashMap<LogicalPlan, ExprResultMap>,
pub pull_up_having_expr: Option<Expr>,
pub pulled_up_scalar_agg: bool,
pub correlated_filters: Vec<Expr>,
/* private fields */
}Expand description
This struct rewrite the sub query plan by pull up the correlated expressions(contains outer reference columns) from the inner subquery’s ‘Filter’. It adds the inner reference columns to the ‘Projection’ or ‘Aggregate’ of the subquery if they are missing, so that they can be evaluated by the parent operator as the join condition.
Fields§
§join_filters: Vec<Expr>mapping from the plan to its holding correlated columns
in_predicate_opt: Option<Expr>§exists_sub_query: boolIs this an Exists(Not Exists) SubQuery. Defaults to FALSE
can_pull_up: boolCan the correlated expressions be pulled up. Defaults to TRUE
need_handle_count_bug: boolDo we need to handle the count bug during the pull up process.
The “count bug” was described in Optimization of Nested SQL Queries Revisited. This bug is not specific to the COUNT function, and it can occur with any aggregate function, such as SUM, AVG, etc. The anomaly arises because aggregates fail to distinguish between an empty set and null values when optimizing a correlated query as a join. Here, we use “the count bug” to refer to all such cases.
collected_count_expr_map: HashMap<LogicalPlan, ExprResultMap>mapping from the plan to its expressions’ evaluation result on empty batch
pull_up_having_expr: Option<Expr>pull up having expr, which must be evaluated after the Join
pulled_up_scalar_agg: boolwhether we have converted a scalar aggregation into a group aggregation. When unnesting lateral joins, we need to produce a left outer join in such cases.
An Aggregate above stops the pull up when this is set. f_up visits
the aggregate that sets it before any node above.
Every correlated conjunct that a Filter of the subquery applies,
before remove_duplicated_filter drops the ones that the IN
predicate already covers. The outer references are kept, so that a
subquery column and an outer column with the same qualified name stay
apart.
join_filters holds only the conjuncts that the join still needs.
This list is what the subquery enforces on its own rows. The caller
uses it to tell if a join key can be NULL inside the scope of an outer
row: x IN (SELECT y FROM .. WHERE y = x) keeps every NULL y out of
its result, although join_filters no longer says so.
The list is cleared when the pull up passes a node that can put a NULL back into such a column: an outer join, a union or a grouping set.
Implementations§
pub fn new() -> Self
Sourcepub fn with_need_handle_count_bug(self, need_handle_count_bug: bool) -> Self
pub fn with_need_handle_count_bug(self, need_handle_count_bug: bool) -> Self
Set if we need to handle the count bug during the pull up process
Sourcepub fn with_in_predicate_opt(self, in_predicate_opt: Option<Expr>) -> Self
pub fn with_in_predicate_opt(self, in_predicate_opt: Option<Expr>) -> Self
Set the in_predicate_opt
Sourcepub fn with_exists_sub_query(self, exists_sub_query: bool) -> Self
pub fn with_exists_sub_query(self, exists_sub_query: bool) -> Self
Set if this is an Exists(Not Exists) SubQuery
Trait Implementations§
Source§type Node = LogicalPlan
type Node = LogicalPlan
Source§fn f_down(&mut self, plan: LogicalPlan) -> Result<Transformed<LogicalPlan>>
fn f_down(&mut self, plan: LogicalPlan) -> Result<Transformed<LogicalPlan>>
Source§fn f_up(&mut self, plan: LogicalPlan) -> Result<Transformed<LogicalPlan>>
fn f_up(&mut self, plan: LogicalPlan) -> Result<Transformed<LogicalPlan>>
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more