include Query_part_1 include Query_part_2 include Query_part_3 include Query_part_4 open Sqlite (* An inner join before an outer one -- the shape the planner keeps its access paths for. The inner join answers six rows and the LEFT join pads the four whose key no [c] carries. *) let test_outer_chain_inner_left () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l JOIN r ON l.k = r.k LEFT JOIN c ON c.k = l.k \ ORDER BY l.v, r.w, c.u" [ [ Text "l2"; Text "r2"; Null ]; [ Text "l2"; Text "r2b"; Null ]; [ Text "l2b"; Text "r2"; Null ]; [ Text "l2b"; Text "r2b"; Null ]; [ Text "l3"; Text "r3"; Text "c3" ]; [ Text "l3"; Text "r3"; Text "c3b" ]; ] (* The pair that says where an ON runs. A RIGHT join over an inner one pads the whole block to its left, and the block's own ON is part of what a row of that block has to satisfy to count as a match -- so the ON runs INSIDE the RIGHT join's loop, once per [c] row. [c1] matches [l1], whose [r] the inner ON rejects, so [c1] is reported with both leading sources NULL. Move that same ON into the WHERE and three rows go: [c1] then matches [l1] paired with every [r], counts as matched, and the WHERE throws all five pairings away afterwards -- leaving nothing to report [c1] with, and [c5] and [cnull] dropped as well because a padded [l.k] satisfies no equality. Five rows against two: an ON placed one level out is a wrong answer, not a slower one. *) let test_outer_chain_inner_right () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l JOIN r ON l.k = r.k RIGHT JOIN c ON c.k = l.k \ ORDER BY c.u, l.v, r.w" [ [ Null; Null; Text "c1" ]; [ Text "l3"; Text "r3"; Text "c3" ]; [ Text "l3"; Text "r3"; Text "c3b" ]; [ Null; Null; Text "c5" ]; [ Null; Null; Text "cnull" ]; ]; oc_check db "SELECT l.v, r.w, c.u FROM l, r RIGHT JOIN c ON c.k = l.k WHERE l.k = r.k \ ORDER BY c.u, l.v, r.w" [ [ Text "l3"; Text "r3"; Text "c3" ]; [ Text "l3"; Text "r3"; Text "c3b" ]; ] (* A RIGHT join then a LEFT one. The RIGHT drives from [r] and pads [l]; the LEFT then preserves everything that produced, [r4] and [rnull] included, and pads [c] where the chained key finds none. *) let test_outer_chain_right_left () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l RIGHT JOIN r ON r.k = l.k LEFT JOIN c ON c.k \ = r.k ORDER BY r.w, l.v, c.u" [ [ Text "l2"; Text "r2"; Null ]; [ Text "l2b"; Text "r2"; Null ]; [ Text "l2"; Text "r2b"; Null ]; [ Text "l2b"; Text "r2b"; Null ]; [ Text "l3"; Text "r3"; Text "c3" ]; [ Text "l3"; Text "r3"; Text "c3b" ]; [ Null; Text "r4"; Null ]; [ Null; Text "rnull"; Null ]; ] (* Two FULL joins over three sources: each end of each join keeps its unmatched rows, and every one of the twelve is reported exactly once. *) let test_outer_chain_full_full () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l FULL JOIN r ON l.k = r.k FULL JOIN c ON c.k = \ l.k ORDER BY l.v, r.w, c.u" [ [ Null; Null; Text "c5" ]; [ Null; Null; Text "cnull" ]; [ Null; Text "r4"; Null ]; [ Null; Text "rnull"; Null ]; [ Text "l1"; Null; Text "c1" ]; [ Text "l2"; Text "r2"; Null ]; [ Text "l2"; Text "r2b"; Null ]; [ Text "l2b"; Text "r2"; Null ]; [ Text "l2b"; Text "r2b"; Null ]; [ Text "l3"; Text "r3"; Text "c3" ]; [ Text "l3"; Text "r3"; Text "c3b" ]; [ Text "lnull"; Null; Null ]; ] (* Three LEFT joins in a row, keyed off the leading source: every [l] row is emitted, padded independently on each of the three. *) let test_outer_chain_three_left () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u, d.q FROM l LEFT JOIN r ON l.k = r.k LEFT JOIN c ON \ c.k = l.k LEFT JOIN d ON d.k = l.k ORDER BY l.v, r.w, c.u, d.q" [ [ Text "l1"; Null; Text "c1"; Text "d1" ]; [ Text "l2"; Text "r2"; Null; Text "d2" ]; [ Text "l2"; Text "r2b"; Null; Text "d2" ]; [ Text "l2b"; Text "r2"; Null; Text "d2" ]; [ Text "l2b"; Text "r2b"; Null; Text "d2" ]; [ Text "l3"; Text "r3"; Text "c3"; Null ]; [ Text "l3"; Text "r3"; Text "c3b"; Null ]; [ Text "lnull"; Null; Null; Null ]; ] (* The same three joins keyed in a chain, each off the source before it. A padded level pads the one after it: [l1] finds no [r], so [c.k = r.k] has a NULL on one side and matches nothing, and [d] in turn matches nothing. *) let test_outer_chain_three_left_keyed_in_chain () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u, d.q FROM l LEFT JOIN r ON l.k = r.k LEFT JOIN c ON \ c.k = r.k LEFT JOIN d ON d.k = c.k ORDER BY l.v, r.w, c.u, d.q" [ [ Text "l1"; Null; Null; Null ]; [ Text "l2"; Text "r2"; Null; Null ]; [ Text "l2"; Text "r2b"; Null; Null ]; [ Text "l2b"; Text "r2"; Null; Null ]; [ Text "l2b"; Text "r2b"; Null; Null ]; [ Text "l3"; Text "r3"; Text "c3"; Null ]; [ Text "l3"; Text "r3"; Text "c3b"; Null ]; [ Text "lnull"; Null; Null; Null ]; ] (* A non-equality conjunct in each ON. It qualifies the match and not the row: a row it rejects is padded, not dropped, so [l2]/[l2b] keep only [r2b] and [l3] only [c3b]. *) let test_outer_chain_non_equality_on () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l LEFT JOIN r ON l.k = r.k AND r.w <> 'r2' LEFT \ JOIN c ON c.k = l.k AND c.u <> 'c3' ORDER BY l.v, r.w, c.u" [ [ Text "l1"; Null; Text "c1" ]; [ Text "l2"; Text "r2b"; Null ]; [ Text "l2b"; Text "r2b"; Null ]; [ Text "l3"; Text "r3"; Text "c3b" ]; [ Text "lnull"; Null; Null ]; ] (* A WHERE over the chain runs after both null-fills, so it can select the padded rows -- which is what tells a WHERE from an ON. *) let test_outer_chain_where_after_fill () = let db = oc_setup () in oc_check db "SELECT l.v, r.w, c.u FROM l LEFT JOIN r ON l.k = r.k LEFT JOIN c ON c.k = \ l.k WHERE c.u IS NULL ORDER BY l.v, r.w" [ [ Text "l2"; Text "r2"; Null ]; [ Text "l2"; Text "r2b"; Null ]; [ Text "l2b"; Text "r2"; Null ]; [ Text "l2b"; Text "r2b"; Null ]; [ Text "lnull"; Null; Null ]; ] (* A GROUP BY over the chain groups the null-filled rows as they stand, so [count(c.u)] counts the matches and answers 0 for a group whose [c] was padded -- while counting the rows themselves would answer the padding. *) let test_outer_chain_group_by () = let db = oc_setup () in oc_check db "SELECT l.v, count(c.u) FROM l LEFT JOIN r ON l.k = r.k LEFT JOIN c ON c.k \ = l.k GROUP BY l.v ORDER BY l.v" [ [ Text "l1"; Int 1L ]; [ Text "l2"; Int 0L ]; [ Text "l2b"; Int 0L ]; [ Text "l3"; Int 2L ]; [ Text "lnull"; Int 0L ]; ] (* DISTINCT over the chain folds the duplicates the first join's multiplicity produced: [l2] pairs with two [r] rows and appears once. *) let test_outer_chain_distinct () = let db = oc_setup () in oc_check db "SELECT DISTINCT l.v, c.u FROM l LEFT JOIN r ON l.k = r.k LEFT JOIN c ON \ c.k = l.k ORDER BY l.v, c.u" [ [ Text "l1"; Text "c1" ]; [ Text "l2"; Null ]; [ Text "l2b"; Null ]; [ Text "l3"; Text "c3" ]; [ Text "l3"; Text "c3b" ]; [ Text "lnull"; Null ]; ] (* A self-join chained twice: one table, three cursors, and the second join keyed off the first join's source. *) let test_outer_chain_self_join () = let db = oc_setup () in oc_check db "SELECT a.nm, b.nm, e.nm FROM t a LEFT JOIN t b ON b.parent = a.id LEFT \ JOIN t e ON e.parent = b.id ORDER BY a.nm, b.nm, e.nm" [ [ Text "a"; Null; Null ]; [ Text "b"; Text "c"; Null ]; [ Text "c"; Null; Null ]; [ Text "root"; Text "a"; Null ]; [ Text "root"; Text "b"; Text "c" ]; ] (* A two-column key chained into a third source. Both columns must match for the join to, so [m12] and [m21] are padded although each shares one column with an [n] row, and the [NULL] in [n1n]'s [b] matches nothing. *) let test_outer_chain_multi_column_key () = let db = oc_setup () in oc_check db "SELECT m.v, n.w, c.u FROM m LEFT JOIN n ON m.a = n.a AND m.b = n.b LEFT \ JOIN c ON c.k = m.a ORDER BY m.v, n.w, c.u" [ [ Text "m11"; Text "n11"; Text "c1" ]; [ Text "m11"; Text "n11b"; Text "c1" ]; [ Text "m12"; Null; Text "c1" ]; [ Text "m21"; Null; Null ]; [ Text "mn1"; Null; Null ]; ] (* A NOCASE column on one side of the first join's key: the declared collation reaches the join comparison, so ['Alpha'] matches ['alpha']. The second join is on plain text and matches nothing. *) let test_outer_chain_nocase_key () = let db = oc_setup () in oc_check db "SELECT cs.v, ct.w, c.u FROM cs LEFT JOIN ct ON cs.s = ct.s LEFT JOIN c ON \ c.u = cs.v ORDER BY cs.v, ct.w" [ [ Text "cs1"; Text "ct1"; Null ]; [ Text "cs2"; Text "ct2"; Null ]; [ Text "cs3"; Null; Null ]; ] (* An uncorrelated IN (SELECT ...) The subquery reads nothing of the outer row, so it runs once and its rows answer every outer row: [rows_scanned] is the outer table once and the inner one once, at every size of either. Reading the inner rows once is half of it; the other half is what each outer row does with them. Compared with every inner value in turn, the outer scan costs the product of the two sides, which no read counter sees, so the second count here is the words the query allocates: a pass over the inner values per outer row allocates for every pair, a lookup does not. That count is a count, the same on every run of one build, and the bound leaves two orders of magnitude to whatever an unrelated change adds. Both shapes of house's flow check are here: a member test and its NOT IN. *) let is_setup ~outer ~inner = let db = in_memory () in exec_db db "CREATE TABLE o (x INTEGER)"; exec_db db "CREATE TABLE s (y INTEGER)"; let fill table n f = exec_db db (Fmt.str "INSERT INTO %s WITH RECURSIVE c(i) AS (VALUES (0) UNION ALL SELECT i \ + 1 FROM c WHERE i < %d) SELECT %s FROM c" table (n - 1) f) in fill "o" outer "i"; fill "s" inner "2 * i"; db let is_queries = [ "SELECT count(*) FROM o WHERE x IN (SELECT y FROM s)"; "SELECT count(*) FROM o WHERE x NOT IN (SELECT y FROM s)"; ] let is_measure db sql = let before = Stats.rows_scanned db in let words = Gc.minor_words () in let out = q db sql [] in (out, Stats.rows_scanned db - before, Gc.minor_words () -. words) let test_in_select_reads_its_inner_side_once () = let inner = 1000 in List.iter (fun outer -> let db = is_setup ~outer ~inner in List.iter (fun sql -> let _, scanned, _ = is_measure db sql in Alcotest.(check int) (Fmt.str "%s, %d outer rows: each side read once" sql outer) (outer - 1 + (inner - 1)) scanned) is_queries) [ 1000; 2000; 4000 ]; (* the inner side quadrupled under a fixed outer: a lookup per outer row adds what holding 3000 more values costs, a pass adds 2000 x 3000 pairs *) let outer = 2000 in let words inner sql = let db = is_setup ~outer ~inner in let out, _, words = is_measure db sql in (out, words) in List.iter (fun sql -> (* every even outer value is a member at either size, and no odd one *) let half = [ [ Int (Int64.of_int (outer / 2)) ] ] in let small, w_small = words 1000 sql in let large, w_large = words 4000 sql in Alcotest.check rows (sql ^ ": 1000 inner rows") half small; Alcotest.check rows (sql ^ ": 4000 inner rows") half large; let added = w_large -. w_small in if added > 1_000_000. then Alcotest.failf "%s: 3000 more inner rows cost %.0f more words, a pass per outer row" sql added) is_queries (* An equi-join no index serves, at three sizes Neither side has an index on the join column, so the inner side is read once into an automatic index, as sqlite3 3.54.1 plans it, and each outer row probes it. [rows_scanned] is then the two passes, 2 (n - 1), and doubles with n; a nested loop rescans the inner side per outer row and quadruples, n (n - 1) + n - 1, which is what this shape cost before the hash: 0.57 s, 2.73 s and 8.78 s at these three sizes. *) let uj_setup n = let db = in_memory () in exec_db db "CREATE TABLE l (k INTEGER, v INTEGER)"; exec_db db "CREATE TABLE r (k INTEGER, w INTEGER)"; let fill table key = exec_db db (Fmt.str "INSERT INTO %s WITH RECURSIVE c(i) AS (VALUES (0) UNION ALL SELECT i \ + 1 FROM c WHERE i < %d) SELECT %s, i FROM c" table (n - 1) key) in fill "l" "i"; fill "r" (Fmt.str "%d - i" (n - 1)); db let test_unindexed_join_is_linear () = List.iter (fun n -> let db = uj_setup n in let out, scanned, plan = jp_measure db "SELECT count(*) FROM l JOIN r ON l.k = r.k" in Alcotest.check rows (Fmt.str "%d rows a side: every row has its match" n) [ [ Int (Int64.of_int n) ] ] out; Alcotest.(check string) (Fmt.str "%d rows a side: an automatic index to search" n) "SCAN l\n\ BLOOM FILTER ON r (k=?)\n\ SEARCH r USING AUTOMATIC COVERING INDEX (k=?)" plan; Alcotest.(check int) (Fmt.str "%d rows a side: each side read once" n) (2 * (n - 1)) scanned) [ 2000; 4000; 8000 ] (* A named parameter binds by the index its first appearance takes, as sqlite3_bind_* by index does: [:x] is the first value, [@y] the second, and the second [:x] the first again. One left unbound is NULL. *) let test_named_parameters () = let db = in_memory () in Alcotest.check rows "bound by index" [ [ Int 1L; Int 2L; Int 1L ] ] (q db "SELECT :x, @y, :x" [ Int 1L; Int 2L ]); Alcotest.check rows "unbound" [ [ Null; Text "null" ] ] (q db "SELECT $z, typeof(:w)" []) let suite = ( "query", [ Alcotest.test_case "named parameters" `Quick test_named_parameters; Alcotest.test_case "find_layer (eq + params + limit)" `Quick test_find_layer; Alcotest.test_case "join + coalesce" `Quick test_join_coalesce; Alcotest.test_case "count(*)" `Quick test_count_star; Alcotest.test_case "like" `Quick test_like; Alcotest.test_case "like escape + like()/glob()" `Quick test_like_escape; Alcotest.test_case "in (list)" `Quick test_in_list; Alcotest.test_case "in (select)" `Quick test_in_select; Alcotest.test_case "in ((subquery))" `Quick test_in_parenthesised_subquery; Alcotest.test_case "is not null" `Quick test_is_not_null; Alcotest.test_case "order by" `Quick test_order_by; Alcotest.test_case "from subquery (VM path)" `Quick test_from_subquery; Alcotest.test_case "order by (VM path)" `Quick test_order_by_vm; Alcotest.test_case "order by ordinal" `Quick test_order_by_ordinal; Alcotest.test_case "order by ordinal with COLLATE" `Quick test_order_ordinal_collate; Alcotest.test_case "distinct" `Quick test_distinct; Alcotest.test_case "distinct (no order, VM path)" `Quick test_distinct_no_order; Alcotest.test_case "distinct with COLLATE" `Quick test_distinct_collate; Alcotest.test_case "distinct honours a declared collation" `Quick test_distinct_declared_collation; Alcotest.test_case "an aggregate DISTINCT dedups under a collation" `Quick test_distinct_aggregate_collation; Alcotest.test_case "aggregate / GROUP BY (VM path)" `Quick test_aggregate_vm; Alcotest.test_case "unknown column" `Quick test_unknown_column; Alcotest.test_case "select without from" `Quick test_select_no_from; Alcotest.test_case "pragma introspection" `Quick test_pragma_introspection; Alcotest.test_case "pragma through Raw.query" `Quick test_pragma_query; Alcotest.test_case "pragma table-valued functions" `Quick test_pragma_table_function; Alcotest.test_case "printf / format" `Quick test_printf; Alcotest.test_case "string_agg + aggregate FILTER" `Quick test_agg_filter; Alcotest.test_case "window functions" `Quick test_window; Alcotest.test_case "window frames (ROWS)" `Quick test_window_frames; Alcotest.test_case "scalar subquery + EXISTS" `Quick test_subquery_expr; Alcotest.test_case "collate (NOCASE/RTRIM)" `Quick test_collate; Alcotest.test_case "a simple CASE's base comparison collates" `Quick test_case_base_collation; Alcotest.test_case "IN honours left-operand collation" `Quick test_in_collation; Alcotest.test_case "IN (SELECT) reads both operands' collation" `Quick test_in_select_collation; Alcotest.test_case "is / is not (null-safe)" `Quick test_is_operator; Alcotest.test_case "is honours a collating sequence" `Quick test_is_collation; Alcotest.test_case "insert column affinity" `Quick test_insert_affinity; Alcotest.test_case "an ALTER-added REAL default reads as a real" `Quick test_alter_added_real_default_reads_as_a_real; Alcotest.test_case "an aggregate over a widened REAL column" `Quick test_an_aggregate_over_a_widened_real_column; Alcotest.test_case "unary + strips affinity" `Quick test_unary_plus_affinity; Alcotest.test_case "declared column collation" `Quick test_declared_collation; Alcotest.test_case "declared collation through a derived table" `Quick test_collate_through_a_derived_table; Alcotest.test_case "create table as select" `Quick test_create_table_as; Alcotest.test_case "query sqlite_master" `Quick test_sqlite_master; Alcotest.test_case "derived table as join operand" `Quick test_derived_table_join; Alcotest.test_case "view on the VM" `Quick test_view_on_vm; Alcotest.test_case "subquery hoisting" `Quick test_subquery_hoisting; Alcotest.test_case "correlated subqueries" `Quick test_correlated_subqueries; Alcotest.test_case "correlated IN with NULL" `Quick test_correlated_in_null; Alcotest.test_case "NOT IN / NOT EXISTS" `Quick test_not_in_not_exists; Alcotest.test_case "window on the VM" `Quick test_window_on_vm; Alcotest.test_case "projected comparison" `Quick test_projected_comparison; Alcotest.test_case "projected binop" `Quick test_projected_binop; Alcotest.test_case "projected IS NULL" `Quick test_projected_is_null; Alcotest.test_case "projected IS" `Quick test_projected_is; Alcotest.test_case "projected IN list" `Quick test_projected_in_list; Alcotest.test_case "native count/min/max aggregate" `Quick test_native_aggregate; Alcotest.test_case "native group by" `Quick test_native_group_by; Alcotest.test_case "native group by order/limit" `Quick test_native_group_by_order; Alcotest.test_case "native group by having" `Quick test_native_group_by_having; Alcotest.test_case "native group by expression key" `Quick test_native_group_by_expr_key; Alcotest.test_case "native group by collate" `Quick test_native_group_by_collate; Alcotest.test_case "native group by over a join" `Quick test_native_group_by_join; Alcotest.test_case "insert default values" `Quick test_default_values; Alcotest.test_case "update ... from" `Quick test_update_from; Alcotest.test_case "float text rendering" `Quick test_float_text; Alcotest.test_case "blob funcs (unhex/octet_length/zeroblob)" `Quick test_blob_funcs; Alcotest.test_case "derived table (subquery in from)" `Quick test_derived_table; Alcotest.test_case "between" `Quick test_between; Alcotest.test_case "group by" `Quick test_group_by; Alcotest.test_case "limit param" `Quick test_limit_param; Alcotest.test_case "like (lang_expr spec)" `Quick test_like_spec; Alcotest.test_case "aggregate in where" `Quick test_aggregate_in_where; Alcotest.test_case "arithmetic" `Quick test_arithmetic; Alcotest.test_case "where truthiness" `Quick test_where_truthiness; Alcotest.test_case "int64 overflow and int/float compare" `Quick test_int_overflow_and_float_compare; Alcotest.test_case "aggregates (sum/avg/min/max/total)" `Quick test_aggregates; Alcotest.test_case "integer SUM overflow errors" `Quick test_sum_integer_overflow; Alcotest.test_case "length + group_concat" `Quick test_length_and_group_concat; Alcotest.test_case "compound dedups under a collation" `Quick test_compound_collation; Alcotest.test_case "compound (union/except/intersect)" `Quick test_compound; Alcotest.test_case "string funcs (instr/substr)" `Quick test_string_funcs; Alcotest.test_case "concat (||)" `Quick test_concat; Alcotest.test_case "insert ... select" `Quick test_insert_select; Alcotest.test_case "create index with ASC/DESC" `Quick test_create_index_desc; Alcotest.test_case "cast" `Quick test_cast; Alcotest.test_case "vacuum" `Quick test_vacuum; Alcotest.test_case "hash join (unindexed equi-join)" `Quick test_hash_join; Alcotest.test_case "cross join (comma)" `Quick test_cross_join; Alcotest.test_case "left join (null-pad)" `Quick test_left_join; Alcotest.test_case "left join semantics (VM)" `Quick test_left_join_semantics; Alcotest.test_case "right / full outer join" `Quick test_right_full_join; Alcotest.test_case "natural join" `Quick test_natural_join; Alcotest.test_case "offset" `Quick test_offset; Alcotest.test_case "having" `Quick test_having; Alcotest.test_case "case expression" `Quick test_case_expr; Alcotest.test_case "scalar functions" `Quick test_scalar_funcs; Alcotest.test_case "math functions" `Quick test_math_funcs; Alcotest.test_case "more core functions" `Quick test_more_funcs; Alcotest.test_case "returning" `Quick test_returning; Alcotest.test_case "upsert" `Quick test_upsert; Alcotest.test_case "values" `Quick test_values; Alcotest.test_case "with (non-recursive cte)" `Quick test_cte; Alcotest.test_case "with recursive" `Quick test_recursive_cte; Alcotest.test_case "index access path" `Quick test_index_access; Alcotest.test_case "rowid seek (integer primary key)" `Quick test_rowid_seek; Alcotest.test_case "a single-use CTE flattens to the index path" `Quick test_cte_flattens_to_the_index_path; Alcotest.test_case "a CTE is bound inside a subquery" `Quick test_cte_binds_inside_a_subquery; Alcotest.test_case "a WITH scopes over every arm" `Quick test_a_with_scopes_over_every_arm; Alcotest.test_case "explain describes a materialised CTE" `Quick test_explain_a_materialised_cte; Alcotest.test_case "exec: insert" `Quick test_exec_insert; Alcotest.test_case "exec: insert or replace" `Quick test_exec_insert_or_replace; Alcotest.test_case "exec: insert conflict" `Quick test_exec_insert_conflict; Alcotest.test_case "exec: insert or ignore" `Quick test_insert_or_ignore; Alcotest.test_case "exec: WITH on update/delete" `Quick test_with_update_delete; Alcotest.test_case "exec: update" `Quick test_update; Alcotest.test_case "exec: run script" `Quick test_raw_run; Alcotest.test_case "exec: delete where" `Quick test_exec_delete_where; Alcotest.test_case "exec: delete with alias" `Quick test_delete_alias; Alcotest.test_case "exec: delete subquery" `Quick test_exec_delete_subquery; Alcotest.test_case "exec: create if not exists" `Quick test_exec_create_if_not_exists; Alcotest.test_case "exec: transaction" `Quick test_exec_transaction; Alcotest.test_case "exec: transaction misuse" `Quick test_exec_transaction_misuse; Alcotest.test_case "exec: script" `Quick test_exec_script; Alcotest.test_case "exec: create index validates" `Quick test_exec_create_index_validates; Alcotest.test_case "secondary index (non-unique access path)" `Quick test_secondary_index; Alcotest.test_case "secondary index maintained on insert/update/delete" `Quick test_secondary_index_maintained; Alcotest.test_case "explicit unique index (enforce + drop)" `Quick test_unique_index_explicit; Alcotest.test_case "unique index over existing duplicates fails" `Quick test_unique_index_over_duplicates; Alcotest.test_case "descending index seek" `Quick test_desc_index_seek; Alcotest.test_case "secondary index rollback" `Quick test_secondary_index_rollback; Alcotest.test_case "create/drop index name errors" `Quick test_create_index_errors; Alcotest.test_case "exec: params" `Quick test_exec_params; Alcotest.test_case "typed: find" `Quick test_typed_find; Alcotest.test_case "typed: count" `Quick test_typed_count; Alcotest.test_case "qualified star (t.*)" `Quick test_qualified_star; Alcotest.test_case "implicit rowid column" `Quick test_rowid; Alcotest.test_case "negative LIMIT is unbounded" `Quick test_negative_limit; Alcotest.test_case "nested aggregate in select list" `Quick test_nested_aggregate; Alcotest.test_case "string column alias" `Quick test_string_alias; Alcotest.test_case "select-list alias in WHERE" `Quick test_where_alias; Alcotest.test_case "empty IN () set" `Quick test_empty_in; Alcotest.test_case "star under GROUP BY" `Quick test_star_group_by; Alcotest.test_case "GROUP BY key ordering" `Quick test_group_by_key_order; Alcotest.test_case "GROUP BY collation" `Quick test_group_by_collation; Alcotest.test_case "generated column" `Quick test_generated_column; Alcotest.test_case "WITHOUT ROWID table" `Quick test_without_rowid; Alcotest.test_case "column ON CONFLICT clause parses" `Quick test_column_conflict_clause; Alcotest.test_case "partial index" `Quick test_partial_index; Alcotest.test_case "expression index" `Quick test_expression_index; Alcotest.test_case "ISNULL / NOTNULL" `Quick test_isnull_notnull; Alcotest.test_case "TRUE / FALSE literals" `Quick test_true_false; Alcotest.test_case "aggregate over an empty table" `Quick test_empty_aggregate_group; Alcotest.test_case "min/max bare column companion" `Quick test_minmax_bare_column; Alcotest.test_case "aggregates over the rowid keyword" `Quick test_rowid_aggregates; Alcotest.test_case "rowid MIN/MAX edge seek" `Quick test_rowid_minmax_seek; Alcotest.test_case "rowid MIN/MAX non-rowid still scans" `Quick test_rowid_minmax_non_rowid; Alcotest.test_case "rowid MIN/MAX over a range" `Quick test_rowid_minmax_range; Alcotest.test_case "rowid range MIN/MAX allocation is O(log N)" `Quick test_rowid_minmax_range_allocation; Alcotest.test_case "rowid MAX allocation is O(log N)" `Quick test_rowid_minmax_allocation; Alcotest.test_case "rowid LIMIT pushdown" `Quick test_rowid_limit_pushdown; Alcotest.test_case "rowid LIMIT pushdown fall-through" `Quick test_rowid_limit_fallthrough; Alcotest.test_case "rowid LIMIT allocation is O(limit)" `Quick test_rowid_limit_allocation; Alcotest.test_case "rowid-range WHERE + LIMIT" `Quick test_rowid_range_limit; Alcotest.test_case "rowid-range LIMIT allocation is O(limit)" `Quick test_rowid_range_limit_allocation; Alcotest.test_case "indexed equality access path" `Quick test_indexed_scan; Alcotest.test_case "indexed range access path" `Quick test_indexed_range; Alcotest.test_case "indexed range avoids the full scan" `Quick test_indexed_range_scans_nothing; Alcotest.test_case "indexed equality allocation is O(log N)" `Quick test_indexed_scan_allocation; Alcotest.test_case "SELECT * over a derived table" `Quick test_derived_star; Alcotest.test_case "generate_series table function" `Quick test_generate_series; Alcotest.test_case "WITH on INSERT" `Quick test_with_insert; Alcotest.test_case "ordered primary key projection" `Quick test_ordered_primary_key_projection; Alcotest.test_case "NOT IN / NOT LIKE / NOT BETWEEN" `Quick test_not_operators; Alcotest.test_case "IN type affinity" `Quick test_in_affinity; Alcotest.test_case "BETWEEN bound COLLATE" `Quick test_between_collate; Alcotest.test_case "unary + keeps explicit COLLATE" `Quick test_unary_plus_collation; Alcotest.test_case "typed: join" `Quick test_typed_join; Alcotest.test_case "typed: aggregates + GROUP BY" `Quick test_typed_aggregates; Alcotest.test_case "typed: coalesce nullable" `Quick test_typed_coalesce_nullable; Alcotest.test_case "typed: like" `Quick test_typed_like; Alcotest.test_case "typed: in + is not null" `Quick test_typed_in_and_null; Alcotest.test_case "typed: text_of_query exact" `Quick test_text_of_query_exact; Alcotest.test_case "sql_of_query runs like run" `Quick test_to_sql_runs_like_run; Alcotest.test_case "typed: writes" `Quick test_typed_writes; Alcotest.test_case "prepared: INSERT persists rows" `Quick test_prepared_insert; Alcotest.test_case "prepared: SELECT with params" `Quick test_prepared_query; Alcotest.test_case "prepared: bound text not SQL-parsed" `Quick test_prepared_bound_text; Alcotest.test_case "prepared: == repeated text exec" `Quick test_prepared_equiv_text; Alcotest.test_case "join: pinned outer seeks both sides" `Quick test_join_pinned_outer; Alcotest.test_case "join: comma equality takes the same path" `Quick test_join_comma_equality; Alcotest.test_case "join: LEFT JOIN seeks its inner side" `Quick test_join_left_seeks_inner; Alcotest.test_case "join: unpinned outer still seeks the inner" `Quick test_join_unpinned_outer; Alcotest.test_case "join: multi-row outer pin" `Quick test_join_multi_row_outer; Alcotest.test_case "join: three-way seeks every level" `Quick test_join_three_way; Alcotest.test_case "join: aggregate over a join" `Quick test_join_aggregate; Alcotest.test_case "join: a parameterised pin seeks" `Quick test_join_parameterised_pin; Alcotest.test_case "seek: identifier case does not decide it" `Quick test_seek_ignores_identifier_case; Alcotest.test_case "seek: a rowid alias in any case" `Quick test_rowid_seek_ignores_identifier_case; Alcotest.test_case "seek: a transitive pin reaches every source" `Quick test_seek_derives_a_transitive_pin; Alcotest.test_case "seek: a transitive pin stops at an outer join" `Quick test_transitive_pin_respects_an_outer_join; Alcotest.test_case "seek: a transitive pin stops at an affinity change" `Quick test_transitive_pin_stops_at_an_affinity_change; Alcotest.test_case "seek: a chain is planned by its two ends" `Quick test_a_chain_is_planned_by_its_ends; Alcotest.test_case "seek: a chain the planner declines still answers" `Quick test_a_chain_the_planner_declines_still_answers; Alcotest.test_case "seek: the index binding more keys wins" `Quick test_seek_prefers_the_index_binding_more_keys; Alcotest.test_case "seek: a key prefix keeps its rows" `Quick test_seek_on_a_key_prefix_keeps_its_rows; Alcotest.test_case "join: an unindexed column scans" `Quick test_join_unindexed_column; Alcotest.test_case "join: an unindexed equi-join is linear" `Quick test_unindexed_join_is_linear; Alcotest.test_case "join: an unpinned outer seeks the inner" `Quick test_join_unpinned_outer_seeks_inner; Alcotest.test_case "join: a pinned outer seeks" `Quick test_join_pinned_outer_seeks; Alcotest.test_case "join: several columns hash as one key" `Quick test_join_on_several_columns_hashes_them_all; Alcotest.test_case "covering: the entry is the answer" `Quick test_covering_index_answers_from_its_entries; Alcotest.test_case "covering: an entry reads what the row reads" `Quick test_covering_index_reads_what_the_row_reads; Alcotest.test_case "analyze: a measured bucket reprices the seek" `Quick test_analyze_reprices_the_seek; Alcotest.test_case "join: RIGHT seeks its table on its ON" `Quick test_join_right_seeks_its_table_on_its_on; Alcotest.test_case "join: FULL pads and keeps its table" `Quick test_join_full_pads_and_keeps_its_table; Alcotest.test_case "join: a materialised source is counted" `Quick test_join_materialised_source_counted; Alcotest.test_case "join: a WITH clause costs a compound its arms" `Quick test_a_with_clause_costs_a_compound_its_arms; Alcotest.test_case "join: a WITH clause keeps the index path" `Quick test_a_with_clause_keeps_the_index_path; Alcotest.test_case "seek: a pinned chain counts its buckets" `Quick test_a_pinned_chain_counts_its_buckets; Alcotest.test_case "cte: a CTE read twice is spliced twice" `Quick test_a_cte_read_twice_is_spliced_twice; Alcotest.test_case "rows_scanned counts every source row" `Quick test_rows_scanned_counts_every_source_row; Alcotest.test_case "an uncorrelated IN reads its inner side once" `Quick test_in_select_reads_its_inner_side_once; Alcotest.test_case "a fast path is charged for what it reads" `Quick test_a_fast_path_is_charged_for_what_it_reads; Alcotest.test_case "an OFFSET skips rows as they stream" `Quick test_an_offset_skips_rows_as_they_stream; Alcotest.test_case "min and max read one edge of an index" `Quick test_min_max_reads_one_edge; Alcotest.test_case "a rowid range walks only its span" `Quick test_a_rowid_range_walks_only_its_span; Alcotest.test_case "a rowid equality seeks under every spelling" `Quick test_a_rowid_equality_seeks_under_every_spelling; Alcotest.test_case "a column named rowid takes the spelling back" `Quick test_a_column_named_rowid_takes_the_spelling_back; Alcotest.test_case "explain: a fast path reports itself" `Quick test_explain_reports_the_fast_path; Alcotest.test_case "join: LEFT then LEFT" `Quick test_outer_chain_left_left; Alcotest.test_case "join: LEFT then RIGHT" `Quick test_outer_chain_left_right; Alcotest.test_case "join: LEFT then FULL" `Quick test_outer_chain_left_full; Alcotest.test_case "join: LEFT then inner" `Quick test_outer_chain_left_inner; Alcotest.test_case "join: inner then LEFT" `Quick test_outer_chain_inner_left; Alcotest.test_case "join: inner then RIGHT, and its ON in the WHERE" `Quick test_outer_chain_inner_right; Alcotest.test_case "join: RIGHT then LEFT" `Quick test_outer_chain_right_left; Alcotest.test_case "join: FULL then FULL" `Quick test_outer_chain_full_full; Alcotest.test_case "join: three LEFT joins" `Quick test_outer_chain_three_left; Alcotest.test_case "join: three LEFT joins keyed in a chain" `Quick test_outer_chain_three_left_keyed_in_chain; Alcotest.test_case "join: a chain's ON takes a non-equality" `Quick test_outer_chain_non_equality_on; Alcotest.test_case "join: a chain's WHERE runs after the fills" `Quick test_outer_chain_where_after_fill; Alcotest.test_case "join: a GROUP BY over a chain" `Quick test_outer_chain_group_by; Alcotest.test_case "join: a DISTINCT over a chain" `Quick test_outer_chain_distinct; Alcotest.test_case "join: a chained self-join" `Quick test_outer_chain_self_join; Alcotest.test_case "join: a chain on a two-column key" `Quick test_outer_chain_multi_column_key; Alcotest.test_case "join: a chain on a NOCASE key" `Quick test_outer_chain_nocase_key; ] )