@@ -46,13 +46,13 @@ object DefaultOptimizer extends Optimizer {
4646 CombineLimits ) ::
4747 Batch (" ConstantFolding" , FixedPoint (100 ),
4848 NullPropagation ,
49+ OptimizeIn ,
4950 ConstantFolding ,
5051 LikeSimplification ,
5152 BooleanSimplification ,
5253 SimplifyFilters ,
5354 SimplifyCasts ,
54- SimplifyCaseConversionExpressions ,
55- OptimizeIn ) ::
55+ SimplifyCaseConversionExpressions ) ::
5656 Batch (" Decimal Optimizations" , FixedPoint (100 ),
5757 DecimalAggregates ) ::
5858 Batch (" LocalRelation" , FixedPoint (100 ),
@@ -293,11 +293,19 @@ object ConstantFolding extends Rule[LogicalPlan] {
293293 // Fold expressions that are foldable.
294294 case e if e.foldable => Literal .create(e.eval(null ), e.dataType)
295295
296- // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly.
296+ // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly when all
297+ // elements is literal.
297298 case InSet (Literal (v, _), hSet) => {
298299 val isExists = hSet.contains(v)
299300 if (isExists) Literal .create(true , BooleanType ) else Literal .create(false , BooleanType )
300301 }
302+
303+ // Fold "literal in (item1, item2, ..., literal, ...)" into true directly when
304+ // not all elements is literal.
305+ case In (Literal (v, _), list) if list.exists {
306+ case Literal (candidate, _) if candidate == v => true
307+ case _ => false
308+ } => Literal .create(true , BooleanType )
301309 }
302310 }
303311}
0 commit comments