feat: Analyze VALUES for nullability#22089
Open
neilconway wants to merge 2 commits intoapache:mainfrom
Open
Conversation
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?
VALUESis never considered non-nullable #22088.Rationale for this change
LogicalPlanBuilder::infer_data(the inference path forVALUESclauses without a target schema) hard-coded every inferred column's nullability totrue, regardless of whether any row actually contained a NULL. This is inconsistent with how nullability is computed for other, similar situations (e.g.,SELECT 1).In addition to improving internal consistency (and theoretically allowing better query optimization), this also makes it easier to write tests for nullability-related behavior without using a scratch table.
What changes are included in this PR?
LogicalPlanBuilder::infer_datanow tracks per-column nullability while iterating values, marking the column nullable iff any row's value expression returnsnullable() == true. Note that this only changes behavior forVALUESwithout a schema;INSERT INTO VALUES, for example, already computed nullability.Are these changes tested?
Yes, with new tests added.
Are there any user-facing changes?
The inferred schema for
CREATE TABLE AS VALUES (...)will now change, although if we also fix #22087 then the original behavior will be preserved.