Source:
protected PlanNodeStatsEstimate visitInPredicate(InPredicate node, Void context) { if (!(node.getValueList() instanceof InListExpression)) { return PlanNodeStatsEstimate.unknown(); } InListExpression inList = (InListExpression) node.getValueList(); ImmutableList<PlanNodeStatsEstimate> equalityEstimates = inList.getValues().stream() .map(inValue -> process(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, node.getValue(), inValue))) .collect(toImmutableList()); if (equalityEstimates.stream().anyMatch(PlanNodeStatsEstimate::isOutputRowCountUnknown)) { return PlanNodeStatsEstimate.unknown(); } PlanNodeStatsEstimate inEstimate = equalityEstimates.stream() .reduce(PlanNodeStatsEstimateMath::addStatsAndSumDistinctValues) .orElse(PlanNodeStatsEstimate.unknown()); if (inEstimate.isOutputRowCountUnknown()) { return PlanNodeStatsEstimate.unknown(); } SymbolStatsEstimate valueStats = getExpressionStats(node.getValue()); if (valueStats.isUnknown()) { return PlanNodeStatsEstimate.unknown(); } double notNullValuesBeforeIn = input.getOutputRowCount() * (1 - valueStats.getNullsFraction()); PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.buildFrom(input); result.setOutputRowCount(min(inEstimate.getOutputRowCount(), notNullValuesBeforeIn)); if (node.getValue() instanceof SymbolReference) { Symbol valueSymbol = Symbol.from(node.getValue()); SymbolStatsEstimate newSymbolStats = inEstimate.getSymbolStatistics(valueSymbol) .mapDistinctValuesCount(newDistinctValuesCount -> min(newDistinctValuesCount, valueStats.getDistinctValuesCount())); result.addSymbolStatistics(valueSymbol, newSymbolStats); } return result.build(); }

Target:
protected PlanNodeStatsEstimate visitInPredicate(InPredicate node, Void context) { if (!(node.getValueList() instanceof InListExpression)) { return PlanNodeStatsEstimate.unknown(); } InListExpression inList = (InListExpression) node.getValueList(); ImmutableList<PlanNodeStatsEstimate> equalityEstimates = inList.getValues().stream() .map(inValue -> process(new ComparisonExpression(EQUAL, node.getValue(), inValue))) .collect(toImmutableList()); if (equalityEstimates.stream().anyMatch(PlanNodeStatsEstimate::isOutputRowCountUnknown)) { return PlanNodeStatsEstimate.unknown(); } PlanNodeStatsEstimate inEstimate = equalityEstimates.stream() .reduce(PlanNodeStatsEstimateMath::addStatsAndSumDistinctValues) .orElse(PlanNodeStatsEstimate.unknown()); if (inEstimate.isOutputRowCountUnknown()) { return PlanNodeStatsEstimate.unknown(); } SymbolStatsEstimate valueStats = getExpressionStats(node.getValue()); if (valueStats.isUnknown()) { return PlanNodeStatsEstimate.unknown(); } double notNullValuesBeforeIn = input.getOutputRowCount() * (1 - valueStats.getNullsFraction()); PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.buildFrom(input); result.setOutputRowCount(min(inEstimate.getOutputRowCount(), notNullValuesBeforeIn)); if (node.getValue() instanceof SymbolReference) { Symbol valueSymbol = Symbol.from(node.getValue()); SymbolStatsEstimate newSymbolStats = inEstimate.getSymbolStatistics(valueSymbol) .mapDistinctValuesCount(newDistinctValuesCount -> min(newDistinctValuesCount, valueStats.getDistinctValuesCount())); result.addSymbolStatistics(valueSymbol, newSymbolStats); } return result.build(); }