[ https://issues.apache.org/jira/browse/CALCITE-4155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17173954#comment-17173954 ]
Julian Hyde commented on CALCITE-4155: -------------------------------------- I have started work on a related case that may end up solving this one. See my work in [https://github.com/julianhyde/calcite/tree/4159-simplify]. Note that the way we simplify OR currently is to simplify the first item, then add a predicate that to the list so that when we simplify the second item we know the first item must have been false. My fix builds on that approach, and it uses Guava's RangeSet rather than inventing something similar. I think the ultimate fix to this issue must do both of those things. Predicate-driven simplification is powerful, and we must continue doing it. On a separate note, I have had further thoughts about our use of IN in {{RexCall}}. As you know we have only allowed it for a short time. I think we should replace it with something more powerful: [sargs|https://en.wikipedia.org/wiki/Sargable]. A *sarg* is an ordered set of intervals, represented as a Guava ImmutableRangeSet, such as "[[0‥1), (1‥2], [3‥3], (5‥+∞)]". It can represent an {{IN}}-list of constants, but also ranges. Sarg would be a form of {{RexLiteral}}. If you wrote created a {{RexCall(IN, arg, inList)}} then {{arg}} can be any kind of {{RexNode}} (e.g. RexInputRef) but {{inList}} must be a {{RexLiteral}} containing a sarg. Sargs (and Guava RangeSets) have a powerful and well-defined algebra, so if we invest in sarg support in {{RexSimplify}} and {{RelOptPredicateList}}, that investment will pay dividends. Sargs have support for discrete domains, so they can optimize ">2 AND <4" to "3". I'll start a thread on dev to discuss this. > Simplify IN expression of discrete values > ----------------------------------------- > > Key: CALCITE-4155 > URL: https://issues.apache.org/jira/browse/CALCITE-4155 > Project: Calcite > Issue Type: New Feature > Components: core > Reporter: Liya Fan > Assignee: Liya Fan > Priority: Major > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > For example, given expressions like > {{a in (1, 2, 3, 4, 5)}} > or > {{a = 1 or a = 2 or a = 3 or a = 4 or a = 5}}, > we can simplify it to > {{a >= 1 and a <= 5}} > Such simplification reduces the number of value comparisons from 5 to 2. -- This message was sent by Atlassian Jira (v8.3.4#803005)