Repository navigation
[SPARK-2531 & SPARK-2436] [SQL] Optimize the BuildSide when planning BroadcastNestedLoopJoin. - #1448
concretevitamin wants to merge 4 commits into
Conversation
|
Jenkins, this is okay to test. |
|
Jenkins, test this please... |
|
QA tests have started for PR 1448. This patch merges cleanly. |
|
QA results for PR 1448: |
There was a problem hiding this comment.
Move Vector.fill(left.output.size)(null) out of map action, avoid the object creation in every iteration, the same with Vector.fill(right.output.size)(null)
There was a problem hiding this comment.
Actually I think a lot of this is fixed in the codegen PR (i.e. we use projection instead of creating new arrays everytime). Perhaps we should revisit this PR after that has been merged.
There was a problem hiding this comment.
Hey @marmbrus -- now that codegen is in (congrats!), can you point to the places that I should look at?
There was a problem hiding this comment.
Just look at this code in master. I already rewrote it to use JoinedRow instead of copying.
|
Generally the code looks good to me, except some of the potential performance issues. And this actually supports all of the |
|
Thanks for the comments @chenghao-intel and @marmbrus. As Michael said I'll revisit this after the codegen PR. |
|
QA tests have started for PR 1448. This patch merges cleanly. |
|
QA tests have started for PR 1448. This patch merges cleanly. |
|
I have rebased & made changes according to the previous review comments. Also updated the title and description of the PR, combining two JIRA tickets. @chenghao-intel At least the following tests cover different join types. I ran it and the tests passed for both |
|
QA results for PR 1448: |
|
QA results for PR 1448: |
|
Thanks! I've merged this into master. |
…BroadcastNestedLoopJoin. This PR resolves the following two tickets: - [SPARK-2531](https://issues.apache.org/jira/browse/SPARK-2531): BNLJ currently assumes the build side is the right relation. This patch refactors some of its logic to take into account a BuildSide properly. - [SPARK-2436](https://issues.apache.org/jira/browse/SPARK-2436): building on top of the above, we simply use the physical size statistics (if available) of both relations, and make the smaller relation the build side in the planner. Author: Zongheng Yang <zongheng.y@gmail.com> Closes apache#1448 from concretevitamin/bnlj-buildSide and squashes the following commits: 1780351 [Zongheng Yang] Use size estimation to decide optimal build side of BNLJ. 68e6c5b [Zongheng Yang] Consolidate two adjacent pattern matchings. 96d312a [Zongheng Yang] Use a while loop instead of collection methods chaining. 4bc525e [Zongheng Yang] Make BroadcastNestedLoopJoin take a BuildSide.
…on refusal (apache#1457) ### What changes were proposed in this pull request? Each Varka baseline benchmark checks every section's plan before timing it. It compares the plan's fusion class with the class the section lists: `NONE` (no Varka node), `NULL_TESTS` (Varka fuses only the inferred null tests) or `WHOLE` (no row operator evaluates any of it). If the classes differ, the run stops. This keeps a row that starts fusing a section from quietly turning a baseline into a fused measurement. On an x86 host whose 64-bit vector species have two lanes or fewer, the session refuses a filter's condition in a kernel driven at a 64-bit lane and leaves it to the row engine (`spark.sql.codegen.varka.declineTwoLaneConditions`, which defaults to the host's answer). This is the host every benchmark's 128-bit companion runs on (`-XX:MaxVectorSize=16`). Projections are never refused. Two baselines still listed such filters with the classes they have without the refusal, so their 128-bit runs stopped before timing anything: - **`VarkaTimestampNtzBaselineBenchmark`**: the comparison `ntz < ntz2` as a filter, listed `WHOLE`. - **`VarkaDayTimeIntervalBaselineBenchmark`**: the filter `extract(HOUR FROM dt) >= 12`, listed `NULL_TESTS`, and the control filter `dt > dt2`, listed `WHOLE`. Under the refusal the inferred `dt IS NOT NULL` is refused along with the rest of the condition, so neither filter plans a Varka node. Both now build their sections with `sections(boolean declinesLongConditions)` and read the refusal from the Varka session (`VarkaSessionEmit.of(conf).declineTwoLaneConditions()`), as `VarkaFloatingCastBaselineBenchmark` and `VarkaFloatingBaselineBenchmark` already do. Under the refusal those three filter sections are `NONE` at both null densities. Every projection keeps its class. Section titles are unchanged, because they are the results files' labels. The control's title still says "fuses today", which is true everywhere except under the refusal. The day-time interval benchmark's kernel check runs only for `WHOLE` sections, so under the refusal the filter control left the 128-bit run with no fused control at all. The benchmark now has a second control, the projected blend `CASE WHEN dt > dt2 THEN dt ELSE dt2 END`, at both null densities. A projection is never refused, so the blend is `WHOLE` with its kernel check at both widths. The javadoc now calls the filter the 256-bit control, `NONE` under the refusal. The blend is a fusion control: it checks that the varka on arm times a kernel, and claims nothing about that kernel's speed at two lanes. **The suites.** Each baseline benchmark has a queries suite that makes the benchmark's fuse check in every build. The shared test sessions turn the refusal off (`VarkaSharedSessions` sets it to `false`, so the 128-bit test step does not test the row engine against itself). As a result, no suite ever checked the classes a 128-bit benchmark run expects. A new helper, `VarkaSharedSessions.forEachTwoLaneRefusal`, runs a body with the refusal off and then on, in both sessions. The fuse tests of the TIMESTAMP_NTZ, day-time interval, floating cast, floating arithmetic, integral cast, math, TIMESTAMP_NTZ arithmetic and TIMESTAMP_NTZ fields suites now check every section under both settings. Before this change the floating cast suite read the refusal from its session, which is always off. In the floating arithmetic, integral cast, math, TIMESTAMP_NTZ arithmetic and TIMESTAMP_NTZ fields suites every section has the same class under both settings, so the loop alone could not fail if the setting never took effect. Each loop now starts with a sentinel: a filter over two 64-bit columns (`x < y` on `DOUBLE`, `l < l_n` on `BIGINT`, an NTZ pair), which must fuse exactly when the refusal is off. With the refusal off it is also the "a Varka node is visible at all" check that used to run once outside the loop. The floating and boolean-output suites already looped both ways, by setting the conf on the Varka session alone; they now use the helper, so both sessions get the same setting. The rounding suite makes no fuse check. The decimal suite is left to the open pull requests that fix the decimal benchmark (apache#1422, apache#1448). **Limitations.** `forEachTwoLaneRefusal` sets the refusal in a JVM at its own width, with the shared sessions' unnamed emit level pinned. So it does not reproduce the 128-bit runner's host, where the benchmark's session resolves its emit level from the host (the floating cast benchmark's `BIGINT` casts, below, are the case where that matters). The deeper fix is an own-JVM check at `-XX:UseAVX=2 -XX:MaxVectorSize=16`, as `VarkaTwoLaneDefault128Suite` does for the refusal's default. That belongs with row 594. ### Why are the changes needed? A 128-bit companion run of either benchmark on the EPYC runners fails before timing. Run 41977272181 showed this for the day-time interval benchmark. The TIMESTAMP_NTZ benchmark's committed 128-bit results predate the refusal, so rerunning it fails the same way. No pull request check could see the failure, because the suites ran with the refusal off. ### Does this PR introduce _any_ user-facing change? No. Only benchmarks and test suites change. ### How was this patch tested? - **Queries suites**, on the laptop: the ten touched suites pass, 22 tests (`build/sbt "sql/testOnly ..."`). They also pass in a 128-bit JVM (`-XX:MaxVectorSize=16`): 22 tests. - **Plan-only dry runs** (`-Dvarka.bench.dryRun=true`) of every baseline benchmark with a fuse check, on the laptop (AMD Ryzen AI 9 HX PRO 370, AVX-512) at the preferred width and at `-XX:MaxVectorSize=16`. A dry run plans every section and runs the fuse check but times nothing. The "before" column is master at the merge base, the "after" column is this branch: | benchmark | before, preferred | before, 128-bit | after, preferred | after, 128-bit | |---|---|---|---|---| | `VarkaTimestampNtzBaselineBenchmark` | pass | **fail** (comparison listed `WHOLE`, plans `NONE`) | pass | pass | | `VarkaDayTimeIntervalBaselineBenchmark` | pass | **fail** (`extract(HOUR FROM dt) >= 12` listed `NULL_TESTS`, plans `NONE`) | pass | pass | | `VarkaFloatingBaselineBenchmark` | pass | pass | pass | pass | | `VarkaFloatingArithmeticBaselineBenchmark` | pass | pass | pass | pass | | `VarkaIntegralCastBaselineBenchmark` | pass | pass | pass | pass | | `VarkaMathBaselineBenchmark` | not run (sbt's own metaspace ran out) | pass | pass | pass | | `VarkaRoundingBaselineBenchmark` | pass | pass | pass | pass | | `VarkaTimestampNtzArithmeticBaselineBenchmark` | pass | pass | pass | pass | | `VarkaTimestampNtzFieldsBaselineBenchmark` | pass | pass | pass | pass | | `VarkaDecimalBaselineBenchmark` (unchanged here) | pass | fail (`DECIMAL(9, 2)` comparison, fixed in apache#1422 and apache#1448) | pass | fail, as before | | `VarkaBooleanOutputBenchmark` (unchanged) | fail (output sections fuse) | fail, the same | fail, the same | fail, the same | | `VarkaFloatingCastBaselineBenchmark` (unchanged) | fail (`BIGINT` casts listed `NONE`, plan `WHOLE`) | fail, the same | fail, the same | fail, the same; passes under `-XX:UseAVX=2` | After the second control was added, the day-time interval dry run reports both blend sections as fusing whole at both widths, and they are the only fused sections at `-XX:MaxVectorSize=16`, also under `-XX:UseAVX=2`. The TIMESTAMP_NTZ dry run passes at both widths again. The runners are AVX2, so the two fixed benchmarks and the floating baseline were also dry-run under `-XX:UseAVX=2`. All three pass at both widths. Two failures are not about the refusal, and this change leaves them alone: - `VarkaBooleanOutputBenchmark` stops at both widths because its output sections now fuse ("d < d2 output, no nulls fuses, so it is no longer a baseline"). This is by design. The benchmark exists to time those sections before they fuse, apache#1226 made them fuse, and its javadoc says a later change drops the check and times the same sections. - `VarkaFloatingCastBaselineBenchmark` lists the `BIGINT` casts as `NONE`, but they plan as `WHOLE` at the preferred width, both at AVX-512 and under `-XX:UseAVX=2` (the runners' AVX2). Under `-XX:UseAVX=2 -XX:MaxVectorSize=16` it passes. A `BIGINT` cast to `FLOAT` or `DOUBLE` fuses only at a named emit level (apache#1385, apache#1424). The benchmark's session resolves that level from the host. The test sessions pin the unnamed default (`spark.sql.codegen.varka.emit.useAVX=-1`, so that results mean the same on every runner), so its queries suite plans the casts as `NONE` and passes. Fixing that classification belongs with the `BIGINT` cast work, not with this change. - `PATH=$HOME/.venv-ruff/bin:$PATH python3 dev/varka_push_check.py`: passed (344 counted lines against the cap of 1000). Still owed: regenerating the TIMESTAMP_NTZ and floating 128-bit results files on the EPYC runners, and a first 128-bit run of the day-time interval benchmark. The committed day-time interval results file has no blend control yet, so its 256-bit run is owed too. No workflow was dispatched for this change. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
…ract (apache#1448) ### What changes were proposed in this pull request? Varka holds every type it reads to a shared conformance contract. `VarkaTypeConformance` compiles Catalyst expressions over two columns of the type, runs the emitted kernel over every pair of the type's values under every null pattern, and compares each row with Varka's reference evaluator and with Spark's own `eval`. `DECIMAL` had no such suite. The harness wrote one long per column per row, but a decimal above 18 digits is two 64-bit words a row: Arrow's sixteen-byte slot, which the kernel reads as a low-word lane and a high-word lane. So the type registry recorded the decimal's suite as owed. This PR adds the suite for both of the decimal's representations. **The harness learns sixteen-byte slots.** - `VarkaKernelChecks.runLoadedDecimal` runs a kernel whose columns are decimal slots, through a new lane, `DecimalSlotLane`. Each fixture value is an index into the suite's table of unscaled `BigInteger`s, and each slot is written as that value's two words, low word first. - A column's null rows hold `2^127 - 1` and `-2^127`, alternating by null ordinal. Both are outside every precision, so if the kernel's digit check wrongly reads a null row, it declines the batch and the test fails. - The reference evaluator only knows long columns. So the lane rewrites each word leaf (`DecimalWord`) as a long column of a row twice as wide: the low words first, then the high words. A 64-bit `DecimalColumn` leaf reads the low word, which is its value. - `VarkaSparkOracle.answerInternal` evaluates Spark's expression on Catalyst's internal values, and the harness hands it the `Decimal` that an index names. Up to 18 digits that `Decimal` is built from its unscaled long, as Spark's column readers build it. `answer` now calls `answerInternal` with the lane values, so every other suite gets the same answers as before. - Some kinds of kernel output are not laid out by the slot lane yet: a decimal store, a narrowing root, and a kernel that holds both lanes. The lane refuses them. The oracle also refuses a decimal output above 18 digits. Both fail loudly rather than reading those outputs wrongly. **Two suites, one per representation.** - `VarkaDecimalConformanceSuite` runs at `DECIMAL(30, 4)`, the 128-bit pair. Its eleven values are: - the precision's bounds and their neighbours; - `2^63`, whose low word has its sign bit set under a zero high word, and `-2^63 - 1`; - `-2^64`, whose low word is zero, and `2^64 + 5`; - zero, and one each way. - `VarkaDecimalLongConformanceSuite` runs at `DECIMAL(10, 2)`, the long. Its seven values are the bounds, their neighbours, and zero and one each way. - Both suites build their fixtures through `VarkaTypeConformance.decimal`. The registry's entry becomes `Suite("Decimal")`. **The census's fused-in-part marker.** The harness learns from the census whether each form must fuse. At one scale, the decimal comparisons, `IN` and `BETWEEN` already fuse. The census, though, counts `dec` as fused for them only once rows 360 and 363 add the rescale that a comparison across two scales needs. As things stood, the harness would call those forms drift. - A type marked `^` in `census_curated.txt` now means *fused in part*: one band or form of it fuses, and a coverage row must still show that. - `dev/varka_census.py` writes the marker to a new last column of `census.tsv`, `fused_in_part`, and never to `fused_today`. So the done-when counts and the need rule still read the type as unfused, and the first twelve columns of `census.tsv` are byte-identical. - The harness checks a fused-in-part form where it fuses. - A suite names the operators its fixture may see declined (`declinesInPart`: the pair's `in` alone). Any other fused-in-part form that declines fails as drift. A regression cannot hide as a cancelled check. Each entry is checked as well. It must name an operator the census marks fused in part for the type, and a check that runs its forms fails if none of them declines, with a message saying to drop the entry. **What the suites answer.** Every check runs its fused forms first. A check that also holds owed forms is then cancelled, and the message names each owed form and its rows. - Pair: - null handling passes in full; - load runs `x < y`, a comparison with a literal wider than a long, and `IS NOT NULL`, and is cancelled on `IN`; - ordering runs the six comparisons as conditions and as values, and is cancelled on `greatest` and `least`. - Long: - null handling and load pass in full, `IN` included; - ordering is cancelled on `greatest` and `least`. - Both suites cancel three more checks on forms that are not built yet: - choice and round trip, on decimal outputs; - the cast row, on the casts; - overflow, on the arithmetic. **Also here.** `emitted_bytes.json`'s four option-arm digests for the AVX2 conversion forms had gone stale on master. Each digest is one hash over every coverage shape, and two merges that added shapes landed one after the other. The full regeneration moves those four digests and nothing else; no shape's bytes change. **The EPYC measurement.** Both runs passed on an EPYC 7763 (MaxGekk/spark 42773199798 at 256 bits and 42773203967 at 128 bits), and their fourteen 359a sections are spliced into `VarkaDecimalBaselineBenchmark`'s two runner results files with `dev/varka_bench_sections.py splice`; every other section keeps its committed numbers, and each provenance file names the run its sections came from. At 128 bits the x86 long species has two lanes, so by default the session refuses a filter's condition in a kernel driven at a 64-bit lane (VARKA-503), and the baseline expects those filter sections on the row path; that rule came to master with apache#1422. - At 256 bits, the Varka arm against Spark's row path by best time: the `DECIMAL(38, 10)` comparison 9.7x; the `<=>` filter 25x to 30x; `x < y` as a value 20x to 28x; the `IS NULL` filter 14.5x at one row in ten null and a tie without nulls, where both arms read only the validity. - At 128 bits every filter section ties the row path, as expected under the refusal. `x < y` as a value still fuses there but is slower than the row path: 0.90x to 0.94x without nulls and 0.75x to 0.79x at one row in ten null. The pair's comparison as a value at two long lanes costs more than Spark's row; `VARKA-359.md` 10.5 records it. ### Why are the changes needed? Varka now reads a `DECIMAL` above 18 digits as two 64-bit words and compares them. Even so, the decimal was the one landed type without a conformance suite, so its word-level lowering was checked only by its own unit suites. The conformance checks are how every Varka type shows that its fused forms match Spark across the type's edge values and null patterns. The census marker is needed because without it the harness cannot tell two cases apart: "fuses at one scale, owed at two", and "the register has drifted from the compiler". ### Does this PR introduce _any_ user-facing change? No. The change touches tests, a tooling script and generated tables. Kernels and answers do not change. ### How was this patch tested? - The two new suites pass: seven tests each, with the cancellations listed above. Each takes about 6 s of test time in its own JVM. - A planted fault: the pair's low-word `ULT` was lowered as the signed `LT` by hand, then reverted. Load, null handling and ordering then fail on the first row whose low words straddle `2^63`, where the reference and Spark disagree. - At the defaults, through `dev/varka_matrix.sh --module catalyst`, on the merge with master: - every conformance suite; - `VarkaTypesSuite`, `VarkaEmittedBytesSuite`, `VarkaCoverageSuite` and `VarkaIrFuzzSuite`; - the suites that use the oracle or the long-lane harness. - The two decimal suites and `VarkaTypesSuite` under the lane-less matrix configurations `validityByWidth=false` and `lanesOverride=16`. - `dev/varka_census.py --check` and its self-test, `dev/varka_regen_generated.sh --all` with its changes committed, and `dev/varka_push_check.py`. - One `/code-review high` pass, with one round of fixes: - a fused-in-part form that stops fusing now fails instead of being cancelled; - decimals of 18 digits or fewer reach Spark backed by a long; - the null slots alternate by null ordinal; - the latent output paths are refused; - the shared fixture factory is in the base class; - `between` carries the marker. Left as they are: the reference reads the high words by rewriting the word leaves rather than through an overload, and the harness keeps its per-row `BigInteger` work, since the suites run in seconds. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
### What changes were proposed in this pull request? Plan documents only: six compiler improvements, accepted by the owner on 11 November 2026, are added to the milestone 9 scope catalogue (`sql/varka/plans/m9/SCOPE.md`). Each is a proposal to be measured, not a committed design. Three of them were already partly in the catalogue, so they extend an existing item with a dated paragraph rather than adding a duplicate. The other three are new items 134 to 136. 1. **Check the host's capabilities when emitting, not only when benchmarking: new item 134.** `operator_census.json` records, per host and vector width, whether C2 vectorizes each operator, allocates, or falls back to the Vector API's Java code. No main source reads it. Row 597's decimal readers fuse at 128 bits on x86, where the EPYC 7763's census cells put their slot load in the fallback, and a benchmark found the loss. The item makes each lowering name the census cells it depends on. Planning then treats a fallback cell on the target host as a predicted cost, which item 131's admission step weighs. It is not a refusal by itself, because apache#1262 kept two-lane projections that win although their compare cell reads fallback. It is new rather than part of row 551 or items 127 and 131, because those read HotSpot's feature list or decide *where* a choice is made. None of them use the measured census as the source, and the item sets out how it relates to each. 2. **Compute node properties instead of keeping hand-written lists: extends item 47.** Item 47, "One place per node", was deferred until a second concrete case arrived. The new paragraph records that case. Facts that consumers need sit in `instanceof` lists that miss nodes: the apache#1462 review found `mayHoldOtherNaN` skipping its blend without checking the rounding mode, and row 597 records that apache#1478's `readsDecimal` misses `bigintPair`. The paragraph proposes finishing row 489's descriptor, so the analysis derives these facts bottom-up. The descriptor has to be rebuilt over master, because its branch predates apache#1329. Item 51's mapping type is noted as one more field of the same record. 3. **One admission decision instead of a decline rule per row: extends item 131.** Item 131 already proposes letting the cost model make the two-lane decline. The extension widens it to rows 503, 596, 597 and 603 as one admission step per shape, host and width. That step reads measured costs and item 134's table and refuses with a named reason. It also records that `VarkaEmitCost.kindOf` counts `rint` with and without apache#1462's blend as one feature, which a refit would average. 4. **A hash-consed IR: new item 135.** No item proposes interning. Item 11 has only a one-line design note, and item 85 is about jegg and storage layout. The item starts from row 559 (apache#1329), which cached node hashes and chose that over interning, and lists the walks that still run once per path: the lane lifts, and `equals` over disjoint copies. 5. **Tests that prove they reach the code they claim to test: new item 136.** No item covers this. Two cases from the 11 November reviews show the problem: a test on apache#1436 that passes on an earlier output-type decline, and apache#1425's body claiming checked answers for a test that only asserts no fusion. The item proposes two fixes. Each decline carries the name of the rule that produced it, as `VarkaKernelPlan.Refusal` already carries a kind. The harness records which nodes and lowerings a test reached. `VarkaCompileObserver` is the starting point, but it needs a second listener slot and a lowering report. Item 82's mutation runs are cited as the related check. 6. **Generated files that stop conflicting on every merge: extends item 121.** Item 121 was moved to milestone 8 as row 546, whose merge driver (apache#1293) merged. The new paragraph records what is still left. Every merge still regenerates `option_arms` and the docs blocks and needs another Build, and apache#1448 found four option-arm digests stale on master with no text conflict. The paragraph proposes splitting the files and digests per shape or family, or committing an input digest that CI checks. It notes that row 546 had ruled out CI committing files, because the fork has no token for it. A note further out, folded into **item 1** (decimal lanes) as the owner asked: a general multi-word integer lane for decimals above 18 digits, instead of the per-operation work of rows 359 to 364. Corrections to the evidence as first stated, made after checking it against the tree: - Item 135 does not claim the coverage harness's 45% planning share. `m8/results/VARKA-510-planning-local.txt` puts 45.1% in Spark's analyzer and optimizer, and only 11.7% in Varka's compile and emit, which is the share an interned IR can cut. - The "planning doubles per level" cost of row 561 was fixed for hashing by row 559 (apache#1329), so item 135 cites only the walks that remain. - Row 541's CSE mismatch is between two of Spark's own code generators on the fallback path, so the item says it is outside the IR. - The "60 to 75 minute regeneration" is left out. No committed file records it, and the laptop's regeneration logs of 10 and 11 November show 1 to 23 minutes of sbt time. - The note's rows are 359 to 364, which is the lane-pair range in the milestone 8 header. Row 365 is a read-path fix and row 366 a cast to floating point. One `/code-review high` pass: found 10 / fixed 9 / left 1 (the title says "compiler items" though item 121 is harness work, kept because the owner's brief names the six that way). Fixed: item 134 now treats a census cell that reads F as a predicted cost for item 131's admission step to weigh, not as a refusal on its own, because apache#1262 kept the two-lane projections whose cells read F; items 131 and 134 are one piece of work, with the table built first; item 135 says interning still needs one shared identity memo for the walks; item 47 limits "may raise" to fused subtrees, notes that the 489 branch predates apache#1329, and points its done-when at what apache#1462 and apache#1478 bring to master; item 121's note marks that it stays in milestone 9 and depends on item 129's merge-result build for the stale-digest case; item 136 states `VarkaCompileObserver`'s single listener and that it reports no lowerings; item 131 takes a node's key from row 489's cost kind, and keeps a test for a second lowering of an existing node. A follow-up self-check also tightened four citations: the census's `long.LT` cell, row 559's "every node with a child", row 541's two gates, and the regeneration command's name. ### Why are the changes needed? Several recent problems follow the same patterns. A form known to fall back on a host was still emitted, and only a later EPYC run found it. A hand-written list missed a node or a mode. A decline rule was added for one row at a time. A test passed for a reason other than the one it names. Generated files cost every merge a regeneration and a Build. Recording these as scope items, with their evidence, keeps the fixes general instead of patched one row at a time. Extending the existing items, rather than adding near-duplicates, keeps the catalogue with one entry per idea. ### Does this PR introduce _any_ user-facing change? No. Plan documents only. ### How was this patch tested? `python3 dev/varka_plan_lint.py --check --offline` reports 0 findings. `python3 dev/varka_push_check.py` passes: pre-commit, plan lint, quote check, census check, and 138 counted lines against the cap of 1000. Every row, pull request, file and identifier cited in the new text was checked against `sql/varka/plans/m8/PLAN.md`, the tree at `origin/master`, or the open branches it names. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
…ould fuse (apache#1486) ### What changes were proposed in this pull request? When the Varka predicate compiler would fuse only `IS NOT NULL` tests of columns, with at least one other conjunct left on the row path, it now declines the whole filter. The filter then stays as Spark's own whole-stage `Filter`, the same plan the row path runs. How such a filter looked before this change. Spark's optimizer infers `IS NOT NULL` for each column that a null-intolerant condition reads. So `WHERE x * y < z` reaches the plan as `isnotnull(x) AND isnotnull(y) AND isnotnull(z) AND x * y < z`. For a `DECIMAL(15, 2)` product, or a checked `BIGINT` sum, no lowering computes the comparison, so it declines. The three null tests still fused, and the plan was split in two: ``` *(1) Filter ((x15 * y15) < cast(z15 as decimal(31,4))) +- VarkaFilterColumnarToRow ((isnotnull(x15) AND isnotnull(y15)) AND isnotnull(z15)), ... ``` The kernel reads the validity words and sets a selection bitmap. The to-row node then copies every selected row into an `UnsafeRow`, with every column the residual reads. The row `Filter` above evaluates the comparison over those rows. Spark's own plan reads the batch's vectors in place inside one whole-stage loop, where the null checks cost close to nothing. The inferred tests pass nearly every row, so the kernel saves the row filter almost no work. The extra pass and the copy are pure overhead. The rule is `nullTestsAlone` in `VarkaExpressionCompiler.predicate`. It runs inside the demotion loop, beside the conjunct-order rule (VARKA-380), so it is asked again after every demotion. A size demotion that leaves only these tests fused therefore declines them too. Each demoted test carries the reason in the compiler's per-conjunct explanation (`explainPredicate`): "only IS NOT NULL tests would fuse while another conjunct stays on the row path, ...". No Varka node is planned, so EXPLAIN shows Spark's own `Filter`. The decline belongs to the compiler, so the rule at planning and the task-side compile agree. It does not depend on the host. The cost is on the row side, and no lane width or emit level changes it, so no admission setting or configuration is added. What still fuses, both measured faster than the row path (below): - `IS NOT NULL` tests with nothing left over: there the kernel is the whole filter. - `IS NULL` beside a residual: written by a user, it usually passes few rows, so the kernel spares the row filter most of its work. It ties with no row passing and wins with one row in ten passing. A filter whose fused part reads a value (`isnotnull(l) AND l < 5 AND <residual>`) keeps its split. This PR does not measure that shape. The baselines' declared classes follow. In `VarkaDecimalBaselineBenchmark` the twelve `NULL_TESTS` sections become `NONE`: the lane pair's `-x < y` and `abs(x) < y` filters, at two precisions and two densities, and the `x + y < z` and `x * y < z` widening filters, at two densities. In `VarkaDayTimeIntervalBaselineBenchmark` the two `extract(HOUR FROM dt) >= 12` filters become `NONE`. In `VarkaBigintArithmeticBaselineBenchmark` (apache#1455) the two `filter l + l2 > 0, ANSI` sections, one per null density, become `NONE`. The other classes, and the two-lane refusal's lists, are unchanged. The committed runner results are not regenerated. Their varka on arm timed the split, and it now times Spark's plan, the same as the row path arm. `VarkaCoverageSuite` counts `Attribute` as infrastructure, next to `BoundReference`, because the rule asks it of a null test's operand. Two lessons go into `sql/varka/skills/`: the split's cost, and the fact that `dev/varka_regen_generated.sh --all` does not regenerate the golden corpus. ### Why are the changes needed? On the EPYC 7763 at 256 bits, every baseline section of this shape ran slower with Varka on than on Spark's row path: - `VarkaBigintArithmeticBaselineBenchmark`'s `filter l + l2 > 0, ANSI`: 0.74x without nulls and 0.82x at one row in ten null (apache#1455's runner results). - `VarkaDecimalBaselineBenchmark`'s `DECIMAL(15, 2) x * y < z filter`: 0.77x and 0.87x (apache#1475). - The eighteen other sections that the committed decimal runner file notes as fusing only their null tests, all slower. - The day-time baseline's `extract(HOUR)` filter (apache#1351). At 128 bits these sections tie, because the two-lane refusal already leaves their conditions to the row path there. The cause was measured on the laptop with a probe, `VarkaNullTestFilterProbe`, at the runners' level and width (`-XX:UseAVX=2 -XX:MaxVectorSize=32`), over the decimal baseline's 2,000,000 Arrow-cached rows. Best times in ms, row path then Varka on: | query | no nulls | one row in ten null | |---|---|---| | `x * y < z`, the baseline's section | 366 / 425 (0.86x) | 266 / 349 (0.76x) | | the three `IS NOT NULL` alone, `x` out | 126 / 44 | 106 / 64 | | the three `IS NOT NULL` alone, `x, y, z` out | 145 / 47 | 147 / 66 | | `y IS NULL AND (x * y) IS NULL` | 29 / 25 | 75 / 44 | The split's extra time over the row path is 59 and 83 ms. That is about the null-test kernel with all three columns copied out, 47 and 66 ms. So the row filter above costs about what Spark's whole filter does, and the kernel's pass plus the copy accounts for about the whole loss. A cheaper handoff would have to let the row filter read the batch in place, and that is Spark's plan, so declining is the cheapest handoff. The same kernel with nothing above it beats the row path by 2.2x to 3.1x. The selective `IS NULL` arm ties with no row passing (1.1x to 1.2x over the runs, under the 1.3x a claim needs) and wins at one row in ten (1.4x to 1.7x). That is why the rule covers only `IS NOT NULL`. After the change the section's two arms plan alike and time alike: 334 / 311 and 218 / 211 ms. The full output, three runs with the machine's load, is in `sql/varka/plans/m8/results/VARKA-598-probe.txt`. The laptop was shared with other jobs, so the arms are compared within a run. ### Does this PR introduce _any_ user-facing change? No. Answers are unchanged. With Varka enabled, a filter of this shape now runs as Spark's own plan instead of a Varka filter under a row filter. ### How was this patch tested? - `VarkaExpressionCompilerSuite`, new test, at `useAVX` -1, 2 and 3 (the unnamed level and the named ones). `isnotnull(i) AND sh > 5` declines whole, the reason is on the null test, and the residual keeps its own reason. A value conjunct beside the null test keeps the split. `IS NOT NULL` with nothing left over fuses. `IS NULL` beside the residual fuses. - `VarkaDecimalBaselineQueriesSuite`, new test, over the baseline's table at both densities and the three levels. The `x * y < z` filter plans no Varka filter and is `NONE`. `x IS NOT NULL` is `WHOLE`. `y IS NULL AND (x * y) IS NULL` keeps its Varka filter. Both sessions answer all three alike. The existing class check holds every section's new class, with the two-lane refusal off and on. - `VarkaDayTimeIntervalBaselineQueriesSuite` and `VarkaBigintArithmeticBaselineQueriesSuite`: the filters' classes are `NONE`. - `dev/varka_regen_generated.sh --all` moved no generated file. The golden corpus has its own regeneration (`VARKA_GOLDEN_REGEN=true`), and it moves all 139 of its `PARTIAL` filters to `PLAIN`. These are its `(expr) IS NOT NULL` filters, whose only fused part was the inferred column tests under a row filter. - Suites on the laptop, all green: - `VarkaExpressionCompilerSuite` and `VarkaConjunctOrderSuite`. - The decimal and day-time queries suites, `VarkaFilterExecSuite`, `VarkaFallbackReasonSuite`, `VarkaFamilySwitchQuerySuite`, `VarkaDifferentialSuite`, `VarkaDecimalReadPathSuite`, `VarkaLongLaneSuite`, `VarkaFloatingLaneSuite`, `VarkaCoverageDifferentialSuite`, `VarkaGoldenCorpusSuite` and `VarkaTwoLaneDefault128Suite`: 368 tests. - The regeneration's own suites. - `dev/varka_matrix.sh --defaults --split 4 -j 4`, every Varka suite at the defaults (198 suites), on the AVX-512 laptop at its native width and again with `--jvm-arg -XX:MaxVectorSize=16`: 4481 passed, 0 failed, 102 canceled by design, at both widths. - Every baseline benchmark passes its plan-only dry run (`-Dvarka.bench.dryRun=true`) under `-XX:UseAVX=2`, at `MaxVectorSize=32` and at `MaxVectorSize=16`. There were eleven on master before the merge. - Merged with master on 11 November 2026 (to apache#1483), which brought the BIGINT baseline (apache#1455) and the decimal conformance suites (apache#1448). The merge had no conflicts. `dev/varka_regen_generated.sh --all` ran on the merge, and the BIGINT sections' classes were changed as above. After the merge, on the laptop, all green: `VarkaExpressionCompilerSuite`, `VarkaConjunctOrderSuite`, `VarkaCoverageSuite` and the two decimal conformance suites (205 tests, 12 canceled by design: owed register rows and an opt-in dump); every `*BaselineQueriesSuite` (12), `VarkaGoldenCorpusSuite` and `VarkaTwoLaneDefault128Suite` (47 tests); and the plan-only dry runs of the BIGINT, decimal and day-time baselines under `-XX:UseAVX=2` at `MaxVectorSize=32` and `MaxVectorSize=16`. - A second review (`/code-review high`) of the merge and the BIGINT commit asked for the plan's files and tests lists to name the BIGINT baseline and for its `sections` doc to say why no class reads the refusal flag now; both done. The committed BIGINT runner results still note the filter fusing its null tests, kept like the decimal and day-time ones. - Review (`/code-review high`) found two suites that this change moves: - `VarkaTwoLaneDefault128Suite` expected `WHERE i < l` at two long lanes to keep the inferred `isnotnull(i)` as a kernel next to the refused long comparison. That is exactly this shape, so the expectation is now that it stays whole. - The golden corpus, regenerated as above. It also asked for a `PinsDefaults` tag on the new queries test and for the `NULL_TESTS` class doc to be updated. Both are done. Kept as trade-offs: - The rule reads syntax, so a user's selective `IS NOT NULL` over a mostly null column, next to a residual, now declines too. Plan time has no null count. - The decline sits in the compiler, not in the columnar rule, so that the planning compile, `explainPredicate` and the task's compile give the same answer and reason, as the size and order demotions already do. - A declined filter is compiled once before it is demoted. That is a planning cost only. Overlaps: - apache#1478 (row 596) edits the comment and the `VALUE` entry next to this PR's `NEGATED`/`ABS` entries in `VarkaDecimalBaselineBenchmark.sections`. The textual conflict is trivial, and the two rules compose: 596 declines a projection's boolean output at two long lanes, and this PR declines a filter at every width. - apache#1442 (row 339) changes NTZ month forms, which this PR does not touch. - apache#1484 (row 104) makes the BIGINT baseline's two `filter l + l2 > 0, ANSI` sections fuse `WHOLE` at 256 bits; whichever of apache#1484 and this PR merges second takes apache#1484's classes for those two sections. - Merged master e48a856. In `VarkaDecimalBaselineBenchmark`, two rules touch different sections, and both are kept: VARKA-596's (the projected decimal comparison is `NONE` where the session refuses 64-bit conditions) and this PR's (a filter of which only inferred null tests would fuse is `NONE`). The class's fuse check passes with the refusal on and off. `golden_corpus.json` was regenerated with `VARKA_GOLDEN_REGEN=true`; against master, the only change is 140 filters moving from `PARTIAL` to `PLAIN`. PLAN.md keeps master's rows 603 and 605 to 607 beside row 598, with rows 361 and 601 updated to match. Checks: both modules' test compile, `VarkaExpressionCompilerSuite` (177), `VarkaGoldenCorpusSuite` (4), `VarkaDecimalBaselineQueriesSuite` (21, the fuse check among them) and `VarkaTwoLaneDefault128Suite` (25), `dev/varka_regen_generated.sh --all` and `dev/varka_push_check.py`. One `/code-review high` pass on the resolution: found 6, fixed 4, left 2 (two ragged javadoc lines, and a sentence in `VarkaSqlBenchmarkBase`'s `NULL_TESTS` description whose neighbour reads as if it described `NONE`). - The EPYC 7763 runs of `VarkaDecimalBaselineBenchmark` and `VarkaDayTimeIntervalBaselineBenchmark` on this branch are not in this PR. The DayTime run passed, but the Decimal run never landed on a 7763 in six attempts. Both sets of numbers follow in a results PR, measured after this one merges, and row 598 stays Started until then. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
This PR resolves the following two tickets: