Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
the query must have the following features:
- not all columns are selected
- to enable RelFieldTrimmer to start a cycle
- two equivalent eq filters
- one in IN form (ename in ( 'Sebastian' ))
- a regular = (ename = 'Sebastian')
- an unrelated filter like deptno < 100
the optimizer should more-or-less start with the `RelFieldTrimmer`
the issue happens like:
- at parse time both literals are parsed as CHAR( n )
- the number of values in the `IN` is below `inSubqueryThreshold` - so it gets converted to a set of `=` filters
- expression is converted to OR form
- during conversion SqlToRelConverter#ensureSqlType is called
- which skips the conversion for CHAR / VARCHAR
- the = filter goes thru the "regular" rex conversion - which involves calling rexBuilder#ensureType
- the filter condition contains ename = 'Sebastian' twice; however the types differ
- RelFieldTrimmer starts a change cycle ; which induces the simplification of the filter condition
- RexSimplify is executed with predicate elimination disabled (this will be important)
- simplification compares the two literals with equals and returns `false`
workarounds:
- disable the conversion by setting inSubqueryThreshold=1
- run a rule which executes `RexSimplify` with predicate elimination enabled earlier than the trimmer (ex: ReduceExpressionsRule)
- I think this bug remained hidden because this might happen easily
testcase for `RelOptRulesTest`
@Test void testIncorrectInType() { final String sql = "select ename from emp " + " where ename in ( 'Sebastian' ) and ename = 'Sebastian' and deptno < 100"; sql(sql) .withTrim(true) .withRule() .checkUnchanged(); }
results in plan
LogicalProject(ENAME=[$0]) LogicalValues(tuples=[[]])
Attachments
Issue Links
- is caused by
-
CALCITE-1343 Broken Druid query
- Closed
- is related to
-
CALCITE-5156 Support implicit integer type cast for IN Sub-query
- Resolved
- links to