writeonce/tests/corpus/run/query-index-probe/fixture.wo
shoney.arickathil 881b90e9c7 feat: O(1) read path — index probe wired end to end
- engine: wo_idx_probe answers single-column equality from the index
  hash buckets (idx_hash_key1 reproduces idx_hash bit for bit; verify
  compares exactly as the slab walk did, so results identical);
  composite indexes keep the walk; both executors wired (local + DB
  actor RPC)
- compiler: probe_key_of_where lowers "var.col == key" on an indexed
  column to DB_PROBE; all where guards still run (guard stays the
  final arbiter); keys = ident/int-literal only; Float/Bytes excluded
  (engine raw-eq narrower than VM float-eq)
- measured: reads 1.3k -> 1.3M ops/s, p50 600us -> 1us (~x850);
  query x830; mixread 1.3k -> 89k s1, 21 -> ~1.9k sN
- gate policy moved into the driver (tolerance_for: refresh-proof);
  latency floors max(4x,100us); quick mode skips poll-bound mix
  floors; both tolerance classes proven to bite
- proof: test_table wo_idx_probe suite (RED first), corpus
  query-index-probe 105/0, full battery green, TSan clean, two
  campaigns pass the refreshed baseline

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 16:44:56 +02:00

58 lines
1.6 KiB
Text

-- index selection: `where var.col == key` on a single-column-indexed
-- column lowers to DB_PROBE; the same query on an unindexed column
-- keeps the scan. Results must be identical either way — the where
-- guard stays the final arbiter (probe supplies candidates only).
@table(name: "pts", index: [k])
class Pt {
k: Int
u: Int
tag: Text
}
@table(name: "named", index: [name])
class Named {
name: Text
}
fn main() -> Int {
let i = 0;
while i < 30 {
insert Pt { k: i % 3, u: i % 3, tag: "t${i % 3}" };
i = i + 1;
}
insert Named { name: "alpha" };
insert Named { name: "beta" };
-- probe path (k indexed) vs scan path (u unindexed): same counts
let key = 2;
let a = 0;
for x in from x in Pt where x.k == key select x {
a = a + 1;
}
let b = 0;
for x in from x in Pt where x.u == key select x {
b = b + 1;
}
print("indexed ${a} unindexed ${b}");
-- probe + second guard: guard still filters candidates
let c = 0;
for x in from x in Pt where x.k == key where x.u == 2 select x {
c = c + 1;
}
let d = 0;
for x in from x in Pt where x.k == key where x.u == 0 select x {
d = d + 1;
}
print("guarded ${c} and ${d}");
-- mirrored equality + literal key + take
let e = 0;
for x in from x in Pt where key == x.k take 4 select x {
e = e + 1;
}
print("mirrored-take ${e}");
-- text key probe (unique index): hit and miss
let want = "beta";
let hit = from n in Named where n.name == want take 1 select n;
let miss = from n in Named where n.name == "gamma" take 1 select n;
print("text ${len(hit)} ${len(miss)}");
return 0;
}