(*---------------------------------------------------------------------------
Copyright (c) 2026 Thomas Gazagnaire. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)
(** Tests for {!Sqlite.Select}: the machine that runs a SELECT, exercised
through a real handle by its one observable -- which access path a run took,
seen as {!Sqlite.Stats.rows_scanned} -- and the rows it returns.
The rows a query returns are the same whichever path ran, so the cost is
asked through each executor decision: that an uncorrelated subquery is
folded to a constant once rather than re-evaluated per outer row, that a
bare [IN (SELECT ...)] is a membership answered off the folded set, that a
recursive CTE reaches its fixpoint, that a compound folds its arms through
the set operator, that a shape the VM declines falls back to the engine with
the same answer, and that EXPLAIN prints the plan the run then takes.
The doors that answer a row at a time are asked the same way: that they hand
over what the list doors list, in that order, whatever shape the select is;
that a caller may stop by raising and pays only for the rows it read; and
that a scan of a wide table retains a row rather than an answer, which is
the whole of why those doors exist. *)
open Sqlite
let value = Alcotest.testable Value.pp ( = )
let rows = Alcotest.(list (list value))
let q db sql = Raw.query db sql ~params:[]
(* The full-scan steps one query adds to the handle's counter: the access path
it took, read as {!Stats.rows_scanned} does, across that query alone. *)
let scanned db sql =
let before = Stats.rows_scanned db in
ignore (q db sql : value list list);
Stats.rows_scanned db - before
let ints xs = List.map (fun i -> [ Int (Int64.of_int i) ]) xs
(* Two tables: [t] with 10 rows [1..10], [u] with 30 rows [1..30]. *)
let two_tables () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a INTEGER)";
Table.create_table db ~sql:"CREATE TABLE u (b INTEGER)";
for i = 1 to 10 do
ignore (Table.insert db ~table:"t" [ Int (Int64.of_int i) ])
done;
for i = 1 to 30 do
ignore (Table.insert db ~table:"u" [ Int (Int64.of_int i) ])
done;
db
(* An uncorrelated scalar subquery reads nothing of the outer row, so it is
folded to its value once before the outer scan; a correlated one is
substituted and re-run for each outer row. Both scan [u]'s 30 rows (29
steps); folded once, the query costs [t]'s pass plus one of [u]'s
(9 + 29 = 38), while re-running the correlated one over all 10 outer rows
costs 9 + 10 * 29 = 299. The count is the whole of the difference: the rows
are identical -- the subquery matches nothing either way. *)
let test_uncorrelated_folded_correlated_per_row () =
let db = two_tables () in
let uncorrelated = "SELECT a, (SELECT b FROM u WHERE b = 999) FROM t" in
let correlated = "SELECT a, (SELECT b FROM u WHERE b = a + 100) FROM t" in
let want =
List.map
(fun i -> [ Int (Int64.of_int i); Null ])
[ 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 ]
in
Alcotest.check rows
"the subquery matches nothing, so every second column is NULL" want
(q db uncorrelated);
Alcotest.check rows "the correlated form returns the same rows" want
(q db correlated);
Alcotest.(check int)
"the uncorrelated subquery is folded once" 38 (scanned db uncorrelated);
Alcotest.(check int)
"the correlated subquery is re-evaluated per outer row" 299
(scanned db correlated)
(* A bare [IN (SELECT ...)] is a membership: the uncorrelated subquery is folded
into the set the outer rows are tested against, so the query costs the outer
pass and one pass over [u] -- 9 + 29, as the folded scalar above -- and no
per-row re-scan of [u]. *)
(* sqlite3 codes a correlated subquery once and reads the outer columns from
their registers at each run. A NOT EXISTS stays a subquery, where sqlite3
joins an EXISTS (select.c, existsToJoin). Ours runs one select at each of the ten rows of
[t], the outer column bound as a parameter, so the handle compiles one plan
for the ten runs, beside the outer select's: two. A subquery rewritten with
each row's value as a literal is a new select at each row, and eleven. *)
let test_correlated_subquery_one_plan () =
let db = two_tables () in
let plans () = (Sqlite.Private.handle db).Sqlite.Private.Handle.planned in
let before = plans () in
Alcotest.check rows "the rows of t whose quadruple u does not hold"
(ints [ 8; 9; 10 ])
(q db "SELECT a FROM t WHERE NOT EXISTS (SELECT 1 FROM u WHERE b = a * 4)");
Alcotest.(check int) "one plan for the ten runs" 2 (plans () - before)
(* Beyond the compiled plan, sqlite3 codes a correlated subquery's name
resolution and its access path once. Ours keeps them for the one bound
select every outer row runs: its resolved core and the scan it planned at
the first run (an index seek on the outer value here, the plan of one base
table). A subquery that resolves and plans again at every row keeps
nothing, and one keyed by the row's values keeps ten. *)
let test_correlated_subquery_keeps_its_plan () =
let db = two_tables () in
Raw.exec db "CREATE INDEX ub ON u (b)" ~params:[];
Alcotest.check rows "the rows of t whose quadruple u does not hold"
(ints [ 8; 9; 10 ])
(q db "SELECT a FROM t WHERE NOT EXISTS (SELECT 1 FROM u WHERE b = a * 4)");
let kept =
Sqlite.Private.Handle.Plans.fold
(fun _ p acc -> p :: acc)
(Sqlite.Private.handle db).Sqlite.Private.Handle.subqueries []
in
Alcotest.(check int) "one kept subquery" 1 (List.length kept);
List.iter
(fun (p : Sqlite.Private.Handle.prepared) ->
Alcotest.(check bool)
"resolved once" true
(match p.core with Plain _ -> true | Nested | Unresolved -> false);
Alcotest.(check bool)
"its scan planned once" true
(match p.scan with Planned _ -> true | Unplanned | Per_run -> false))
kept
(* The same on the engine's path. A window over groups runs on the engine,
which hands each correlated subquery to the store with the outer row: the
store binds the row as parameters and plans the one select it runs at every
row, once. A subquery the engine runs itself, rewritten with each row's
values, is planned by the store not at all (0); one planned at every row is
planned seven times. *)
let test_engine_correlated_subquery_one_plan () =
let db = two_tables () in
let planned () = (Sqlite.Private.handle db).Sqlite.Private.Handle.planned in
let before = planned () in
let got =
q db
"SELECT a, sum(a) OVER () FROM t GROUP BY a HAVING a IN (SELECT b / 4 \
FROM u WHERE b = a * 4)"
in
Alcotest.check rows "the groups whose quadruple u holds"
(List.map
(fun a -> [ Int (Int64.of_int a); Int 28L ])
[ 1; 2; 3; 4; 5; 6; 7 ])
(List.sort compare got);
Alcotest.(check int) "one plan for the subquery's runs" 1 (planned () - before)
(* The handle keeps the plan of a select that may run again as it is: one
reading a bound value, which its caller runs again with another, and a step
of a trigger program, run for each row it fires on. Each is planned once
for its runs. A statement of literals alone meets its like only where its
text runs again, and a text is prepared again at each run, as sqlite3_exec
prepares it: the select an UPDATE finds its rows by keeps nothing then. A
handle that kept it would hold one plan more after the literal UPDATE; one
that kept none would plan the bound UPDATE and the trigger step at every
run. *)
let test_literal_statement_keeps_no_plan () =
let db = Sqlite.in_memory () in
List.iter
(fun sql -> Raw.exec db sql ~params:[])
[
"CREATE TABLE s (k INTEGER PRIMARY KEY, n INTEGER)";
"INSERT INTO s VALUES (1, 0), (2, 0), (3, 0)";
"CREATE TABLE lg (x)";
"CREATE TRIGGER tr AFTER INSERT ON lg BEGIN UPDATE s SET n = n + 1 WHERE \
n >= 0; END";
];
let h = Sqlite.Private.handle db in
let kept () = Sqlite.Private.Handle.Plans.length h.plan_cache in
let planned () = h.Sqlite.Private.Handle.planned in
let before = kept () in
Raw.exec db "UPDATE s SET n = n + 1 WHERE n < 5" ~params:[];
Alcotest.(check int) "a literal UPDATE keeps no plan" 0 (kept () - before);
let bound () =
let before = planned () in
Raw.exec db "UPDATE s SET n = n + 1 WHERE n < ?" ~params:[ Int 10L ];
planned () - before
in
Alcotest.(check int) "a bound UPDATE is planned at its first run" 1 (bound ());
Alcotest.(check int) "and not at its second" 0 (bound ());
let before = planned () in
Raw.exec db "INSERT INTO lg VALUES (1), (2), (3)" ~params:[];
Alcotest.(check int)
"a trigger step is planned once for three rows" 1
(planned () - before);
Alcotest.check rows "every UPDATE ran"
[ [ Int 1L; Int 6L ]; [ Int 2L; Int 6L ]; [ Int 3L; Int 6L ] ]
(q db "SELECT k, n FROM s ORDER BY k")
let test_in_membership_over_folded_set () =
let db = two_tables () in
Alcotest.check rows "only the values u holds are kept"
(ints [ 2; 4; 6; 8; 10 ])
(q db
"SELECT a FROM t WHERE a IN (SELECT b FROM u WHERE b % 2 = 0) ORDER BY a");
Alcotest.(check int)
"the membership adds no per-row scan of the inner table" 38
(scanned db "SELECT a FROM t WHERE a IN (SELECT b FROM u)")
(* A recursive CTE is materialised to a fixpoint: the base arm seeds it, then
the recursive arm is re-run against the rows so far until it adds none. *)
let test_recursive_cte_fixpoint () =
let db = in_memory () in
Alcotest.check rows "1..5 counted up to the WHERE bound"
(ints [ 1; 2; 3; 4; 5 ])
(q db
"WITH RECURSIVE c(n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM c WHERE n \
< 5) SELECT n FROM c")
(* A compound select folds its arms through the set operator and applies the
outer ORDER BY over the result: UNION dedups, UNION ALL keeps duplicates,
EXCEPT is set difference and INTERSECT set intersection. *)
let test_compound_set_operators () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a INTEGER)";
Table.create_table db ~sql:"CREATE TABLE u (b INTEGER)";
List.iter
(fun a -> ignore (Table.insert db ~table:"t" [ Int a ]))
[ 1L; 2L; 3L ];
List.iter
(fun b -> ignore (Table.insert db ~table:"u" [ Int b ]))
[ 2L; 3L; 4L ];
Alcotest.check rows "UNION dedups across arms, ORDER BY sorts the union"
(ints [ 1; 2; 3; 4 ])
(q db "SELECT a FROM t UNION SELECT b FROM u ORDER BY 1");
Alcotest.check rows "UNION ALL keeps every arm's rows"
(ints [ 1; 2; 2; 3; 3; 4 ])
(q db "SELECT a FROM t UNION ALL SELECT b FROM u ORDER BY 1");
Alcotest.check rows "EXCEPT is set difference" (ints [ 1 ])
(q db "SELECT a FROM t EXCEPT SELECT b FROM u ORDER BY 1");
Alcotest.check rows "INTERSECT is set intersection"
(ints [ 2; 3 ])
(q db "SELECT a FROM t INTERSECT SELECT b FROM u ORDER BY 1")
(* A shape the VM cannot compile falls back to the engine with the same answer:
a FROM-subquery carrying its own ORDER BY and LIMIT is materialised through
the engine, and the outer select reads its rows -- identical to the same
query without the wrapper. *)
let test_vm_declines_shape_engine_answers () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a INTEGER)";
for i = 1 to 5 do
ignore (Table.insert db ~table:"t" [ Int (Int64.of_int i) ])
done;
Alcotest.check rows "a derived table with ORDER BY/LIMIT still answers"
(ints [ 1; 2 ])
(q db "SELECT x FROM (SELECT a AS x FROM t ORDER BY a LIMIT 2) ORDER BY x")
(* Grouped rows reach a window's sort in group order, and the sort has to say
what it does with two of them its ORDER BY compares equal. sqlite3's answer
follows the direction written: under ASC the tied rows keep the order they
arrived in, under DESC they come out in the reverse of it. Rows straight off
a scan keep theirs whichever way the key runs, so the reversal belongs to the
grouped sort and not to DESC on its own.
Which of the two a select gets is this module's dispatch and not a decision
the window pass makes for itself. A select that both aggregates and names a
window is {!Sql.Private.Query.window_over_groups}, which neither [aggregate_compilable]
nor [window_compilable] claims, so it is handed to {!Sql.Private.Engine.run_select}
and windows over the rows the GROUP BY produced. {!Sql.Private.Window.scan} is called
in exactly one place here, and only under [window_compilable] -- which every
GROUP BY, HAVING or aggregate select fails -- so the rows reaching it are
always scan rows and its sort always keeps a tied run as it stands. The arms
below are that split, read as row order: fold the two together, either way
round, and one of them answers wrongly.
The sqlite3 CLI (Apple build, 3.54.0) and a stock 3.53.4 build agree line for
line, over [CREATE TABLE t (a INTEGER)] holding (1),(1),(2),(3) -- and the
same plus (4) -- with rn standing for
"row_number() OVER (ORDER BY count(*)
)":
four rows, "ORDER BY rn", DESC 1|2 3|1 2|1
four rows, "ORDER BY rn", ASC 2|1 3|1 1|2
five rows, "ORDER BY rn", DESC 1|2 4|1 3|1 2|1
five rows, "ORDER BY rn", ASC 2|1 3|1 4|1 1|2
A third tied group is what tells a reversal from a swap: groups 2, 3 and 4
all count 1, and DESC numbers them 4, 3, 2 -- the whole tied run turned
round, not its ends exchanged.
"SELECT a, row_number() OVER (ORDER BY 0 DESC) FROM t" (five rows,
ungrouped) 1|1 1|2 2|3 3|4 4|5 *)
let test_a_grouped_window_sort_turns_a_tied_run_round () =
let seeded values =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a INTEGER)";
List.iter
(fun a -> ignore (Table.insert db ~table:"t" [ Int (Int64.of_int a) ]))
values;
db
in
let four = seeded [ 1; 1; 2; 3 ] in
let five = seeded [ 1; 1; 2; 3; 4 ] in
let pairs =
List.map (fun (a, b) -> [ Int (Int64.of_int a); Int (Int64.of_int b) ])
in
let ranked ?(from = "t") dir =
Fmt.str
"SELECT a, count(*) FROM %s GROUP BY a ORDER BY row_number() OVER (ORDER \
BY count(*) %s)"
from dir
in
Alcotest.check rows "DESC turns the tied run round"
(pairs [ (1, 2); (3, 1); (2, 1) ])
(q four (ranked "DESC"));
Alcotest.check rows "ASC leaves it as the grouping put it"
(pairs [ (2, 1); (3, 1); (1, 2) ])
(q four (ranked "ASC"));
Alcotest.check rows "a third tied group is turned round with them"
(pairs [ (1, 2); (4, 1); (3, 1); (2, 1) ])
(q five (ranked "DESC"));
Alcotest.check rows "and left alone with them"
(pairs [ (2, 1); (3, 1); (4, 1); (1, 2) ])
(q five (ranked "ASC"));
(* A leading WITH is the other door into the window path, and it reaches the
same sort: the CTE is materialised and the grouped select over it is
dispatched exactly as the CTE-free one is. *)
Alcotest.check rows "a WITH in front of it reaches the same sort"
(pairs [ (1, 2); (4, 1); (3, 1); (2, 1) ])
(q five ("WITH c AS (SELECT a FROM t) " ^ ranked ~from:"c" "DESC"));
(* the same DESC key over an ungrouped scan keeps the rows as they came, which
is what confines the reversal to the grouped sort *)
Alcotest.check rows "an ungrouped scan under a DESC key is not turned round"
(pairs [ (1, 1); (1, 2); (2, 3); (3, 4); (4, 5) ])
(q five "SELECT a, row_number() OVER (ORDER BY 0 DESC) FROM t")
(* EXPLAIN prints the access path the run then takes, over the same layout the
executed plan reads -- a plain rowid table's cursor carries a hidden rowid
slot the layout appends, so the two cannot drift on what a column position
means. A bare select scans the table; an equality on the INTEGER PRIMARY KEY
seeks it and scans nothing. *)
let test_explain_is_the_plan_that_runs () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (id INTEGER PRIMARY KEY, v TEXT)";
for i = 1 to 20 do
ignore
(Raw.exec db "INSERT INTO t (v) VALUES (?)"
~params:[ Fmt.kstr (fun s -> Text s) "v%d" i ])
done;
Alcotest.(check string)
"a bare select scans the table" "SCAN t"
(Raw.explain db "SELECT v FROM t");
Alcotest.(check int)
"an INTEGER PRIMARY KEY equality seeks, scanning nothing" 0
(scanned db "SELECT v FROM t WHERE id = 7")
(* Six rows holding a duplicate and out of order, so DISTINCT and ORDER BY each
have something to do, beside three to join and to compound against. *)
let unordered_tables () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a INTEGER, s TEXT)";
Table.create_table db ~sql:"CREATE TABLE u (b INTEGER)";
List.iter
(fun (a, s) -> ignore (Table.insert db ~table:"t" [ Int a; Text s ]))
[ (3L, "c"); (1L, "a"); (3L, "c"); (2L, "b"); (1L, "a"); (5L, "e") ];
List.iter
(fun b -> ignore (Table.insert db ~table:"u" [ Int b ]))
[ 1L; 3L; 7L ];
db
(* What {!Raw.iter} handed over, in the order it handed it over. *)
let iterated db sql =
let out = ref [] in
Raw.iter db sql ~params:[] ~f:(fun r -> out := r :: !out);
List.rev !out
(* Every select shape, asked both ways. Answering a row at a time is a change of
how a row is reached and never of which rows there are or what order they
come in, so each shape is checked against a written-out answer and the list
door is asked for the same one.
The shapes are the two arms the door has. A scan, a filtered scan and a
bounded one stream: nothing in them has to see a later row before it can
answer an earlier one. The rest cannot and materialise inside the door --
ORDER BY has no first row until it has seen the last, DISTINCT has to
remember what it answered, an OFFSET counts rows it must not answer, GROUP BY
folds a whole scan into its groups, a compound folds its arms through a set
operator, and a select the VM declines is answered by the engine as a list. A
caller sees no difference, which is what this pins. *)
let test_iter_answers_what_query_answers () =
let db = unordered_tables () in
let shapes =
[
("a plain scan", "SELECT a FROM t", ints [ 3; 1; 3; 2; 1; 5 ]);
("a filtered scan", "SELECT a FROM t WHERE a > 1", ints [ 3; 3; 2; 5 ]);
("LIMIT 3", "SELECT a FROM t LIMIT 3", ints [ 3; 1; 3 ]);
( "LIMIT past the last row",
"SELECT a FROM t LIMIT 99",
ints [ 3; 1; 3; 2; 1; 5 ] );
("LIMIT 0", "SELECT a FROM t LIMIT 0", []);
("ORDER BY", "SELECT a FROM t ORDER BY a", ints [ 1; 1; 2; 3; 3; 5 ]);
("DISTINCT", "SELECT DISTINCT a FROM t ORDER BY a", ints [ 1; 2; 3; 5 ]);
("OFFSET", "SELECT a FROM t ORDER BY a LIMIT 2 OFFSET 3", ints [ 3; 3 ]);
( "GROUP BY",
"SELECT a, count(*) FROM t GROUP BY a ORDER BY a",
[
[ Int 1L; Int 2L ];
[ Int 2L; Int 1L ];
[ Int 3L; Int 2L ];
[ Int 5L; Int 1L ];
] );
( "a join",
"SELECT a FROM t JOIN u ON u.b = t.a ORDER BY a",
ints [ 1; 1; 3; 3 ] );
( "a compound",
"SELECT a FROM t UNION SELECT b FROM u ORDER BY a",
ints [ 1; 2; 3; 5; 7 ] );
(* The VM declines a derived table carrying its own ORDER BY / LIMIT, and
the engine answers it: a shape whose rows reach [f] as a list. *)
( "a shape the VM declines",
"SELECT x FROM (SELECT a AS x FROM t ORDER BY a LIMIT 2) ORDER BY x",
ints [ 1; 1 ] );
]
in
List.iter
(fun (name, sql, want) ->
Alcotest.check rows (name ^ ", row at a time") want (iterated db sql);
Alcotest.check rows (name ^ ", as a list") want (q db sql))
shapes
(* {!Raw.iter_rows} answers what {!Raw.iter} answers, read through {!Raw.Row}:
a streamed shape hands over the VM's registers, a buffered one and one the
VM declines hand over a row of values, and a caller sees the same rows in the
same order either way. *)
let test_iter_rows_answers_what_iter_answers () =
let db = unordered_tables () in
List.iter
(fun sql ->
let out = ref [] in
Raw.iter_rows db sql ~params:[] ~f:(fun r ->
out := List.init (Raw.Row.length r) (Raw.Row.value r) :: !out);
Alcotest.check rows sql (iterated db sql) (List.rev !out))
[
"SELECT a, s FROM t";
"SELECT a FROM t WHERE a > 1 LIMIT 3";
"SELECT DISTINCT a, s FROM t ORDER BY a";
"SELECT a, count(*) FROM t GROUP BY a";
"SELECT a FROM t UNION SELECT b FROM u";
"SELECT x FROM (SELECT a AS x FROM t ORDER BY a LIMIT 2) ORDER BY x";
"PRAGMA table_info(t)";
]
(* A row stands on the scan's registers, which the next row overwrites, so it is
readable only inside the call of [f] that receives it, as a statement's
columns are until its next [sqlite3_step]. Kept past that call, it is refused,
whichever way the rows reached [f]. *)
let test_a_row_kept_past_f_is_refused () =
let db = unordered_tables () in
List.iter
(fun sql ->
let kept = ref None in
Raw.iter_rows db sql ~params:[] ~f:(fun r ->
Alcotest.(check int) "readable inside f" 1 (Raw.Row.length r);
kept := Some r);
let r = Option.get !kept in
match Raw.Row.int64 r 0 with
| _ -> Alcotest.failf "%s: a row read after its call" sql
| exception Invalid_argument _ -> ())
[ "SELECT a FROM t"; "SELECT a FROM t ORDER BY a" ]
(* sqlite3_column_type, _int64, _double, _text and _bytes over each storage
class (c3ref/column_blob.html, and the conversion table there): NULL reads
as 0, 0.0 and ""; a real truncates towards zero and is held to the int64
range; text reads as its leading number; a number reads as its text. *)
let test_row_reads_as_sqlite3_column () =
let db = in_memory () in
let row sql f =
let n = ref 0 in
Raw.iter_rows db sql ~params:[] ~f:(fun r ->
incr n;
f r);
Alcotest.(check int) (sql ^ ": one row") 1 !n
in
row
"SELECT NULL, 42, 2.5, '12abc', x'3132', 9.9e99, -9.9e99, '1.5e1x', \
9223372036854775807"
@@ fun r ->
let kinds = List.init (Raw.Row.length r) (Raw.Row.kind r) in
Alcotest.(check bool)
"kinds" true
(kinds
= [ `Null; `Integer; `Real; `Text; `Blob; `Real; `Real; `Text; `Integer ]);
Alcotest.(check (list int64))
"int64"
[ 0L; 42L; 2L; 12L; 12L; Int64.max_int; Int64.min_int; 1L ]
(List.init 8 (Raw.Row.int64 r));
Alcotest.(check (list (float 0.)))
"float"
[ 0.; 42.; 2.5; 12.; 12.; 9.9e99; -9.9e99; 15. ]
(List.init 8 (Raw.Row.float r));
Alcotest.(check (list string))
"text"
[ ""; "42"; "2.5"; "12abc"; "12" ]
(List.init 5 (Raw.Row.text r));
Alcotest.(check (list int))
"bytes" [ 0; 2; 3; 5; 2 ]
(List.init 5 (Raw.Row.bytes r));
Alcotest.(check int) "int" 42 (Raw.Row.int r 1);
Alcotest.check_raises "int past the native range"
(Invalid_argument
"Sql.Row.int: 9223372036854775807 is outside the native range")
(fun () -> ignore (Raw.Row.int r 8 : int));
let buf = Bytes.make 5 '.' in
Raw.Row.blit r 3 ~off:1 buf ~pos:1 ~len:3;
Alcotest.(check string) "blit" ".2ab." (Bytes.to_string buf);
Alcotest.check_raises "a column past the row"
(Invalid_argument "Sql.Row: column 9 of a row of 9") (fun () ->
ignore (Raw.Row.value r 9 : value))
(* The typed door answers the rows its list form answers, decoded. *)
let test_typed_iter_answers_what_run_answers () =
let db = unordered_tables () in
let a = Sql.Col.v "a" Sql.int Fun.id in
let t = Sql.Table.(map "t" Fun.id |> col a |> seal) in
let query =
Sql.Query.(
from t @@ fun r ->
where Expr.(get r a > int 1L) @@ (select Fun.id |> col (get r a) |> seal))
in
let out = ref [] in
iter db query ~f:(fun r -> out := r :: !out);
Alcotest.(check (list int64))
"the typed rows, in scan order" [ 3L; 3L; 2L; 5L ] (List.rev !out);
Alcotest.(check (list int64))
"which is what run answers" (run db query) (List.rev !out)
exception Stop_scan
(* Raising out of [f] is how a caller leaves a scan it has seen enough of. The
exception is the caller's own -- neither swallowed nor wrapped -- what [f]
took before it raised is what it was given, and the scan ends there instead
of reading on.
Read off {!Stats.rows_scanned}, which counts a pass over [n] rows as [n - 1]
steps (sqlite3's FULLSCAN_STEP, which does not count the rewind that begins
the pass): a whole pass over these six rows is 5, and a caller that stops on
the second row stands on two and steps once. The read is given back on the
way out, so the handle answers the next question as if the scan had ended of
its own accord. *)
let test_raising_out_of_f_ends_the_scan () =
let db = unordered_tables () in
let seen = ref [] in
let before = Stats.rows_scanned db in
Alcotest.check_raises "the caller's own exception" Stop_scan (fun () ->
Raw.iter db "SELECT a FROM t" ~params:[] ~f:(fun r ->
seen := r :: !seen;
if List.length !seen = 2 then raise Stop_scan));
Alcotest.check rows "the rows taken before the raise"
(ints [ 3; 1 ])
(List.rev !seen);
Alcotest.(check int)
"and the scan stood where it raised" 1
(Stats.rows_scanned db - before);
Alcotest.check rows "the handle answers after the raise" [ [ Int 6L ] ]
(q db "SELECT count(*) FROM t")
(* A script has an answer per statement where this door has one, so it is not a
question this door takes: {!Raw.run} is the door for one. Refused as it is
read rather than half run, so no row of the first statement has been handed
over when the caller learns the second one was there. *)
let test_iter_takes_one_statement () =
let db = unordered_tables () in
let calls = ref 0 in
Alcotest.check_raises "a two-statement script"
(Sqlite.Error (Prepare "query: expected a single SELECT statement"))
(fun () ->
Raw.iter db "SELECT a FROM t; SELECT b FROM u" ~params:[] ~f:(fun _ ->
incr calls));
Alcotest.(check int) "no row was handed over" 0 !calls;
Alcotest.check_raises "a statement that is not a query"
(Sqlite.Error (Prepare "query: statement is not a SELECT")) (fun () ->
Raw.iter db "INSERT INTO u VALUES (9)" ~params:[] ~f:(fun _ -> incr calls));
Alcotest.(check int) "and none for the write either" 0 !calls;
Alcotest.check rows "which is not written" [ [ Int 3L ] ]
(q db "SELECT count(*) FROM u")
(* A select the VM declines is answered by the engine, and the door has to
settle which of the two answered before a row reaches [f]: the VM says it
cannot compile a shape while compiling it, which is before it has scanned
anything. Were that settled any later, [f] would see the rows the VM produced
and then the whole answer over again from the engine.
Counting the calls is what says it is not: a prefix answered twice is more
calls than the answer has rows. Both arms are counted, so the count means the
same thing either way. *)
let test_a_declined_shape_answers_once () =
let db = unordered_tables () in
let calls sql =
let n = ref 0 in
Raw.iter db sql ~params:[] ~f:(fun _ -> incr n);
!n
in
Alcotest.(check int)
"the VM answers a plain scan once" 6 (calls "SELECT a FROM t");
Alcotest.(check int)
"and the engine answers a declined shape once" 2
(calls "SELECT x FROM (SELECT a AS x FROM t ORDER BY a LIMIT 2) ORDER BY x")
(* Words that survive into the major heap while [f] runs -- what the call holds,
as opposed to what it allocates and drops. The minor heap is shrunk for the
measurement so anything the call keeps is promoted rather than hidden: a row
of a few words fits in the default 256k-word nursery whole, and a buffer of
them would read as costing nothing at all. *)
let retained_words f =
let major () = (Gc.quick_stat ()).Gc.major_words in
let gc = Gc.get () in
Gc.set { gc with Gc.minor_heap_size = 8192 };
Gc.full_major ();
let before = major () in
ignore (Sys.opaque_identity (f ()));
let words = major () -. before in
Gc.set gc;
words
(* A wide scan costs a row through {!Raw.iter} and its whole answer through
{!Raw.query}. Both read the same rows off the same warmed handle, so what
separates them is the list one of them builds.
The budget either side counts words a row, and the row says what they are. A
row of one TEXT cell is held as the answer list's cons (3 words), the row
list's cons (3) and the [Text] box (2): 8 words before a byte of the string
itself, which for these is 9 more. So a door keeping the answer cannot retain
fewer than 8 words a row, and one keeping a row at a time retains none --
budgeted at 1 word a row, an order of magnitude under the cheapest buffer and
well above what a run holding nothing promotes.
The handle is read once before either measurement so the pager already holds
the pages both passes read; without that the first pass is charged for the
cache it filled, which is neither door's answer. *)
let test_a_wide_scan_retains_no_rows () =
let n = 20_000 in
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE w (v TEXT)";
let cell = String.make 64 'x' in
for _ = 1 to n do
ignore (Table.insert db ~table:"w" [ Text cell ])
done;
let sql = "SELECT v FROM w" in
ignore (q db sql : value list list);
let w_iter =
retained_words (fun () -> Raw.iter db sql ~params:[] ~f:(fun _ -> ()))
in
let w_query = retained_words (fun () -> q db sql) in
let per w = w /. float_of_int n in
Alcotest.(check bool)
(Fmt.str "a streamed scan retains none of its %d rows (%.2fw/row, budget 1)"
n (per w_iter))
true
(per w_iter < 1.0);
Alcotest.(check bool)
(Fmt.str "where the list holds every one of them (%.2fw/row, floor 8)"
(per w_query))
true
(per w_query >= 8.0)
(* Compiling a SELECT is a per-query act, so two handles compiling at the same
instant in two OCaml 5 domains have nothing to share. Each domain below
builds its own in-memory database and asks its own question of it -- no file,
no shared handle, nothing between them but the library. Each question carries
a subquery, which is the one shape a compiled plan is never cached for
({!Sqlite.Private.Handle.plan_entry}), so every pass compiles afresh; and the
questions differ in the facts a compile reads off the schema, so a domain
answering another one's question is wrong by a count it can check. *)
let questions =
[|
("SELECT v FROM nums WHERE v IN (SELECT v FROM evens)", 15);
( "SELECT v FROM nums WHERE v IN (SELECT v FROM threes) AND v IN (SELECT v \
FROM evens)",
5 );
( "SELECT v FROM nums WHERE EXISTS (SELECT 1 FROM threes WHERE threes.v = \
nums.v)",
10 );
("SELECT v FROM names WHERE v IN (SELECT v FROM evens)", 15);
|]
(* [nums] holds 1..30, [evens] and [threes] their multiples, and [names] the
same numbers as text -- so the last question is answered through the column
affinity a comparison reads off the schema, which is one more per-compile
fact than the others need. *)
let numbers () =
let db = in_memory () in
List.iter
(fun (t, ty) ->
Table.create_table db ~sql:(Fmt.str "CREATE TABLE %s (v %s)" t ty))
[
("nums", "INTEGER");
("evens", "INTEGER");
("threes", "INTEGER");
("names", "TEXT");
];
for i = 1 to 30 do
let v = Int (Int64.of_int i) in
ignore (Table.insert db ~table:"nums" [ v ] : int64 option);
if i mod 2 = 0 then
ignore (Table.insert db ~table:"evens" [ v ] : int64 option);
if i mod 3 = 0 then
ignore (Table.insert db ~table:"threes" [ v ] : int64 option);
ignore
(Table.insert db ~table:"names" [ Text (string_of_int i) ] : int64 option)
done;
db
let row_count db sql =
List.fold_left (fun n _ -> n + 1) 0 (Raw.query db sql ~params:[])
let test_domains_compile_independently () =
let passes = 2000 in
let ask i =
let sql, expect = questions.(i) in
let db = numbers () in
(* The answer on its own, before a domain is spawned: an expectation that is
simply wrong fails here rather than looking like a race below. *)
let alone = row_count db sql in
if alone <> expect then
Alcotest.failf "question %d answers %d, not %d, on its own" i alone expect;
fun () ->
let wrong = ref 0 and raised = ref 0 and first = ref "" in
for _ = 1 to passes do
match row_count db sql with
| n ->
if n <> expect then begin
incr wrong;
if !first = "" then first := Fmt.str "%d rows, not %d" n expect
end
| exception (Sqlite.Error _ as e) ->
incr raised;
if !first = "" then first := Printexc.to_string e
done;
(!wrong, !raised, !first)
in
let workers = Array.init (Array.length questions) ask in
let results = Array.map Domain.join (Array.map Domain.spawn workers) in
Array.iteri
(fun i (wrong, raised, first) ->
if wrong > 0 || raised > 0 then
Alcotest.failf
"question %d: %d of %d passes answered wrongly and %d raised; first: \
%s"
i wrong passes raised first)
results
let test_count_rowid_ranges () =
let db = in_memory () in
Raw.exec db "CREATE TABLE t (id INTEGER PRIMARY KEY, value INTEGER)"
~params:[];
List.iter
(fun id -> Raw.exec db "INSERT INTO t VALUES (?, NULL)" ~params:[ Int id ])
[ Int64.min_int; -3L; 0L; 2L; 9L; Int64.max_int ];
List.iter
(fun (sql, expected) ->
Alcotest.check rows sql (ints [ expected ]) (q db sql))
[
("SELECT count(*) FROM t", 6);
("SELECT count(*) FROM t WHERE id > 0", 3);
("SELECT count(*) FROM t WHERE id >= 0 AND id < 9", 2);
("SELECT count(*) FROM t WHERE id <= -3", 2);
("SELECT count(*) FROM t WHERE id > 9 AND id < 2", 0);
("SELECT count(value) FROM t WHERE id > 0", 0);
("SELECT count(*) FROM t WHERE id > 0 OR id < 0", 5);
];
Alcotest.check rows "bound parameters" (ints [ 2 ])
(Raw.query db "SELECT count(*) FROM t WHERE id > ? AND id <= ?"
~params:[ Int 0L; Int 9L ]);
Alcotest.check rows "LIMIT zero suppresses the aggregate" []
(q db "SELECT count(*) FROM t LIMIT 0");
Alcotest.check rows "OFFSET skips the aggregate row" []
(q db "SELECT count(*) FROM t LIMIT 1 OFFSET 1")
let count_range_words n =
let db = in_memory () in
Raw.exec db "CREATE TABLE t (id INTEGER PRIMARY KEY, value INTEGER)"
~params:[];
with_transaction db (fun () ->
for i = 1 to n do
ignore (Table.insert db ~table:"t" [ Int (Int64.of_int i); Int 1L ])
done);
let sql = "SELECT count(*) FROM t WHERE id > 1" in
ignore (q db sql);
Gc.full_major ();
let before = Gc.minor_words () in
let got = q db sql in
let words = Gc.minor_words () -. before in
Alcotest.check rows "counted range" (ints [ n - 1 ]) got;
words
let test_count_range_allocation () =
let small = count_range_words 1_000 in
let large = count_range_words 100_000 in
Alcotest.(check bool)
(Fmt.str "COUNT allocation: 1000 rows=%.0fw, 100000 rows=%.0fw" small large)
true
(large <= small *. 2.)
(* sqlite3 codes a recursive CTE's step once and runs it per row of its queue
(select.c, generateWithRecursiveQuery). Each round of [WITH RECURSIVE] here
reads one row, so what a round allocates is the step's cost per row. The
step run once as a query of its own pays to parse, check, compile and run
it; a round that checks and compiles the step again allocates a fifth of
that (1861 words against 9220), one that only runs it under a thirtieth. *)
let words f =
Gc.full_major ();
let before = Gc.minor_words () in
ignore (Sys.opaque_identity (f ()));
Gc.minor_words () -. before
let recursive_words db n =
words (fun () ->
Alcotest.check rows "counted" (ints [ n ])
(q db
(Fmt.str
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k \
WHERE i < %d) SELECT count(*) FROM k"
n)))
let test_recursive_step_compiles_once () =
let db = in_memory () in
let round =
(recursive_words db 2_000 -. recursive_words db 1_000) /. 1_000.
in
let once =
words (fun () -> q db "SELECT i + 1 FROM (SELECT 1 AS i) WHERE i < 2000")
in
Alcotest.(check bool)
(Fmt.str "a round allocates %.0fw, the step run once %.0fw" round once)
true
(10. *. round < once)
(* A recursive CTE is a co-routine of the select that reads it: each row of
its queue is handed out as it is produced, so an outer LIMIT stops even a
recursion with no bound of its own, as in sqlite3 (lang_with.html, "the
LIMIT ... on the outer query"; select.c, generateWithRecursiveQuery). The
rows come in queue order -- each round's rows in the order the round
before them produced them -- under the CTE's own LIMIT and OFFSET first and
the outer query's after. Every answer is sqlite3 3.54.1's. *)
let test_recursive_cte_streams_to_its_reader () =
let db = in_memory () in
let text = function
| Int i -> Int64.to_string i
| Text s -> s
| Null -> "-"
| v -> Fmt.str "%a" Value.pp v
in
let answer sql =
List.map (fun row -> String.concat "|" (List.map text row)) (q db sql)
in
let check what sql expected =
Alcotest.(check (list string)) what expected (answer sql)
in
check "an outer LIMIT stops an unbounded recursion"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k) SELECT i \
FROM k LIMIT 5"
[ "1"; "2"; "3"; "4"; "5" ];
check "a WHERE and a LIMIT over an unbounded recursion"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k) SELECT i \
FROM k WHERE i % 1000 = 0 LIMIT 2"
[ "1000"; "2000" ];
check "the queue's order, each round after the one before"
"WITH RECURSIVE t(n, d) AS (SELECT 1, 0 UNION ALL SELECT n * 2 + x, d + 1 \
FROM t, (SELECT 0 AS x UNION ALL SELECT 1) WHERE d < 3) SELECT \
group_concat(n) FROM (SELECT n FROM t LIMIT 10)"
[ "1,2,3,4,5,6,7,8,9,10" ];
check "the CTE's LIMIT and OFFSET, then the outer ones"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k LIMIT 8 \
OFFSET 2) SELECT i FROM k LIMIT 3 OFFSET 1"
[ "4"; "5"; "6" ];
check "a UNION drops a row the queue has seen"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION SELECT i % 5 + 1 FROM k) SELECT \
group_concat(i) FROM k"
[ "1,2,3,4,5" ];
check "a CTE read twice, by a join"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k WHERE i < \
4) SELECT x.i, y.i FROM k AS x, k AS y WHERE x.i + y.i = 5"
[ "1|4"; "2|3"; "3|2"; "4|1" ];
check "a CTE read in a subquery and by the outer select"
"WITH RECURSIVE k(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM k WHERE i < \
5) SELECT i, (SELECT count(*) FROM k) FROM k LIMIT 2"
[ "1|5"; "2|5" ]
(* A scan reads the columns a query names, not the row
[n] rows of [width] text columns, built by one INSERT ... SELECT so the
setup costs no row-at-a-time inserts. *)
let wide_table ~width n =
let db = in_memory () in
let cols = List.init width (Fmt.str "c%d") in
Raw.exec db
(Fmt.str "CREATE TABLE w (%s)"
(String.concat ", " (List.map (fun c -> c ^ " TEXT") cols)))
~params:[];
Raw.exec db
(Fmt.str
"INSERT INTO w WITH RECURSIVE r(i) AS (VALUES (1) UNION ALL SELECT i + \
1 FROM r WHERE i < %d) SELECT %s FROM r"
n
(String.concat ", "
(List.mapi
(fun j _ -> Fmt.str "'v%d-' || i || '-xxxxxxxxxxxx'" j)
cols)))
~params:[];
db
(* The words a query allocates, and the words that outlive a minor
collection: a value held past the row that read it is promoted, one decoded
and dropped is not. *)
let scan_words db sql =
ignore (q db sql);
Gc.full_major ();
let minor = Gc.minor_words ()
and promoted = (Gc.quick_stat ()).promoted_words in
let got = q db sql in
( got,
Gc.minor_words () -. minor,
(Gc.quick_stat ()).promoted_words -. promoted )
(* Reading the first column of a row and reading the last cost the same, and a
row 160 columns wide costs what a row 4 wide does: the record's header is
read and the one slot asked for decoded. Decoding the whole row would cost
at least a value per column, 160 words a row where this allows 100. On
house's 158-column [communes] table, counting its first, 79th or 158th
column once took 6.1 to 6.5 s against the reference's 0.02 to 0.05 s. *)
let test_a_scan_decodes_the_columns_it_reads () =
let n = 4_000 in
let per_row width sql =
let db = wide_table ~width n in
let got, words, _ = scan_words db sql in
Alcotest.check rows (Fmt.str "%s, %d columns" sql width) (ints [ n ]) got;
words /. float_of_int n
in
let first = per_row 160 "SELECT count(c0) FROM w" in
let last = per_row 160 "SELECT count(c159) FROM w" in
let narrow = per_row 4 "SELECT count(c0) FROM w" in
List.iter
(fun (what, w) ->
if w > 100. then
Alcotest.failf "%s: %.0f words a row, a decode of the whole row" what w)
[
("the first of 160", first); ("the last of 160", last); ("1 of 4", narrow);
]
(* A scan holds what it keeps, not what it reads: a predicate no row passes
promotes nothing out of the minor heap however many rows it reads. Holding
each row read until the scan ends -- 683 MB for no match over 1.79 M rows of
house's [elections] -- would promote a value per column of every row: 16 000
rows of 40 columns are 640 000 values, past what the minor heap can hide,
and returning two columns of each promotes 330 000 words here. *)
let test_a_scan_holds_what_it_keeps () =
let n = 16_000 in
let db = wide_table ~width:40 n in
let got, _, promoted =
scan_words db "SELECT c0 FROM w WHERE c39 = 'nothing'"
in
Alcotest.check rows "no row matches" [] got;
if promoted > 50_000. then
Alcotest.failf "%d rows read and none kept promoted %.0f words" n promoted
(* A register's text is valid until the register is next written, so whatever
keeps a text across rows copies it (sqlite3VdbeMemCopy). Each query below
keeps texts while the column registers take the next rows, written in
place into the same buffers: a later row shorter than the one kept, which
a kept view of a column buffer would read as the later row's bytes over the
kept one's tail ("fig" over "zucchini" reads "figchini"). *)
let test_kept_texts_survive_the_next_row () =
let db = in_memory () in
Table.create_table db ~sql:"CREATE TABLE t (a TEXT, b TEXT)";
Table.create_table db ~sql:"CREATE TABLE u (a TEXT, c TEXT)";
List.iter
(fun (a, b) -> ignore (Table.insert db ~table:"t" [ Text a; Text b ]))
[
("pear", "g1");
("zucchini", "g2");
("apple", "g1");
("fig", "g2");
("kiwi", "g1");
];
List.iter
(fun (a, c) -> ignore (Table.insert db ~table:"u" [ Text a; Text c ]))
[ ("zucchini", "long-green"); ("fig", "small"); ("pear", "pyrus") ];
let texts l = List.map (List.map (fun s -> Text s)) l in
Alcotest.check rows "max keeps its winner past smaller, shorter rows"
(texts [ [ "zucchini" ] ])
(q db "SELECT max(a) FROM t");
Alcotest.check rows "min keeps its winner past larger, shorter rows"
(texts [ [ "apple" ] ])
(q db "SELECT min(a) FROM t");
Alcotest.check rows "each group keeps its own extremes"
(texts [ [ "g1"; "apple"; "pear" ]; [ "g2"; "fig"; "zucchini" ] ])
(q db "SELECT b, min(a), max(a) FROM t GROUP BY b ORDER BY b");
Alcotest.check rows "the sorter keeps every row it sorts"
(texts [ [ "apple" ]; [ "fig" ]; [ "kiwi" ]; [ "pear" ]; [ "zucchini" ] ])
(q db "SELECT a FROM t ORDER BY a");
Alcotest.check rows "a join keeps the texts it built"
(texts
[
[ "fig"; "g2"; "small" ];
[ "pear"; "g1"; "pyrus" ];
[ "zucchini"; "g2"; "long-green" ];
])
(q db "SELECT t.a, t.b, u.c FROM t JOIN u ON u.a = t.a ORDER BY t.a");
Alcotest.check rows "two cursors on one table read their own rows"
(texts
[
[ "apple"; "kiwi" ];
[ "apple"; "pear" ];
[ "fig"; "zucchini" ];
[ "kiwi"; "pear" ];
])
(q db
"SELECT x.a, y.a FROM t AS x JOIN t AS y ON x.b = y.b AND x.a < y.a \
ORDER BY x.a, y.a")
let suite =
( "select",
[
Alcotest.test_case "a recursive CTE compiles its step once" `Quick
test_recursive_step_compiles_once;
Alcotest.test_case "a recursive CTE streams to its reader" `Quick
test_recursive_cte_streams_to_its_reader;
Alcotest.test_case "COUNT respects rowid range semantics" `Quick
test_count_rowid_ranges;
Alcotest.test_case "COUNT range allocation is bounded" `Quick
test_count_range_allocation;
Alcotest.test_case "a scan decodes the columns it reads" `Quick
test_a_scan_decodes_the_columns_it_reads;
Alcotest.test_case "a scan holds what it keeps" `Quick
test_a_scan_holds_what_it_keeps;
Alcotest.test_case "uncorrelated folded once, correlated per row" `Quick
test_uncorrelated_folded_correlated_per_row;
Alcotest.test_case "a correlated subquery keeps one plan" `Quick
test_correlated_subquery_one_plan;
Alcotest.test_case "a correlated subquery keeps its resolution and scan"
`Quick test_correlated_subquery_keeps_its_plan;
Alcotest.test_case "the engine's correlated subquery keeps one plan"
`Quick test_engine_correlated_subquery_one_plan;
Alcotest.test_case "a literal statement keeps no plan" `Quick
test_literal_statement_keeps_no_plan;
Alcotest.test_case "IN is a membership over the folded set" `Quick
test_in_membership_over_folded_set;
Alcotest.test_case "recursive CTE to fixpoint" `Quick
test_recursive_cte_fixpoint;
Alcotest.test_case "compound set operators" `Quick
test_compound_set_operators;
Alcotest.test_case "VM declines a shape, engine answers" `Quick
test_vm_declines_shape_engine_answers;
Alcotest.test_case "a grouped window sort turns a tied run round" `Quick
test_a_grouped_window_sort_turns_a_tied_run_round;
Alcotest.test_case "EXPLAIN is the plan that runs" `Quick
test_explain_is_the_plan_that_runs;
Alcotest.test_case "iter answers what query answers" `Quick
test_iter_answers_what_query_answers;
Alcotest.test_case "iter_rows answers what iter answers" `Quick
test_iter_rows_answers_what_iter_answers;
Alcotest.test_case "a row kept past f is refused" `Quick
test_a_row_kept_past_f_is_refused;
Alcotest.test_case "a row reads as sqlite3_column does" `Quick
test_row_reads_as_sqlite3_column;
Alcotest.test_case "the typed door answers what run answers" `Quick
test_typed_iter_answers_what_run_answers;
Alcotest.test_case "raising out of f ends the scan" `Quick
test_raising_out_of_f_ends_the_scan;
Alcotest.test_case "iter takes one statement, not a script" `Quick
test_iter_takes_one_statement;
Alcotest.test_case "a declined shape answers once" `Quick
test_a_declined_shape_answers_once;
Alcotest.test_case "a wide scan retains no rows" `Quick
test_a_wide_scan_retains_no_rows;
Alcotest.test_case "a domain compiles its own select" `Quick
test_domains_compile_independently;
Alcotest.test_case "kept texts survive the next row" `Quick
test_kept_texts_survive_the_next_row;
] )