Skip to content

Commit

Permalink
[opt](nereids) opt range inference for or expression when out of order (
Browse files Browse the repository at this point in the history
apache#46303)

### What problem does this PR solve?

Problem Summary:

For range inference, it will merge multiple value desc whose reference
are the same. It will merge two value desc step by step. Diff merge
order may get diff result.

For range Inference: `x1 op x2 op x3 op x4`

If op is `AND`, then the merge order doesn't matter. It will always get
the same result.

But if op is `OR`, then the merge order does matter. For example: `(a <
10) or ( a > 30) or (a >= 15 and a <= 35)`. When merge the first OP, it
will get an UnknownValue: and its source is: `[ (-00, 10), (30, +00) ]`,
latter will merge this UnknowValue with RangeValue `[15, 35]`. Since
UnknowValue union another value desc will get a new UnknownValue, then
then final result is UknownValue(UnknowValue(RangeValue(`a<10`) or
RangeValue(`a>30`)) or RangeValue(`a>=15 and a <= 35`)). This is bad. It
should merge the 1st and 3rd value desc firstly, latter merge the 2nd
value desc, Then finally the merge result is 'TRUE'.

In order to achieve this, use a RangeSet to record all the ranges, then
RangeSet will auto merge the results.

What's more, this pr also:
1.  opt  'a > 20 or a = 20'  to  'a >= 20';
2. for the discrete value's options, if an option is in one range, then
the option will eliminate. for example: `a <= 10 or a in [1, 2, 3, 11,
12, 13]` will opt to `a <= 10 or a in [11, 12, 13]`;
3. delete toExpr in RangeInference;
  • Loading branch information
yujun777 authored Jan 9, 2025
1 parent 322de2b commit bbf8a81
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 116 deletions.
Loading

0 comments on commit bbf8a81

Please sign in to comment.