Expand description
Query planner: name resolution, WHERE analysis, cost model, join ordering.
Implements:
- Compound SELECT ORDER BY resolution (§19 quirk: first SELECT wins)
- Cost model for access paths in page reads (§10.5)
- Index usability analysis for WHERE terms (§10.5)
- Bounded beam search join ordering — NGQP-style (§10.5)
Note: AST-to-VDBE compilation is an integration concern and lives above the planner layer per the workspace layering rules (bd-1wwc).
Modules§
- codegen
- AST-to-VDBE bytecode compilation (§10.6).
- decision_
contract - Decision Contract for the query planner (bd-1lsfu.6).
- differential
- Planner-side fail-closed compiler for Bloodstream-compatible view shapes.
- stats
- Statistics for cost-based query planning.
Structs§
- Access
Path - A concrete access path chosen by the planner.
- Cost
Metrics Snapshot - Point-in-time snapshot of planner cost metrics.
- Cracking
Hint Store - Minimal adaptive hint cache keyed by table name.
- Index
Info - Metadata about an index, used for cost estimation and usability checks.
- Join
Plan Segment - One join-operator decision segment.
- Morsel
Eligibility - Morsel-parallel SELECT eligibility decision produced by the planner.
- Planner
Feature Flags - Planner feature toggles.
- Pushed
Predicate - A pushed-down predicate: WHERE term assigned to a specific table.
- Query
Plan - The final output of the query planner: an ordered access plan.
- Query
Planner - Stateful planner wrapper that memoizes query plans by SQL template and schema cookie.
- Resolved
Compound Order By - A resolved ORDER BY term for a compound SELECT.
- Rowid
Alias Hint - Schema hint that a visible table column is an alias for SQLite’s hidden
rowid, as with
INTEGER PRIMARY KEY. - Table
RefWith Stats - A table reference paired with cost-model inputs for join ordering.
- Table
Stats - Statistics about a table, used for cost estimation.
- Where
Column - The column side of a WHERE comparison.
- Where
Term - A decomposed WHERE term with the column it references (if any).
Enums§
- Access
Path Kind - The kind of access path the planner can choose for a table scan.
- Access
Path Probe - Probe expressions extracted from the WHERE clause during access-path selection. Carried forward so downstream consumers (connection seam, VDBE codegen) do not re-extract from the AST.
- Compound
Order ByError - Errors during compound ORDER BY resolution.
- Fold
Result - Result of attempting to fold a constant expression.
- Index
Usability - Result of analyzing a WHERE term against an index.
- Join
Operator - Join operator chosen for a segment of the join plan.
- Morsel
Ineligible Reason - Why a query was deemed ineligible for morsel-parallel execution.
- Multi
Column Trailing Constraint - Single
Table Projection Error - Errors during single-table result-column resolution.
- Stats
Source - How table/index statistics were obtained.
- Where
Term Kind - Classification of a WHERE term for index usability.
Constants§
- DEFAULT_
PLAN_ CACHE_ CAPACITY - Default number of cached query plans retained by
QueryPlanner.
Functions§
- analyze_
index_ usability - Determine the usability of an index for a set of WHERE terms.
- asymmetric_
estimation_ loss - Compute asymmetric loss between estimated and actual costs.
- best_
access_ path - Build the cheapest
AccessPathfor a table given available indexes and WHERE terms. Returns the lowest-cost option. - best_
access_ path_ with_ hints - Build the cheapest
AccessPathwhile applying explicit index hints and optional adaptive cracking hint reuse. - best_
access_ path_ with_ rowid_ alias_ hints - Build the cheapest
AccessPathwhile recognizing schema-provided rowid alias columns such asid INTEGER PRIMARY KEY. - choose_
join_ segments - Select join operator segments for a query plan.
- classify_
where_ term - Classify a single WHERE expression into a
WhereTerm. - collect_
table_ index_ hints - Extract per-table index hints from a FROM clause.
- compound_
op_ name - Get the compound operator type names for a compound SELECT (for logging).
- compute_
mx_ choice - Compute the
mxChoicebeam width from the number of tables in the join. - cost_
metrics_ snapshot - Take a point-in-time snapshot of cost estimation metrics.
- count_
output_ columns - Count the number of output columns in a
SelectCore. - decompose_
where - Decompose a WHERE clause into individual conjuncts (AND-separated terms).
- detect_
star_ query - Detect a star-query pattern: one table joins to all other tables.
- estimate_
cost - Estimate the cost (in page reads) for a given access path.
- estimate_
cost_ ext - Estimate the cost (in page reads) for a given access path, optionally incorporating the table row count (PLANNER-2).
- extract_
output_ aliases - Extract output column alias names from a single
SelectCore. - is_
compound - Check whether a
SelectBodyis a compound query (has UNION/INTERSECT/EXCEPT). - order_
join_ inputs_ with_ hints - Decide a join evaluation order for
tablesusing per-table cost hints. - order_
joins - Order tables using bounded beam search (NGQP-style, §10.5).
- order_
joins_ with_ hints - Order tables using bounded beam search while honoring table-level
INDEXED BY/NOT INDEXEDhints and optional adaptive cracking hints. - order_
joins_ with_ hints_ and_ features - Order tables using bounded beam search and select join operators (hash vs Leapfrog Triejoin) based on feature flags and cost model.
- plans_
enumerated_ total - Take a snapshot of plans-enumerated counter.
- pushdown_
predicates - Push WHERE predicates down to the lowest possible table in the join tree.
- record_
estimation_ error - Record an estimation error observation (actual_cost / estimated_cost).
- reset_
cost_ metrics - Reset cost estimation metrics.
- reset_
plans_ enumerated - Reset plans-enumerated counter.
- resolve_
compound_ order_ by - Resolve all ORDER BY terms for a compound SELECT statement.
- resolve_
single_ table_ result_ columns - Resolve result columns for a single-table SELECT by:
- resolve_
single_ table_ result_ columns_ with_ options - Resolve result columns for a single-table SELECT with explicit control over
whether hidden rowid aliases (
rowid,_rowid_,oid) are available. - snapshot_
index_ selection_ totals - try_
constant_ fold - Attempt to constant-fold an expression.