feat(predicate): optimize IN and NOT IN evaluation with a literal lookup set - #261
Open
lucasfang wants to merge 1 commit into
Open
feat(predicate): optimize IN and NOT IN evaluation with a literal lookup set#261lucasfang wants to merge 1 commit into
lucasfang wants to merge 1 commit into
Conversation
lxy-9602
marked this pull request as draft
August 31, 2026 01:48
lucasfang
marked this pull request as ready for review
August 31, 2026 06:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Linked issue: close #262
Evaluating
IN/NOT INpredicates currently goes throughMultiLiteralsLeafFunction, which materializes the whole column intoLiteralobjects (one heap allocation per row) and linearly scans all literals for every row, i.e.O(rows × literals)per batch. This PR introducesLiteralSet, an immutable, type-specialized lookup structure built once when the predicate is constructed, so arrow arrays are probed inO(rows)with no per-row allocation:string_views backed by owned storage, filtered by length range and a first-byte bitmap before hashing. Dictionary-encoded arrays are probed once per dictionary and then only follow indices, with null dictionary entries probed as empty strings to keep exact parity with the fallback converter.In/NotInexactly: null literals are ignored byIN, a null literal makesNOT INfalse for every row, and null column values never match.Unsupported types (FLOAT/DOUBLE, TIMESTAMP, DECIMAL), heterogeneous literal types, and mismatched arrow array types all fall back to the existing
LeafFunctionimplementation, so observable behavior including error reporting stays unchanged. The structure is immutable after construction and shared viastd::shared_ptr<const LiteralSet>onNewLeafPredicaterebinds, keeping concurrent evaluation lock-free and avoiding rebuilds per reader.Tests
New unit tests in
src/paimon/common/predicate/literal_set_test.cpp:TestDenseIntegers,TestSparseIntegers,TestInt64FullSpan(regression for the full int64 range that used to crash when building the dense bitmap),TestTinyIntAndSmallInt,TestDateTestBoolean,TestString,TestStringWithoutEmptyLiteral,TestBinaryTestDictionaryString,TestDictionaryWithNullValue(regression for null dictionary entries matching empty-string semantics of the fallback path)TestNullLiteralIgnoredForIn,TestOnlyNullLiterals,TestCreateOrNullUnsupported,TestMatchesArrowTypeMismatch,TestValueNull,TestSlicedArray,TestOutputBufferValidationNew end-to-end tests in
src/paimon/common/predicate/predicate_test.cpp:TestLargeStringIn: 1000-literal STRINGIN/NOT INover a plain array including empty string and nullTestInAfterRebind: verifies rebinding by field name/index shares the prebuilt lookup and keeps results identicalTestInt64BoundaryIn:IN/NOT INwithINT64_MINandINT64_MAXliterals throughPredicateBuilder, guarding the construction-time crash pathVerified with the full
paimon-common-testsuite (1515 tests, all passed).API and Format
No. All changes are internal to
src/paimon/common/predicate/; no public header underinclude/, storage format, or protocol is touched.Documentation
No. This is a performance optimization with no user-visible behavior change.
Generative AI tooling
Generated-by: Qoder