Source:
<code>private void makeResultBudget(int numRows) { int bytesSoFar = 0; double selectivity = 1; <START> int totalAsk = 0; <END> if (targetResultBytes == OrcRecordReader.UNLIMITED_BUDGET || (ariaFlags & AriaFlags.noReaderBudget) != 0) { for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; if (reader.getChannel() != -1) { reader.setResultSizeBudget(OrcRecordReader.UNLIMITED_BUDGET); } } return; } for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; bytesSoFar += reader.getResultSizeInBytes(); Filter filter = reader.getFilter(); int channel = reader.getChannel(); if (filter != null) { selectivity *= filter.getSelectivity(); } if (channel != -1) { int avgSize = reader.getAverageResultSize(); readerBudget[i] = Math.max(8000, (int) (numRows * selectivity * avgSize)); totalAsk += readerBudget[i]; if (i < filterFunctionOrder.length && filterFunctionOrder[i] != null) { for (FilterFunction function : filterFunctionOrder[i]) { selectivity *= function.getSelectivity(); } } } else { readerBudget[i] = 0; } } if (totalAsk == 0) { return; } long available = targetResultBytes - bytesSoFar; if (available < 10000) { available = 10000; } double grantedFraction = (double) available / totalAsk; for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; if (reader.getChannel() != -1) { long budget = (int) (readerBudget[i] * grantedFraction); reader.setResultSizeBudget(budget * BUDGET_HARD_LIMIT_MULTIPLIER); } } }</code><technical_language>of variables is in case of unlimited budget. Move unlimited budget case is processed</technical_language>

Target:
private void makeResultBudget(int numRows) { if (targetResultBytes == UNLIMITED_BUDGET || (ariaFlags & AriaFlags.noReaderBudget) != 0) { for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; if (reader.getChannel() != -1) { reader.setResultSizeBudget(UNLIMITED_BUDGET); } } return; } long bytesSoFar = 0; double selectivity = 1; long totalAsk = 0; for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; bytesSoFar += reader.getResultSizeInBytes(); Filter filter = reader.getFilter(); if (filter != null) { selectivity *= filter.getSelectivity(); } if (reader.getChannel() != -1) { readerBudget[i] = Math.max(MIN_READER_BUDGET, (long) (numRows * selectivity * reader.getAverageResultSize())); totalAsk += readerBudget[i]; if (i < filterFunctionOrder.length && filterFunctionOrder[i] != null) { for (FilterFunction function : filterFunctionOrder[i]) { selectivity *= function.getSelectivity(); } } } else { readerBudget[i] = 0; } } if (totalAsk == 0) { return; } long available = targetResultBytes - bytesSoFar; if (available < MIN_READER_BUDGET) { available = MIN_READER_BUDGET * sortedStreamReaders.length; } double grantedFraction = available < totalAsk ? (double) available / totalAsk : 1.0; for (int i = 0; i < sortedStreamReaders.length; i++) { StreamReader reader = sortedStreamReaders[i]; if (reader.getChannel() != -1) { reader.setResultSizeBudget((long) (readerBudget[i] * grantedFraction) * BUDGET_HARD_LIMIT_MULTIPLIER); } } }