Class PushDownFilterAndLimitIntoUnionAll

java.lang.Object
org.elasticsearch.xpack.esql.rule.Rule<LogicalPlan,LogicalPlan>
org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownFilterAndLimitIntoUnionAll

public final class PushDownFilterAndLimitIntoUnionAll extends Rule<LogicalPlan,LogicalPlan>
Push down filters that can be evaluated by the UnionAll branch to each branch, below the added Limit and Subquery, so that the filters can be pushed down further to the data source when possible. Filters that cannot be pushed down remain above the UnionAll. Also push down the Limit added by AddImplicitForkLimit below the Subquery, so that the other rules related to Limit optimization can be applied. This rule applies for certain patterns of UnionAll branches. The branches of a UnionAll/Fork plan has a similar pattern, as Fork adds EsqlProject, an optional Eval and Limit on top of its actual children. In case there is mismatched data types on the same field across different UnionAll branches, a ConvertFunction could also be added in the optional Eval. If the patterns of the UnionAll branches do not match the following expected patterns, the rule is not applied. EsqlProject Eval (optional) - added when the output of each UnionAll branch are not exactly the same Limit EsRelation or EsqlProject Eval (optional) Limit Subquery or Limit - CombineProjections may remove the EsqlProject on top of the limit Subquery