fix(nereids): prevent implicit BigInt/LargeInt to Double cast in join…#63054
Open
leonard9893 wants to merge 1 commit intoapache:masterfrom
Open
fix(nereids): prevent implicit BigInt/LargeInt to Double cast in join…#63054leonard9893 wants to merge 1 commit intoapache:masterfrom
leonard9893 wants to merge 1 commit intoapache:masterfrom
Conversation
… 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>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
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.
... 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.