nx_qplan.nx
buildroot/runtime/nx_qplan.nx
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
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
structs
| none |
consts
| 17 | const QP_MAGIC_9050: i64 = 9050 |
| 18 | const QP_MAGIC_5273: i64 = 5273 |
| 19 | const QP_MAGIC_50000: i64 = 50000 |
| 20 | const QP_MAGIC_1200: i64 = 1200 |
| 22 | const QP_OUT: i64 = 4096 |
| 23 | const QP_CONF_CAP: i64 = 4096 |
| 24 | const QP_TAB: i64 = 9 |
| 25 | const QP_NL: i64 = 10 |
| 26 | const QP_HASH: i64 = 35 |
| 27 | const QP_ZERO: i64 = 48 |
| 28 | const QP_SEQ: i64 = 0 |
| 29 | const QP_PAR: i64 = 1 |
functions
| 31 | func qp_atoi_rng(buf: *u8, a: i64, b: i64) -> i64 called by 1: qp_conf |
| 38 | func qp_conf(key: *u8, dflt: i64) -> i64 |
| 72 | func qp_cost_seq(mrows: i64, cw: i64) -> i64 |
| 78 | func qp_cost_par(mrows: i64, cw: i64, ncores: i64) -> i64 |
| 94 | func qp_choose(mrows: i64, cw: i64, ncores: i64) -> i64 |
| 101 | func 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 |
| 102 | func qp_num(out: *u8, o: i64, v: i64) -> i64 |
| 114 | func 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 |
| 117 | func qp_plan_json(mrows: i64, cw: i64, ncores: i64, out: *u8) -> i64 |
| 141 | func main(argc: i64, argv: *i64) -> i64 |