Repository navigation
fix: validate recursive CTE column coercion - #25956
goutamadwant wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25956 +/- ##
==========================================
+ Coverage 82.58% 82.89% +0.30%
==========================================
Files 1144 1154 +10
Lines 443198 458083 +14885
Branches 443198 458083 +14885
==========================================
+ Hits 366024 379726 +13702
- Misses 54978 55317 +339
- Partials 22196 23040 +844 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kumarUjjawal
left a comment
There was a problem hiding this comment.
Thank you @goutamadwant for the fix.
| if type_union_coercion(into, from).as_ref() != Some(into) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Medium · Apply decimal range checks before the UNION-type gate
For an Int64 recursive column and a DECIMAL(19,0) seed, this gate rejects a lossless conversion: type_union_coercion represents signed and unsigned 64-bit integers as Decimal128(20,0), although every signed Int64 fits in 19 digits. Consequently, WITH RECURSIVE t AS (SELECT 1::DECIMAL(19,0) AS a UNION ALL SELECT 2::BIGINT FROM t WHERE a < 2) SELECT * FROM t now fails planning. The more accurate signed-integer range check below is never reached. Handle decimal destinations with that range/scale check before requiring equality with UNION's common type.
Which issue does this PR close?
Rationale for this change
A recursive CTE currently casts each recursive column to the non-recursive term's type, even when that discards information. A fractional increment can therefore become the same integer on every iteration, returning incorrect rows or preventing termination. The query should fail during planning and explain how to choose the intended output type.
What changes are included in this PR?
What is the testing strategy for this PR?
cte.sltregressions for float/decimal-to-integer coercion, integer-to-float precision loss above 2^53, float-to-decimal rounding, nested structs, cross-category coercion, and decimal range saturation. The error cases useEXPLAINso they cannot run indefinitely.cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings, the focusedcte.sltsuite, and the extended workspace test command fromAGENTS.md.Are there any user-facing changes?
Yes. Recursive CTEs with unsafe implicit type coercion or mismatched compound types now fail at planning time with a hint to cast the non-recursive term to the intended type. No public API changes.