Skip to content

Optimizer implementation

Alexey Ozeritskiy edited this page Oct 14, 2026 · 1 revision

Optimizer implementation

Implementation reference checked against f5e786f. Fundamental explanations remain in docs/arch.

Entry points and diagnostics

QDB_DUMP_PASSES=1 prints intermediate plans. --nocbo selects the heuristic ordering path; --verbose also prints physical/runtime diagnostics.

QDB_DUMP_PASSES=1 ./build/bin/qdb --sql --data /path/to/parquet -i query.sql
./build/bin/qdb --sql --verbose --data /path/to/parquet -i query.sql

The CBO component bound is NCbo::MaxRelations = 12. The region falls back when CBO is disabled, an input lacks row statistics, an edge endpoint lacks a positive NDV, there are no equality edges, a component exceeds the bound, or search returns no tree. TPlanDiagnostics::JoinReorder records strategy and reason. Disconnected CBO components are cross-joined in relation-count order.

Source-file navigation is maintained in the repository's AGENTS.md. Detailed examples formerly used to reproduce optimizer plans are retained below.

Reproducing the plans

QDB_DUMP_PASSES=1 ./build/bin/qdb --sql --data <dir> -i q.sql   # plan after every pass
./build/bin/qdb --sql --verbose --data <dir> -i q.sql           # logical + runtime plan + scheduler graph

All examples below use four tiny Parquet tables:

table columns rows
t a int64, b string, c int64 6
u a int64, d string 4
v a int64, e int64 3
big a int64, c int64 40 rows in 4 row groups

Plans are printed by PrintPlanTree (qdb/plan/plan_print.cpp); source paths are shortened here. rows≈/cost≈ annotations appear once EstimateStats has run, and are elided below where they are not the point.

Clone this wiki locally