Repository navigation
perf(expression): Support split and parallel scans - Part-3.5: compile Evaluator expressions and compare raw values - #1166
Open
kamcheungting-db wants to merge 3 commits into
Conversation
Evaluator::Evaluate() visited the bound expression for every row, copying shared_ptrs while dispatching on each predicate, and built a Literal for every compared value. Building a Literal copies the type's shared_ptr singleton and, for strings and bytes, the value itself. With several threads evaluating residual filters, the atomic reference count of the shared type object became the bottleneck: a parallel scan with a per-row residual ran slower than a serial one. Evaluator::Make() now compiles the bound expression once into evaluation nodes. Literal and unary predicates on a field reference of a primitive type read the field's raw scalar and compare it with the bound literal, matching Literal ordering: null and out-of-range literals are unordered, floating-point values use the total order, decimals compare across scales, and strings and bytes compare as unsigned bytes. Set predicates, transforms, and any value without a raw representation still go through the literal-based visitor, so results and errors are unchanged. And/Or still evaluate both sides, so a failing row still reports its error. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
… test Use std::array instead of C-style arrays and designated initializers for ColumnCase. Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
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.
What this PR does
Makes
Evaluator(used for residual filters byFileScanTaskReader) evaluate rows without building aLiteralper value, and without visiting the expression tree per row.Evaluator::Make()now compiles the bound expression once into a small tree of evaluation nodes.Evaluate()runs those nodes.Why
Per row, the old path:
dynamic_pointer_cast(ashared_ptrcopy) for each predicate, andLiteralfor every compared value, which copies the type'sshared_ptrsingleton (for exampleint64()) and, for strings and bytes, the value itself.With several threads evaluating residuals, every thread updates the same atomic reference count of the shared type object, so the cache line bounces between cores. In the Part-5 parallel scan benchmark (#1168) a per-row residual made 8 workers slower than one thread. A
perfprofile put about two-thirds of the samples on thelock inc/lock xaddinLiteral::LongandEvalVisitor::GtEq, and on the virtual call through the shared type object inLiteral::operator<=>.How it works
The node tree is immutable after
Make(), so oneEvaluatorcan still be used from several threads.Node mapping
true/falsenot,and,orand/orstill evaluate both sides, left first, so a failing row still reports its errorScalarand compares it with the bound literalThe raw comparison matches
Literalordering: null and out-of-range literals are unordered,float/doubleuse the total order (std::strong_order), decimals compare across scales, and strings, binary, fixed, and UUIDs compare as unsigned bytes. When a raw value does not have the field type's representation, the node falls back to the visitor for that row, so results and errors stay the same.Tests
eval_expr_test(evaluator_test.cc):MatchesLiteralSemantics: more than 1,000 checks comparing the evaluator withBoundPredicate::Test()on the literal-based value, across boolean, int, date, long, time, timestamp, timestamptz, float, double, decimal, string, binary, fixed, and UUID; all literal and unary operations; and nulls, NaNs, signed zeros, infinities, prefixes, and high bytes. Changing one comparison operator in the new code makes it fail.INand transform predicates still evaluate correctly.The existing
expression_testandeval_expr_testsuites pass, and the fullctestsuite passes.pre-commitis clean.Performance
In the Part-5 benchmark, 8 workers versus a serial scan with an all-pass residual on 4 large Parquet files went from 0.80x to 6.72x, and the serial scan itself got about 1.9x faster (0.834s to 0.432s). Details are in the Part-5 PR.
Related
Part 3.5 of the split and parallel scans series: Part 1 #976 · Part 2a #1002 · Part 2b #1062 · Part 2c #1065 · Part 3 #1113 · Part 4 #1167 · Part 5 #1168.
This pull request and its description were written by Isaac.