Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file plan.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380(** Physical query plan operators for Phase 0.
Phase 0 operators: CreateTable, Insert, SeqScan, Filter, Project.
Extended in later phases with IndexLookup, HashJoin, Sort, etc. *)moduleCat=Granary_catalog.Catalogtypebinop=|Eq|Ne|Lt|Le|Gt|Ge|Add|Sub|Mul|Div|And|Or|Concat|Mod|Bit_and|Bit_or|Lshift|Rshift|Like|Globtypeexpr=|P_litofAst.literal|P_colofint(** column ordinal *)|P_binopofbinop*expr*expr|P_notofexpr|P_is_nullofexpr|P_is_not_nullofexpr|P_negofexpr|P_bitnotofexpr|P_betweenofexpr*expr*expr|P_inofexpr*exprlist|P_funcofAst.scalar_func*exprlist|P_paramofint(** 0-indexed positional parameter *)|P_subqueryofAst.stmt|P_existsofAst.stmt|P_in_selectofexpr*Ast.stmt|P_caseof{scrutinee:exproption;branches:(expr*expr)list;else_:exproption}|P_castofexpr*Ast.ty|P_excluded_colofint(** Column reference into the proposed INSERT excluded row. *)|P_window_slotofint(** Window function slot reference — substituted to P_col(n_input_cols+i) by planner. *)|P_collateofexpr*Ast.collationtypewindow_plan_item={func:Ast.window_func;args:exprlist;partition_by:exprlist;order_by:(expr*[`Asc|`Desc]*[`Nulls_first|`Nulls_last])list;frame:Ast.frame_specoption}typesnippet_spec={col_idx:int;start_tag:string;end_tag:string;ellipsis:string;n_tokens:int}typeop=|Op_create_tableof{name:string;columns:Granary_encoding.Row.columnlist;uniq_idxs:(string*stringlist*Cat.idx_origin)list;if_not_exists:bool;fk_constraints:(stringlist*string*stringlist*Granary_catalog.Catalog.fk_action*Granary_catalog.Catalog.fk_action*bool)list(** [(local_cols, parent_table, parent_cols, on_delete, on_update, deferrable)] *);without_rowid:bool;autoincrement:bool(** #299: INTEGER PRIMARY KEY AUTOINCREMENT. *)}|Op_col_create_tableof{name:string;columns:Granary_encoding.Row.columnlist;if_not_exists:bool}|Op_insertof{table_meta:Cat.table_meta;ordinals:intlist;values:exprlistlist(* one sublist per VALUES row *);on_conflict:Ast.conflict_actionoption;returning:exprlist;upsert_update:(stringlist*(int*expr)list)option}|Op_insert_selectof{table_meta:Cat.table_meta;ordinals:intlist;source:op;on_conflict:Ast.conflict_actionoption}|Op_seq_scanof{table_meta:Cat.table_meta}|Op_filterof{pred:expr;child:op}|Op_projectof{ordinals:intlist;child:op}|Op_expr_projectof{exprs:(expr*stringoption)list;child:op}|Op_sortof{keys:(expr*[`Asc|`Desc]*[`Nulls_first|`Nulls_last])list;child:op}|Op_limitof{limit:int;offset:int;child:op}|Op_create_indexof{name:string;table:string;tree_id:int(** table's tree_id *);col_sqls:stringlist(** col name (plain) or expr SQL (expression) *);col_expr_flags:boollist(** true = expression index column, false = plain column *);where_expr:exproption;where_sql:stringoption;unique:bool;columns:Granary_encoding.Row.columnlist(** columns of the target table — needed for row decoding
during index population *);if_not_exists:bool}|Op_index_lookupof{table_tree:int(** table's tree_id *);idx_tree:int(** index tree_id *);col_idx:int(** column ordinal for encoding *);col_type:Granary_encoding.Row.ty;lookup_val:expr(** value to look up *);table_meta:Cat.table_meta(** for row decoding *)}|Op_rowid_lookupof{table_meta:Cat.table_meta;lookup_val:expr}|Op_col_seq_scanof{table_meta:Cat.table_meta}|Op_updateof{table_meta:Cat.table_meta;assignments:(int*expr)list(** [(col_ordinal, new_value_expr)] *);where:exproption;order:(expr*[`Asc|`Desc]*[`Nulls_first|`Nulls_last])list;limit:intoption;offset:intoption;indexes:Cat.index_infolist;returning:exprlist}|Op_deleteof{table_meta:Cat.table_meta;where:exproption;order:(expr*[`Asc|`Desc]*[`Nulls_first|`Nulls_last])list;limit:intoption;offset:intoption;indexes:Cat.index_infolist;returning:exprlist}|Op_drop_tableof{table_meta:Cat.table_meta;indexes:Cat.index_infolist}|Op_drop_indexof{idx_info:Cat.index_info}|Op_nested_loop_joinof{left:op(** left input (any op stream) *);right_meta:Cat.table_meta(** right table for row decode *);idx_tree:int(** right-side index tree id *);right_col_idx:int(** join col ordinal IN RIGHT TABLE *);left_col_idx:int(** join col ordinal in the LEFT row *);join_kind:[`Inner|`Left];right_col_offset:int(** = n_left_cols *);n_right_cols:int}|Op_hash_joinof{left:op;right:op;left_key:int(** col ordinal in the left row *);right_key:int(** col ordinal in the right row *);join_kind:[`Inner|`Left];right_col_offset:int;n_right_cols:int}|Op_aggregateof{child:op;group_cols:intlist(** column ordinals in the CHILD row. [[]] = one big group. *);aggs:agg_speclist;having:exproption(** evaluated on the OUTPUT row of [Op_aggregate];
output row = [group_col0; group_col1; ...; agg1; agg2; ...]. *);proj:proj_itemlist(** projection over the aggregate output row. Maps to the final
row emitted to downstream operators. *);windows:window_plan_itemlist(** Post-aggregate window functions; [] for plain GROUP BY. *)}|Op_alter_tableof{table_meta:Cat.table_meta;action:Ast.alter_action}|Op_begin|Op_commit|Op_rollback|Op_savepointofstring|Op_releaseofstring|Op_rollback_toofstring|Op_create_fts_tableof{name:string;columns:stringlist}|Op_fts_insertof{fts_meta:Cat.fts_table_meta;col_names:stringlist;col_values:exprlist;rowid_value:exproption(** #330: explicit [rowid] from the column list *)}|Op_fts_deleteof{fts_meta:Cat.fts_table_meta;where:exproption}|Op_fts_seq_scanof{fts_meta:Cat.fts_table_meta;where:exproption}|Op_fts_match_scanof{fts_meta:Cat.fts_table_meta;query:Fts_query.t;proj:intlist;include_rank:bool(** if true, append BM25 score as last projected column *);snippets:snippet_speclist}|Op_pragma_rowsof{rows:Granary_encoding.Row.tlist}|Op_pragma_get_user_version(** Read user_version from sys_meta at exec time; returns one row [[V_int n]]. *)|Op_pragma_set_user_versionof{version:int64}(** Write user_version to sys_meta; DDL-like, returns 0 rows. *)|Op_pragma_integrity_check(** Scan all table + index B-trees; return [["ok"]] or list of error strings. *)|Op_pragma_get_fk(** Read fk_enforcement flag from catalog; returns one row [[V_int 0|1]]. *)|Op_pragma_set_fkof{on:bool}(** Write fk_enforcement flag to catalog; DDL-like, returns 0 rows. *)|Op_pragma_get_recursive_triggers(** Read recursive_triggers flag from catalog; returns one row [[V_int 0|1]]. *)|Op_pragma_set_recursive_triggersof{on:bool}(** Write recursive_triggers flag to catalog; DDL-like, returns 0 rows. *)|Op_pragma_get_defer_fk(** Read defer_foreign_keys flag from catalog; returns one row [[V_int 0|1]]. *)|Op_pragma_set_defer_fkof{on:bool}(** Write defer_foreign_keys flag to catalog; DDL-like, returns 0 rows. *)|Op_pragma_wal_checkpoint(** Migrate WAL contents to main DB and reset; no-op outside WAL mode. *)|Op_pragma_get_wal_autocheckpoint(** Read per-connection auto-checkpoint threshold. *)|Op_pragma_set_wal_autocheckpointof{n:int64}(** Set per-connection auto-checkpoint threshold (0 disables). *)|Op_pragma_get_synchronous(** #298 read durability mode *)|Op_pragma_set_synchronousof{mode:string}|Op_pragma_get_wal_batch_commits|Op_pragma_set_wal_batch_commitsof{n:int64}|Op_pragma_get_wal_batch_interval_ms|Op_pragma_set_wal_batch_interval_msof{n:int64}|Op_vacuum(** Compact-rebuild the database file (phase 37 / #120). *)|Op_attachof{path:string;schema:string}(** [ATTACH DATABASE 'path' AS schema] — phase 40 / #64. Mutates
the executing [Db.t]'s [attached] map; never observed by exec.ml. *)|Op_detachof{schema:string}(** [DETACH DATABASE schema] — phase 40 / #64. *)|Op_database_list(** [PRAGMA database_list] — phase 40 / #64. Yields one row per
schema: (seq INT, name TEXT, file TEXT). *)|Op_active_database_get(** [PRAGMA active_database] — phase 40 / #64. *)|Op_active_database_setof{schema:string}(** [PRAGMA active_database = schema] — phase 40 / #64. Subsequent
non-routing statements route through [t.attached] under [schema]. *)|Op_distinctof{child:op}|Op_unionof{all:bool;left:op;right:op}|Op_intersectof{left:op;right:op}|Op_exceptof{left:op;right:op}|Op_const_selectof{exprs:(expr*stringoption)list}|Op_windowof{child:op;windows:window_plan_itemlist;n_input_cols:int}|Op_with_cteof{cte_name:string;def:op;query:op;recursive:bool}|Op_cte_scanof{cte_name:string;n_cols:int}|Op_create_viewof{name:string;query:Ast.stmt}|Op_create_reactive_viewof{name:string;query:Ast.stmt;refresh:Ast.refresh_mode}|Op_drop_viewof{name:string}|Op_create_triggerof{name:string;timing:Ast.trigger_timing;event:Ast.trigger_event;table:string;when_:Ast.exproption;body:Ast.stmtlist}|Op_drop_triggerof{name:string}|Op_sqlite_master(** Virtual scan that reconstructs sqlite_master rows from catalog metadata. *)|Op_sqlite_sequence(** #312: virtual scan over AUTOINCREMENT counters (name, seq). *)|Op_seq_setof{table:string;seq:int64}(** #312.1: writable sqlite_sequence SET/INSERT -> set [table]'s next_rowid. *)|Op_seq_resetof{table:stringoption}(** #312.1: writable sqlite_sequence DELETE -> reset [table]'s next_rowid;
[None] (bare DELETE, no WHERE) resets every AUTOINCREMENT counter. *)|Op_no_op(** No-op plan node produced by IF EXISTS DROP when object not found. *)|Op_changes(** Returns rows affected by last DML. Intercepted in db.ml query — not exec.ml. *)|Op_last_insert_rowid(** Returns rowid of last INSERT. Intercepted in db.ml query — not exec.ml. *)|Op_total_changes(** Returns total rows affected since the connection was opened.
Intercepted in db.ml query — not exec.ml. *)|Op_explainof{analyze:bool;inner:op}andproj_item=|PI_group_colofint(** project the i-th GROUP BY column (index into group_cols) *)|PI_agg_slotofint(** project the k-th aggregate result *)|PI_window_slotofint(** project the j-th post-aggregate window function result *)andagg_spec={func:Ast.agg_func;col_ord:intoption(** [None] means COUNT-star *)}[@@@ai_disclosure"ai-generated"][@@@ai_model"claude-opus-4-7"][@@@ai_provider"Anthropic"]