code wiki / (root) / nx_qplan.nx

nx_qplan.nx

buildroot/runtime/nx_qplan.nx

7844 B156 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_qplan.nx -- COST-BASED QUERY PLANNER, the optimizer that makes the engine intelligent (the capstone over colframe/vecexec/distexec/parexec). What separates a query engine from a bag of operators is a planner that ESTIMATES the cost of each execution strategy and CHOOSES the cheapest -- and ours is grounded in the numbers we MEASURED, not guessed (that is the whole point of having benched parexec). The decision the bench proved and this encodes: a job splits into a SCAN cost (bandwidth-bound, barely parallelises -- 4 workers fight one memory bus) and a per-row COMPUTE cost (CPU-bound, parallelises by ~ncores x efficiency). Parallel execution also pays a fixed FORK/COW cost. So: cost_seq(Mrows, cw) = scan_us*Mrows + comp_us*cw*Mrows cost_par(Mrows, cw) = fork_us + scan_us*Mrows*bw_penalty + (comp_us*cw*Mrows)*1000/(ncores*eff_permille) Pure scan (cw=0): parallel adds fork+penalty and divides nothing -> SEQUENTIAL wins (we measured 0.66x). Heavy compute (cw high): the /ncores term dominates -> PARALLEL wins (we measured 3.10x). Small data: fork_us dwarfs the work -> SEQUENTIAL. All constants live in analyst_qplan.conf (rule 11), seeded FROM the measured bench. license_tier: ORIGINAL No hardware writes (Rule 26).

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_estate_path.nx nx_qplan.nx nx_qplan_gate.nx

imports: nx_syscalls.nxnx_estate_path.nx

imported by: nx_qplan_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ep_anchor sys_openat_rd sys_close sys_chdir sys_mmap sys_mmap ↻ qp_atoi qp_plan_json qp_cost_seq qp_conf sys_openat_rd ↻ sys_mmap ↻ sys_read sys_close ↻ qp_atoi_rng qp_cost_par qp_conf ↻ qp_choose qp_cost_seq ↻ qp_cost_par ↻ qp_raw qp_num sys_mmap ↻ sys_write

structs

none

consts

17const QP_MAGIC_9050: i64 = 9050
18const QP_MAGIC_5273: i64 = 5273
19const QP_MAGIC_50000: i64 = 50000
20const QP_MAGIC_1200: i64 = 1200
22const QP_OUT: i64 = 4096
23const QP_CONF_CAP: i64 = 4096
24const QP_TAB: i64 = 9
25const QP_NL: i64 = 10
26const QP_HASH: i64 = 35
27const QP_ZERO: i64 = 48
28const QP_SEQ: i64 = 0
29const QP_PAR: i64 = 1

functions

31func qp_atoi_rng(buf: *u8, a: i64, b: i64) -> i64
called by 1: qp_conf
38func qp_conf(key: *u8, dflt: i64) -> i64
72func qp_cost_seq(mrows: i64, cw: i64) -> i64
called by 3: qp_chooseqp_plan_jsonmain calls 1: qp_conf
78func qp_cost_par(mrows: i64, cw: i64, ncores: i64) -> i64
called by 3: qp_chooseqp_plan_jsonmain calls 1: qp_conf
94func qp_choose(mrows: i64, cw: i64, ncores: i64) -> i64
101func qp_raw(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } return o }
called by 1: qp_plan_json
102func qp_num(out: *u8, o: i64, v: i64) -> i64
called by 1: qp_plan_json calls 1: sys_mmap
114func qp_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; var go: i64 = 1; while go == 1 { let c: i64 = s[i] as i64; if c < 48 { go = 0 } else { if c > 57 { go = 0 } else { v = v * 10 + (c - 48); i = i + 1 } } } return v }
called by 1: main
117func qp_plan_json(mrows: i64, cw: i64, ncores: i64, out: *u8) -> i64
141func main(argc: i64, argv: *i64) -> i64