Commit 720456c
[CALCITE-7747] RexSimplify.simplifySearch does not simplify SEARCH(literal, Sarg) when pointCount >= 2
RexSimplify.simplifySearch only evaluated a SEARCH(subject, Sarg) call
against its Sarg when sarg.isPoints() && sarg.pointCount <= 1, with no
check for whether the subject itself is a constant. A single-point
Sarg with any subject folded correctly, and a multi-point Sarg with a
column-reference subject simplified correctly elsewhere, but a literal
subject compared against a multi-point Sarg (for example,
SEARCH(5, Sarg[1, 2])) fell through every branch unevaluated instead
of folding to a boolean constant.
This can occur whenever a rule substitutes a literal for a column
reference in a SEARCH condition, such as when
FilterSetOpTransposeRule pushes a filter through a branch of a Union
that projects a constant.
Fix simplifySearch so that when the search subject is itself a
RexLiteral, the call is expanded via the existing RexUtil.expandSearch
and the result is simplified recursively, regardless of point count.
This matches the treatment already given to a single-point Sarg, but
adds the recursive simplify() call needed to fold the expanded
comparison tree down to a constant.1 parent 1a0b436 commit 720456c
2 files changed
Lines changed: 27 additions & 2 deletions
File tree
- core/src
- main/java/org/apache/calcite/rex
- test/java/org/apache/calcite/rex
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2608 | 2608 | | |
2609 | 2609 | | |
2610 | 2610 | | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
2611 | 2615 | | |
2612 | | - | |
2613 | | - | |
| 2616 | + | |
| 2617 | + | |
2614 | 2618 | | |
2615 | 2619 | | |
2616 | 2620 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2262 | 2262 | | |
2263 | 2263 | | |
2264 | 2264 | | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
2265 | 2286 | | |
2266 | 2287 | | |
2267 | 2288 | | |
| |||
0 commit comments