Skip to content

Support simplification that requires multiple applications of constant folding / simplification #1160

@alamb

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
The constant folding and constant evaluation in constant_folding.rs(and added to in #1153) can not fold certain types of expressions where it takes

For example there is an expression like this in #1153

now() < cast(to_timestamp(...) as int) + 5000000000

It is entirely evaluateable at query time, however, as formulated in #1153 it will not be folded because it requires the constant evaluator to run after the simplifier (because the simplifier can fill in now()` and then the evaluator will fill in the rest).

However, there are other types of exprs such as (true or false) != col which need to have the constant evaluator run before the simplifier to be fully simplified.

It is a more general problem where running either the Simplifier or ConstEvaluator could allow a second pass of the other to proceed

Describe the solution you'd like
In general this is typically handled with some sort of 'fixed point' algorithm where there is a loop that runs the two passes until the Expr is not changed. It may also be possible to combine the Simplifier pass with the constant rewriter.

Describe alternatives you've considered
I think there are two possible approaches I can think if:

  1. applying constant eval / simplifier in a loop until no changes are detected
  2. Combining the ConstantEval and Simplify steps into a single pass

Additional context
#1153

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions