deniskuzZ commented on code in PR #6082: URL: https://github.com/apache/hive/pull/6082#discussion_r2360368006
########## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java: ########## @@ -734,26 +736,30 @@ private static boolean shareSameType( private static RexNode handleOR(RexBuilder rexBuilder, RexCall call) { // IN clauses need to be combined by keeping all elements final List<RexNode> operands = new ArrayList<>(RexUtil.flattenOr(call.getOperands())); + final List<RexNode> newOperands = new ArrayList<>(operands.size()); final Multimap<RexNode,SimilarRexNodeElement> inLHSExprToRHSExprs = LinkedHashMultimap.create(); - for (int i = 0; i < operands.size(); i++) { - RexNode operand = operands.get(i); - if (operand instanceof RexCall && HiveIn.INSTANCE.equals(((RexCall) operand).op)) { - RexCall inCall = (RexCall) operand; - if (!HiveCalciteUtil.isDeterministic(inCall.getOperands().get(0))) { + int inExpressionCount = 0; + for (RexNode operand : operands) { + if (operand instanceof RexCall inCall && HiveIn.INSTANCE.equals(inCall.op)) { + if (!HiveCalciteUtil.isDeterministic(inCall.getOperands().getFirst())) { continue; } - RexNode ref = inCall.getOperands().get(0); + RexNode ref = inCall.getOperands().getFirst(); for (int j = 1; j < inCall.getOperands().size(); j++) { inLHSExprToRHSExprs.put(ref, new SimilarRexNodeElement(inCall.getOperands().get(j))); } - operands.remove(i); - --i; + ++inExpressionCount; + } else { + newOperands.add(operand); } } + if (inExpressionCount == inLHSExprToRHSExprs.keySet().size()) { + // No IN expressions can be merged, bail out + return call; + } // Create IN clauses (fourth parameter is not needed since no expressions were removed) - final List<RexNode> newOperands = createInClauses(rexBuilder, - inLHSExprToRHSExprs.keySet(), inLHSExprToRHSExprs, null); - newOperands.addAll(operands); + newOperands.addAll(createInClauses(rexBuilder, Review Comment: same https://github.com/apache/hive/pull/6082/files#r2360354039 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org