Repository navigation
Fix SQLite-discovered SQL issues and support scalar subquery initialization - #389
Merged
Merged
Conversation
An AND over a union was merged like an OR: pieces disjoint from the other operand were kept, yet the predicate was reported fully consumed, so EliminateIndexFilter dropped the filter and index scans returned extra rows (e.g. id > 10 AND (id = 3 OR id = 21) returned 3). An empty piece in the union also hit an unreachable!() arm. Split range merging by operator: AND sweeps both sorted unions and keeps only the intersections of overlapping pieces, OR keeps the in-place union merge.
NULL index keys sort after every value, but range merging disagreed: - Eq x Eq placement used partial_cmp, so Eq(NULL) vs Eq(x) counted as overlapping; OR-merging them made no progress and recursed until the stack overflowed (e.g. c1 = 1 or c1 = 2 or c1 is null). - Scope OR Eq(NULL) put NULL first, and kept it only when the lower bound was excluded, so c1 >= 3 or c1 is null and c1 < 3 or c1 is null dropped the NULL rows. A scope only covers NULL when its upper bound is unbounded. Compare Eq x Eq with bound_compared, keep NULL as a trailing piece unless the scope already covers it, and drop the special NULL arms in union_piece that were masking the inconsistency.
Match SQLite, PostgreSQL and MySQL. Also show a missing column default as NULL in describe, and update slt expectations (two rowsort blocks reorder because NULL now sorts before lowercase text).
Replace ScalarApply and WHERE scalar joins with ScalarQueryInit and leaf Init expressions. Keep statement-local results in an owning ExecArenaView cache, including NULL results, and make them available before sorting, grouping and DISTINCT. Use arena-scoped references for initialization definitions and relocate view references before serialization. Add subquery SLT regressions and a database-level catalog reload test. Retain explicit rejection of correlated scalar subqueries.
Register signed and unsigned integer and floating-point overloads. Preserve NULL values and reject signed integer absolute-value overflow. Cover numeric columns, arithmetic arguments, predicates, NULL and overflow in SLT.
Expose Database::run_mut to consume the final statement's results inside a callback, reusing DDL execution, commit and catalog publication. Move statement scope cleanup into TransactionGuard so arena and DDL changes can be returned by value. Use run_mut in the SLT harness to avoid SQL parse-display-parse roundtrips. Reject aggregates in WHERE, prefer input columns over conflicting SELECT aliases in SELECT/WHERE, and correct floating-point integer-cast range checks with regression coverage.
Keep integer division results integral with checked zero and overflow handling, while preserving fractional AVG and floating-point results. Eliminate unary plus during binding and remove its evaluator dispatch. Short-circuit decisive boolean operands so guarded division is not evaluated. Update division expectations and cover text identity, signed division, overflow, NULL propagation and mixed floating-point expressions.
Push single-input predicates through cross joins and extract conjunctive equality predicates as inner-join keys, retaining residual filters and localizing right-side positions. Share join-key extraction with explicit JOIN binding. Raise the predicate-pushdown iteration cap to 30 for deeper join trees. Cover plans and query results with join SLT regressions. This does not implement join-order optimization.
Capture outer parameters separately from scalar results and use OuterParam, OuterValue and InitValue expressions to read execution-local values. Attach scalar initializers before their consumers without tuple result-column placeholders or post-hoc projections. Use an explicit ExecMetaArena on execution paths and confine value updates to it. Model scalar initialization with states and reuse a scratch tuple buffer while running child plans. Retain explicit rejection of correlated ORDER BY, DISTINCT and unsupported outer scopes. Add subquery SLT coverage for stage attachment, missing/NULL/text results, multiple correlations and unsupported boundaries. Gate the LMDB bounds helper to its supported build configurations.
Mark row-scoped scalar references and move their values alongside cached sort rows, restoring them before projection. Cover memory sort, TopK and spilled merge runs without scanning plans or introducing separate value maps. Flatten memory-sort keys, compose spill codecs for references and pairs, and consume range combinations directly through callbacks. Extend scalar-subquery regressions including NULL, text and mixed constant/row-dependent results.
6 of 9 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #389 +/- ##
==========================================
+ Coverage 93.30% 93.68% +0.38%
==========================================
Files 259 260 +1
Lines 47765 48783 +1018
==========================================
+ Hits 44565 45704 +1139
+ Misses 3200 3079 -121
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Keep shallow CTE plan references instead of cloning every expression at bind time. Remap positions through consumer-local expression references and reuse rewrites within each input schema. Cover repeated CTEs whose consumers require different columns.
This reverts commit 746719f.
Clone the CTE plan structure once and recursively isolate its mutable expressions using ExprCloner. Preserve scalar initialization references and cover repeated CTE consumers with different pruning requirements.
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.
What problem does this PR solve?
SQLite sqllogictest probing exposed incorrect index ranges, scalar-subquery limitations, and avoidable Cartesian products in implicit joins.
Issue link: Closes #386
What is changed and how it works?
NULL.Database::run_mut, reuse it for DDL, and remove SQL reprinting/reparsing from the SLT harness.abs, eliminate unary+during binding, and use PostgreSQL-style integer division while preserving fractional AVG. Fix alias precedence, numeric casts, and boolean short-circuiting.Code changes
Check List
Tests
Side effects
Note for reviewer
make testpasses (495 library tests, 20 macro tests), and all 199 SLT files pass. External converted SQLite select1–3 pass 5,413 records; index samples pass 71,486, with 5 overflow failures and 10 recursion-limit skips.