fix(sqlite): preserve NOT NULL from schema when explain loses it through ORDER BY#4222
Closed
barry3406 wants to merge 1 commit intolaunchbadge:mainfrom
Closed
fix(sqlite): preserve NOT NULL from schema when explain loses it through ORDER BY#4222barry3406 wants to merge 1 commit intolaunchbadge:mainfrom
barry3406 wants to merge 1 commit intolaunchbadge:mainfrom
Conversation
When a query uses ORDER BY, SQLite routes data through an ephemeral sorter table. The explain-based nullability analysis can lose NOT NULL constraints through this indirection, and sqlite3_column_table_name() returns NULL for ephemeral columns so the schema lookup also fails. Previously, the explain result took priority: exp_nullable.or(col_nullable). This meant a false "nullable" from explain would override the schema. Now, if the schema definitively says NOT NULL (col_nullable = Some(false)), that takes priority regardless of what explain inferred. The schema is the source of truth for column constraints. Fixes launchbadge#4147
Contributor
Author
|
Closing this — my fix was too aggressive and breaks LEFT JOIN / UNION nullability inference. The real issue is in the explain analyzer losing NOT NULL through ORDER BY + LIMIT ephemeral tables. Need to dig deeper into the EXPLAIN opcode tracking. Sorry for the noise. |
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.
Fixes #4147
When a query includes ORDER BY, SQLite routes data through an ephemeral sorter table. This causes two problems for nullability inference:
sqlite3_column_table_name()returns NULL for columns from ephemeral tables, so the schema-basedcolumn_nullable()fallback also returnsNoneBefore:
The macro then generates
Option<String>instead ofString, causing a compile error.After:
If the schema definitively says NOT NULL (
col_nullable = Some(false)), that takes priority over explain. The schema is the source of truth for column constraints.This fixes the case where
query_as!considersTEXT NOT NULLas nullable when ORDER BY is present.