Conversation
KKould
force-pushed
the
feat/prepared-plan
branch
from
September 23, 2026 16:28
414fb47 to
45e3b79
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #383 +/- ##
==========================================
- Coverage 93.18% 93.09% -0.09%
==========================================
Files 257 258 +1
Lines 45852 47487 +1635
==========================================
+ Hits 42727 44209 +1482
- Misses 3125 3278 +153
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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?
The old
preparepath cached only a parsed SQLStatement: each execution still bound and optimized the query. ParameterizedINSERT ... VALUESwas also limited by bind-time constant evaluation. This PR makes prepared execution reuse a typed plan and updates the dependent execution paths.Issue link: N/A
What is changed and how it works?
d9e8766):Database::prepare/DBTransaction::preparetake SQL plus positional parameter types and produce aPreparedPlancontaining a bound, optimized plan and its arena.executesupplies values, clones the logical plan, and runs it without repeating parsing/binding/optimization. Placeholders are typed$1,$2, etc.; selected index ranges are bound and, when possible, specialized from residual predicates for the current parameter values.INSERT/VALUES(d9e8766): retain row expressions asExprRefinValuesOperatorinstead of requiring bind-time constants. Resolve explicitDEFAULTwhile binding; evaluate and castVALUESexpressions per execution, then apply missing-column defaults and target-column length/nullability checks inInsert. This enables expressions and positional parameters in preparedINSERT ... VALUES, as well as expression-based standaloneVALUES.db7d064): addParamArenaover the immutable preparedPlanArena, copying and replacing only parameter-dependent expressions; propagateMetaArenathrough the execution path so repeated executions do not mutate the cached plan. Index lookups are bound on the execution-local plan.45e3b79): keepExecNodes in place instead of moving them out of the arena on everynext_tuple; use arena-backedrewritefor projection/index expressions. SimplifyDataValue::Tuplewhile deriving lower/upper prefix-bound semantics from range context during comparison and index-key encoding; restore tuple-buffer reuse in SeqScan and IndexScan.PreparedPlans with explicit parameter/result types and positional values; SQLite adapts to the shared parameter IDs. Add prepared-plan/index-range unit tests and SQL logic cases forVALUES,INSERT, grouping and indexed predicates.Code changes
Check List
Tests
cargo test --lib --features decimal(426 passed)values.slt,group_by.slt,where_by_index.slt,where_by_index_explain.sltthroughsqllogictest-testSide effects
binder::prepare/db::prepare(AST preparation) andDatabase::execute/DBTransaction::executesignatures change to the typedPreparedPlanAPI.Note for reviewer
cargo fmt --all -- --checkpasses. The four-variant 720-second TPCC results are recorded intpcc/README.md; this run used--cool-temp-c 75because the machine idled above the runner's default 65°C gate.Performance follow-ups (not addressed here):
ScalarExpression::evalcreates temporaryDataValues and evaluates binary/cast nodes one at a time. A no-table prepared arithmetic microbenchmark shows nontrivial per-expression execution cost; benchmark a specialized/compiled evaluation path separately.ParamArena::newtraverses the entire prepared expression arena on every execution, even if only a few expressions depend on parameters. Investigate caching parameter-dependent expression references to avoid this scan.Redundant casts/projections are not optimized by this PR.