fix: Correctly compute nullability in recursive CTE schemas#22552
Open
neilconway wants to merge 1 commit into
Open
fix: Correctly compute nullability in recursive CTE schemas#22552neilconway wants to merge 1 commit into
neilconway wants to merge 1 commit into
Conversation
Contributor
Author
|
cc @kosiew I'll fill in the rest of the PR template tomorrow, but lmk what you think of this approach. |
9b087b3 to
33bcfcd
Compare
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Contributor
Author
|
Alright, I think this is ready for review. Personally I think this approach is simpler and more robust than #22037, but I'd love feedback either way. |
kosiew
approved these changes
May 29, 2026
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.
Which issue does this PR close?
Rationale for this change
Nullability analysis for recursive CTEs had two shortcomings:
The output schema of the
RecursiveQuerywas derived solely from the static (anchor) term. This is incorrect; the recursive term might widen nullability for some of the output columns.The schema of the CTE work table was derived solely from the static term. This is only correct for the first iteration of recursive CTE evaluation; on subsequent iterations, NULLs might have been deposited into the work table, so the static term's nullability properties may not hold.
In this PR, we fix the first issue by computing the output schema of the
RecursiveQueryby taking the union of the per-column nullability of the static and recursive terms. The output schema of theRecursiveQueryis stored explicitly, matching the approach taken for most logical plan nodes.We fix the second issue by conservatively marking the work table's columns as nullable. We could compute nullability precisely by repeatedly doing nullability analysis until we reach fixed point, but for now we take the simpler and cheaper approach.
What changes are included in this PR?
RecursiveQuery, computed by widening the per-column nullability of the static and recursive termsRecursiveQueryschema as part of proto deserialization, rather than attempting to serialize itAre these changes tested?
Yes; new unit and SLT tests added, existing tests updated.
Are there any user-facing changes?
Behavioral: nullability analysis for CTEs will be less buggy.
API:
RecursiveQueryis apub structthat has a new field (schema), and no longer derivesPartialOrd.