Skip to content

EPIC: use cp_solver framework to develop a more sophisticated predicate simplification #16511

Open

Description

@xudong963

Is your feature request related to a problem or challenge?

The predicates in filter can be variable, it's possible to use the cp_solver to simplify the predicates in filter, then reduce the computing cost for filter.

Describe the solution you'd like

We've done some basic simplification in #16362, we can make it a start to develop a more sophisticated rule to cover more cases

Describe alternatives you've considered

No response

Additional context

What I want to discuss:

  1. Make it a new physical optimizer rule? Or add them to the current physical filter push down
  2. Some filters, such as partition columns related predicates, will be fully pushed down scan, that is, we don't have such predicates in some FilterExec. How to capture this?
  3. TBD (You may have other thoughts!)

Activity

  1. adriangb commented on Jun 24, 2025

    @adriangb
    Contributor

    Make it a new physical optimizer rule? Or add them to the current physical filter push down

    Do we need a phyiscal optimizer rule? My thought is that these optimizations can happen at the logical layer. At the phyiscal layer we do need some expression optimization, but primarily to deal with type casting to match the file schema, etc (i.e. #16530), expressions at this point should be already simplified from the logical layer and that doesn't really change except maybe in some edge cases which I'm not sure are worth dealing with.

    Some filters, such as partition columns related predicates, will be fully pushed down scan, that is, we don't have such predicates in some FilterExec. How to capture this?

    Not sure I understood this part

  2. xudong963 commented on Jun 26, 2025

    @xudong963
    MemberAuthor

    My thought is that these optimizations can happen at the logical layer

    Yes, almost all DBs do the optimization in logical layer, but as @alamb said, we want to use the cp solver framework to make it general(cp solver is in the physical layer).

    Not sure I understood this part

    In logical filter pushdown, the partition-related filters will be fully pushed down to scan(they are Exact), see code here:
    https://github.com/apache/datafusion/blob/main/datafusion/optimizer/src/push_down_filter.rs#L1128-L1153

  3. alamb commented on Jun 26, 2025

    @alamb
    Contributor

    Even though the cp_solver is done at the physical layer, I think the overall simplification can still be done in an Optimizer that targets LogicalPlans -- much like the expression simplifier works, we would convert to a physical expr during planning:

    let phys_expr =
    match create_physical_expr(&expr, &self.input_schema, self.execution_props) {
    Ok(e) => e,
    Err(err) => return ConstSimplifyResult::SimplifyRuntimeError(err, expr),
    };

  4. added
    EPICA larger project, actively underway, with sub tasks
    PROPOSAL EPICA proposal being discussed that is not yet fully underway
    and removed
    EPICA larger project, actively underway, with sub tasks
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PROPOSAL EPICA proposal being discussed that is not yet fully underwayenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions