Skip to content

fix(nereids): prevent implicit BigInt/LargeInt to Double cast in join…#63054

Open
leonard9893 wants to merge 1 commit intoapache:masterfrom
leonard9893:fix-issue-62968-bigint-join-precision
Open

fix(nereids): prevent implicit BigInt/LargeInt to Double cast in join…#63054
leonard9893 wants to merge 1 commit intoapache:masterfrom
leonard9893:fix-issue-62968-bigint-join-precision

Conversation

@leonard9893
Copy link
Copy Markdown

@leonard9893 leonard9893 commented May 7, 2026

... type coercion

BigInt and LargeInt types have higher precision (19 and 39 digits respectively) than DoubleType (53-bit mantissa, ~15-17 significant digits). When BigInt/LargeInt are used in join conditions with Float/Double types, the implicit cast to DoubleType loses precision, causing duplicate join results for values beyond 2^53.

Fix: use DecimalV3Type instead of DoubleType as the wider type when joining BigInt/LargeInt with Float/Double types. DecimalV3 preserves exact integer representation.

Closes: #62968


What problem was fixed and how it was fixed

Problem: When joining a BigInt/LargeInt column with a Float/Double column in a query condition, Doris implicitly casts both sides to DoubleType. DoubleType has only 53-bit mantissa (~15-17 significant digits), which cannot accurately represent BigInt values (up to 19 digits) or LargeInt values (up to 39 digits). This causes duplicate join results and incorrect query results for values beyond 2^53.

Reproduction: This issue was reported in #62968. When a BigInt column containing values larger than 2^53 is joined with a Double column via implicit cast to Double, values that differ in the original BigInt column can become indistinguishable after the Double cast, leading to duplicate matches.

How it was fixed: Instead of casting to DoubleType, the join condition now uses DecimalV3(38, 0) as the wider type when joining BigInt/LargeInt with Float/Double types. DecimalV3 preserves exact integer representation without precision loss.

Which behaviors were modified

Previous behavior: Joining BigInt/LargeInt with Float/Double columns would implicitly cast both to DoubleType, losing precision for BigInt values beyond 2^53 and causing duplicate join results.

Current behavior: The join condition casts to DecimalV3(38, 0) instead of DoubleType, preserving exact integer representation and eliminating false duplicate matches.

Impact: This change only affects join conditions involving BigInt/LargeInt with Float/Double types. Performance impact is negligible as DecimalV3 comparison is efficient. Correctness is improved for edge cases with large integer values.

What features were added

No new features were added. This is a bug fix.

Which code was refactored

No code refactoring was involved.

Which functions were optimized

No functions were optimized. The fix changes the type coercion logic in Nereids planner for join condition type resolution, ensuring precision-preserving type promotion for BigInt/LargeInt vs Float/Double joins.

… type coercion

BigInt and LargeInt types have higher precision (19 and 39 digits respectively)
than DoubleType (53-bit mantissa, ~15-17 significant digits). When BigInt/LargeInt
are used in join conditions with Float/Double types, the implicit cast to DoubleType
loses precision, causing duplicate join results for values beyond 2^53.

Fix: use DecimalV3Type instead of DoubleType as the wider type when joining
BigInt/LargeInt with Float/Double types. DecimalV3 preserves exact integer
representation.

Closes: apache#62968
Signed-off-by: leonard9893 <Leonard9893@gmail.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Doris bigint column join will auto cast to double, result repeat. bigint类型关联时自动转double, 导致重复关联。

2 participants