Skip to content

feat: Support swap for RightMark Join - #17651

Merged
alamb merged 8 commits into
apache:mainfrom
jonathanc-n:right-mark
Oct 1, 2025
Merged

feat: Support swap for RightMark Join#17651
alamb merged 8 commits into
apache:mainfrom
jonathanc-n:right-mark

Conversation

@jonathanc-n

@jonathanc-n jonathanc-n commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of fix for #16488

Changes

During decorrelation of an exists subquery into a LeftMark join, the inner side still carries the literal from 'select 1'. The schema looks like this:

right = Projection: [Int64(1), x.b]

Projection Pushdown later drops the unused constant and rewrites the right child to just [x.b]. That “drop the first column” step shifts right-side column indices (from b@1 to b@0). During projection mapping it still assumes the old index (often doing “offset by left_width” and not accounting for the mark column), so when it re-indexes into the child it points at the wrong slot (which is what hit the error)

to fix this, I removed the projections when optimizer builds the join

Tests

The test is added to slt.

@github-actions github-actions Bot added logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) common Related to common crate physical-plan Changes to the physical-plan crate labels Sep 18, 2025
@jonathanc-n

jonathanc-n commented Sep 18, 2025

Copy link
Copy Markdown
Contributor Author

@comphead Decided to circle back to this after forgetting that this was reverted 😆 Are you able to run extended tests?

@comphead

Copy link
Copy Markdown
Contributor

I think we got something broken, you can still run extended tests on your fork, against your branch

@jonathanc-n
jonathanc-n marked this pull request as draft September 18, 2025 21:43
@jonathanc-n
jonathanc-n marked this pull request as ready for review September 19, 2025 01:37
@jonathanc-n

jonathanc-n commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

@comphead It is passing on my end. I added the slt test that is the query that caused the error from the previous pull request.

@jonathanc-n

Copy link
Copy Markdown
Contributor Author

cc @comphead I believe this should be good for another look!

.partition_statistics(None)
.unwrap()
.total_byte_size,
Precision::Inexact(2097152)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this number be a reason of flaky test in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, i have copied this from the other previous join selection swapping testing and thos ehave been working fine.

Comment thread datafusion/optimizer/src/decorrelate_predicate_subquery.rs

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jonathanc-n I think the PR is good to go

Comment thread datafusion/physical-plan/src/joins/sort_merge_join/tests.rs Outdated
@alamb
alamb added this pull request to the merge queue Oct 1, 2025
Merged via the queue into apache:main with commit bd95a6b Oct 1, 2025
28 checks passed
Vedin added a commit to Embucket/datafusion that referenced this pull request Jul 2, 2026
… column, stale EXPLAIN plans

- to_date: Float64 sat in the direct-cast arm, but arrow has no
  Float64 -> Date32 cast; route it through the Int64 two-step like
  Float16/Float32/Decimal (dates.slt:216 now passes, truncation
  semantics identical to the other float widths).
- PIVOT: the value column was rendered with Expr::to_string, which keeps
  quote characters, so a quoted pivot column (FOR "2023_Q1" IN ...)
  never matched its schema field and was not consumed by the pivot.
  Normalize the identifier like the rest of the planner (pivot.slt
  nested-PIVOT case now passes).
- subquery.slt: regenerate the two EXPLAIN expectations — the plans
  changed upstream (CoalesceBatchesExec deprecated in apache#19622, LeftMark
  -> RightMark swap added in apache#17651) and were never regenerated during
  the df53 sync; physical-plan shape only, logical plans unchanged.

encrypted_parquet.slt still fails locally only (expects a no-keys read
to error; environment-dependent, fails identically on the clean base,
passes in CI).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Vedin added a commit to Embucket/datafusion that referenced this pull request Jul 2, 2026
…cs) (#43)

* Decimal division and AVG round half away from zero (Snowflake semantics)

Snowflake rounds the last digit of decimal division and AVG results half
away from zero (verified live: 5/3 = 1.666667, -5/3 = -1.666667,
5/2000000 = 0.000003 — not half-even, not truncation). Arrow's div kernel
and DecimalAverager::avg both truncate toward zero, which produced the
persistent <=1 ULP parity gap on TPC-H Q1/Q8 and ClickBench Q28.

- DecimalAverager::avg: correct the truncated quotient with the remainder.
- BinaryExpr Divide on decimals: dispatch to a fork-local kernel that
  replicates arrow-arith's decimal Op::Div exactly (result precision/scale
  derivation, overflow and divide-by-zero errors) but rounds half away
  from zero. Forking arrow itself was rejected as far heavier.
- decimal.slt expectations regenerated; pre-existing failures in
  subquery/dates/encrypted_parquet/pivot slt files are unchanged (verified
  identical on the clean base).
- Bump the workspace sqlparser pin to the Snowflake string-escape fix rev
  (074bd21) so downstream consumers resolve a single sqlparser instance.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Point sqlparser at the merged sync-branch head (01e9e5e)

The Snowflake string-escape fix was squash-merged into
embucket-sync-df53.0.0-parser0.61.0 as 01e9e5e (content-identical to the
previously pinned 074bd21 feature-branch rev).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Fix pre-existing sqllogictest failures: to_date(double), quoted PIVOT column, stale EXPLAIN plans

- to_date: Float64 sat in the direct-cast arm, but arrow has no
  Float64 -> Date32 cast; route it through the Int64 two-step like
  Float16/Float32/Decimal (dates.slt:216 now passes, truncation
  semantics identical to the other float widths).
- PIVOT: the value column was rendered with Expr::to_string, which keeps
  quote characters, so a quoted pivot column (FOR "2023_Q1" IN ...)
  never matched its schema field and was not consumed by the pivot.
  Normalize the identifier like the rest of the planner (pivot.slt
  nested-PIVOT case now passes).
- subquery.slt: regenerate the two EXPLAIN expectations — the plans
  changed upstream (CoalesceBatchesExec deprecated in apache#19622, LeftMark
  -> RightMark swap added in apache#17651) and were never regenerated during
  the df53 sync; physical-plan shape only, logical plans unchanged.

encrypted_parquet.slt still fails locally only (expects a no-keys read
to error; environment-dependent, fails identically on the clean base,
passes in CI).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants