Improve performance of multi-stage queries with large IN clauses #14615
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CoreRules.FILTER_REDUCE_EXPRESSIONSfrom huge number of filter predicates created byPinotFilterExpandSearchRule(IN->OR, see Multi-stage: Perf issue when IN expression has a lot of entries #13617).SqlToRelConverterwhere we're convertingINtoORno matter the size of theINlist (see discussion in https://issues.apache.org/jira/browse/CALCITE-6467). The default Calcite threshold is 20 beyond which theINis converted to a join with a static table; however, this causes query execution overhead for us since we aren't currently optimizing such joins and might need to pay unnecessary data shuffling cost.SqlToRelConverterpart of the inefficiency will be fixed by upgrading Calcite to 1.39.0 which is due to be released soon.PinotFilterExpandSearchRulebecause we already have logic in theRelNode->PlanNodeconversion phase that safely converts theSEARCHoperators without the risk of incurring optimization overhead from other rules due to the conversion to a bunch of OR'd = expressions (we convert directly toIN/NOT INinstead). The logic has been updated to also be able to handle literal onlySEARCHexpressions that can be generated by Calcite'sFILTER_REDUCE_EXPRESSIONSrule.